mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
chore(ai): event schema validation tool + fixes
- Created `scripts/agent/validate-events.mjs` to validate event builders against schemas. - Refactored `buildVideoPostEvent` in `js/nostrEventSchemas.js` to automatically generate the required `s` (storage pointer) tag if missing, using `infoHash`, `url`, or `videoRootId`. - Verified that `js/utils/storagePointer.js` exists and is imported correctly. - Updated `docs/nostr-event-schemas.md` to reflect the auto-generation behavior. - Verified fixes with `scripts/agent/validate-events.mjs` and existing unit tests. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
0d70cbbcfc
commit
f5233a93f3
3 files changed
+44
-1
No files matched your search
@@ -163,7 +163,7 @@ import { updateWatchHistoryListWithDefaultClient } from "./nostrWatchHistoryFaca
|
||||
|
||||
> **Publishing note:** Session actors only emit passive telemetry (for example, view counters) and must **not** sign video comments. Require a logged-in Nostr signer for comment publishing via [`commentEvents`](../js/nostr/commentEvents.js).
|
||||
|
||||
Video posts now include a required storage pointer tag (`['s', '<provider>:<prefix>']`). The `<prefix>` should resolve to the public storage base for the video assets (for example, a public bucket URL plus the object key without its extension). Clients derive `info.json` by appending `.info.json` to the prefix (or by combining a path-style prefix with the hosted URL origin if needed).
|
||||
Video posts now include a required storage pointer tag (`['s', '<provider>:<prefix>']`). The `buildVideoPostEvent` helper automatically generates this tag from available metadata (`infoHash`, `url`, or `videoRootId`) if it is omitted from the input. The `<prefix>` should resolve to the public storage base for the video assets (for example, a public bucket URL plus the object key without its extension). Clients derive `info.json` by appending `.info.json` to the prefix (or by combining a path-style prefix with the hosted URL origin if needed).
|
||||
|
||||
Video posts should treat `videoRootId` as the stable series identifier that remains unchanged across edits and deletes. File fingerprints such as `infoHash` or `fileSha256` live alongside the content payload so media swaps do not break the version chain.
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ import {
|
||||
WATCH_HISTORY_LIST_IDENTIFIER,
|
||||
WATCH_HISTORY_VERSION_TAG_VALUE,
|
||||
} from "./config.js";
|
||||
import {
|
||||
buildStoragePointerValue,
|
||||
deriveStoragePointerFromUrl,
|
||||
} from "./utils/storagePointer.js";
|
||||
|
||||
export const NOTE_TYPES = Object.freeze({
|
||||
VIDEO_POST: "videoPost",
|
||||
@@ -889,6 +893,38 @@ export function buildVideoPostEvent(params) {
|
||||
tags.push(...sanitizedAdditionalTags.map((tag) => tag.slice()));
|
||||
}
|
||||
|
||||
const hasSTag = tags.some((t) => t[0] === "s");
|
||||
if (!hasSTag) {
|
||||
let contentObj = content;
|
||||
if (typeof content === "string") {
|
||||
try {
|
||||
contentObj = JSON.parse(content);
|
||||
} catch (e) {
|
||||
contentObj = {};
|
||||
}
|
||||
}
|
||||
contentObj = contentObj || {};
|
||||
|
||||
let pointer = "";
|
||||
if (contentObj.infoHash) {
|
||||
pointer = buildStoragePointerValue({
|
||||
provider: "btih",
|
||||
prefix: contentObj.infoHash,
|
||||
});
|
||||
} else if (contentObj.url) {
|
||||
pointer = deriveStoragePointerFromUrl(contentObj.url);
|
||||
}
|
||||
|
||||
if (!pointer && (dTagValue || contentObj.videoRootId)) {
|
||||
const prefix = dTagValue || contentObj.videoRootId;
|
||||
pointer = buildStoragePointerValue({ provider: "nostr", prefix });
|
||||
}
|
||||
|
||||
if (pointer) {
|
||||
tags.push(["s", pointer]);
|
||||
}
|
||||
}
|
||||
|
||||
let serializedContent = "";
|
||||
if (typeof content === "string") {
|
||||
serializedContent = content;
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* Event Schema Validation Tool
|
||||
*
|
||||
* Scans the codebase for event builder usage and verifies that the output
|
||||
* conforms to the defined schemas in `js/nostrEventSchemas.js`.
|
||||
*/
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
Reference in new issue
Block a user