mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-07 21:32:51 +00:00
feat: prioritize video root pointer for view tracking
This commit is contained in:
1 parent
e9ec0b790e
commit
0addd59226
3 files changed
+144
-70
No files matched your search
@@ -0,0 +1,51 @@
|
||||
// js/utils/videoPointer.js
|
||||
|
||||
import { pointerArrayToKey } from "./pointer.js";
|
||||
|
||||
const DEFAULT_VIDEO_KIND = 30078;
|
||||
|
||||
function normalizeString(value) {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
}
|
||||
|
||||
export function resolveVideoPointer({
|
||||
kind,
|
||||
pubkey,
|
||||
videoRootId,
|
||||
dTag,
|
||||
fallbackEventId,
|
||||
} = {}) {
|
||||
const normalizedPubkey = normalizeString(pubkey).toLowerCase();
|
||||
const normalizedKind =
|
||||
typeof kind === "number" && Number.isFinite(kind) ? kind : DEFAULT_VIDEO_KIND;
|
||||
const pointerCandidates = [];
|
||||
|
||||
const rootId = normalizeString(videoRootId);
|
||||
if (rootId && normalizedPubkey) {
|
||||
pointerCandidates.push(["a", `${normalizedKind}:${normalizedPubkey}:${rootId}`]);
|
||||
}
|
||||
|
||||
const normalizedDTag = normalizeString(dTag);
|
||||
if (normalizedDTag && normalizedPubkey) {
|
||||
pointerCandidates.push([
|
||||
"a",
|
||||
`${normalizedKind}:${normalizedPubkey}:${normalizedDTag}`,
|
||||
]);
|
||||
}
|
||||
|
||||
const fallbackId = normalizeString(fallbackEventId);
|
||||
if (fallbackId) {
|
||||
pointerCandidates.push(["e", fallbackId]);
|
||||
}
|
||||
|
||||
for (const pointer of pointerCandidates) {
|
||||
const key = pointerArrayToKey(pointer);
|
||||
if (key) {
|
||||
return { pointer, key };
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default resolveVideoPointer;
|
||||
Reference in new issue
Block a user