mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Merge pull request #2240 from PR0M3TH3AN/refactor-revert-video-2176939372137755635
🧹 Refactor revertVideo to use helper function
This commit is contained in:
3 files changed
+106
-79
No files matched your search
+7
-79
@@ -40,6 +40,7 @@ import {
|
||||
deriveStoragePointerFromUrl,
|
||||
getStoragePointerFromTags,
|
||||
normalizeStoragePointer,
|
||||
resolveStoragePointerValue,
|
||||
} from "../utils/storagePointer.js";
|
||||
import {
|
||||
createWatchHistoryManager,
|
||||
@@ -108,6 +109,7 @@ import {
|
||||
repostEvent as repostEventHelper,
|
||||
mirrorVideoEvent as mirrorVideoEventHelper,
|
||||
rebroadcastEvent as rebroadcastEventHelper,
|
||||
buildRevertVideoPayload,
|
||||
summarizePublishResults,
|
||||
} from "./publishHelpers.js";
|
||||
import {
|
||||
@@ -983,40 +985,6 @@ function normalizeHexHash(candidate) {
|
||||
return HEX64_REGEX.test(trimmed) ? trimmed : "";
|
||||
}
|
||||
|
||||
function resolveStoragePointerValue({
|
||||
storagePointer,
|
||||
url,
|
||||
infoHash,
|
||||
fallbackId,
|
||||
provider,
|
||||
} = {}) {
|
||||
const normalized = normalizeStoragePointer(storagePointer);
|
||||
if (normalized) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
const derivedFromUrl = deriveStoragePointerFromUrl(url, provider || "url");
|
||||
if (derivedFromUrl) {
|
||||
return derivedFromUrl;
|
||||
}
|
||||
|
||||
if (typeof infoHash === "string" && infoHash.trim()) {
|
||||
return buildStoragePointerValue({
|
||||
provider: "btih",
|
||||
prefix: infoHash.trim().toLowerCase(),
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof fallbackId === "string" && fallbackId.trim()) {
|
||||
return buildStoragePointerValue({
|
||||
provider: "nostr",
|
||||
prefix: fallbackId.trim(),
|
||||
});
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const BlobConstructor = typeof Blob !== "undefined" ? Blob : null;
|
||||
let sharedTextEncoder = null;
|
||||
|
||||
@@ -7071,52 +7039,12 @@ export class NostrClient {
|
||||
const stableDTag =
|
||||
existingD || baseEvent?.id || originalEvent?.id || null;
|
||||
|
||||
let oldContent = {};
|
||||
try {
|
||||
oldContent = JSON.parse(baseEvent.content || "{}");
|
||||
} catch (err) {
|
||||
devLogger.warn("[nostr] Failed to parse baseEvent.content while reverting:", err);
|
||||
oldContent = {};
|
||||
}
|
||||
const oldVersion = oldContent.version ?? 1;
|
||||
|
||||
const finalRootId =
|
||||
oldContent.videoRootId ||
|
||||
(existingD
|
||||
? `LEGACY:${baseEvent.pubkey}:${existingD}`
|
||||
: stableDTag || baseEvent?.id || originalEvent?.id || "");
|
||||
|
||||
const oldIsNsfw = oldContent.isNsfw === true;
|
||||
const oldIsForKids = oldContent.isForKids === true && !oldIsNsfw;
|
||||
|
||||
const contentObject = {
|
||||
videoRootId: finalRootId,
|
||||
version: oldVersion,
|
||||
deleted: true,
|
||||
isPrivate: oldContent.isPrivate ?? false,
|
||||
isNsfw: oldIsNsfw,
|
||||
isForKids: oldIsForKids,
|
||||
title: oldContent.title || "",
|
||||
url: "",
|
||||
magnet: "",
|
||||
thumbnail: "",
|
||||
description: "This version was reverted by the creator.",
|
||||
mode: oldContent.mode || "live",
|
||||
};
|
||||
|
||||
const storagePointer = resolveStoragePointerValue({
|
||||
storagePointer: getStoragePointerFromTags(baseEvent.tags),
|
||||
url: oldContent.url,
|
||||
infoHash: oldContent.infoHash,
|
||||
fallbackId: finalRootId,
|
||||
});
|
||||
const additionalTags = storagePointer ? [["s", storagePointer]] : [];
|
||||
const event = buildVideoPostEvent({
|
||||
const event = buildRevertVideoPayload({
|
||||
baseEvent,
|
||||
originalEventId: originalEvent?.id,
|
||||
pubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
dTagValue: stableDTag,
|
||||
content: contentObject,
|
||||
additionalTags,
|
||||
existingD,
|
||||
stableDTag,
|
||||
});
|
||||
|
||||
await this.ensureActiveSignerForPubkey(pubkey);
|
||||
|
||||
@@ -5,10 +5,15 @@ import {
|
||||
summarizePublishResults,
|
||||
} from "../nostrPublish.js";
|
||||
import {
|
||||
buildVideoPostEvent,
|
||||
buildRepostEvent,
|
||||
buildVideoMirrorEvent,
|
||||
sanitizeAdditionalTags,
|
||||
} from "../nostrEventSchemas.js";
|
||||
import {
|
||||
getStoragePointerFromTags,
|
||||
resolveStoragePointerValue,
|
||||
} from "../utils/storagePointer.js";
|
||||
import { normalizePointerInput } from "./watchHistory.js";
|
||||
import { sanitizeRelayList } from "./nip46Client.js";
|
||||
import {
|
||||
@@ -1332,4 +1337,64 @@ export async function rebroadcastEvent({ client, eventId, options = {} }) {
|
||||
}
|
||||
}
|
||||
|
||||
export function buildRevertVideoPayload({
|
||||
baseEvent,
|
||||
originalEventId,
|
||||
pubkey,
|
||||
existingD,
|
||||
stableDTag,
|
||||
}) {
|
||||
let oldContent = {};
|
||||
try {
|
||||
oldContent = JSON.parse(baseEvent.content || "{}");
|
||||
} catch (err) {
|
||||
devLogger.warn(
|
||||
"[nostr] Failed to parse baseEvent.content while reverting:",
|
||||
err,
|
||||
);
|
||||
oldContent = {};
|
||||
}
|
||||
const oldVersion = oldContent.version ?? 1;
|
||||
|
||||
const finalRootId =
|
||||
oldContent.videoRootId ||
|
||||
(existingD
|
||||
? `LEGACY:${baseEvent.pubkey}:${existingD}`
|
||||
: stableDTag || baseEvent.id || originalEventId || "");
|
||||
|
||||
const oldIsNsfw = oldContent.isNsfw === true;
|
||||
const oldIsForKids = oldContent.isForKids === true && !oldIsNsfw;
|
||||
|
||||
const contentObject = {
|
||||
videoRootId: finalRootId,
|
||||
version: oldVersion,
|
||||
deleted: true,
|
||||
isPrivate: oldContent.isPrivate ?? false,
|
||||
isNsfw: oldIsNsfw,
|
||||
isForKids: oldIsForKids,
|
||||
title: oldContent.title || "",
|
||||
url: "",
|
||||
magnet: "",
|
||||
thumbnail: "",
|
||||
description: "This version was reverted by the creator.",
|
||||
mode: oldContent.mode || "live",
|
||||
};
|
||||
|
||||
const storagePointer = resolveStoragePointerValue({
|
||||
storagePointer: getStoragePointerFromTags(baseEvent.tags),
|
||||
url: oldContent.url,
|
||||
infoHash: oldContent.infoHash,
|
||||
fallbackId: finalRootId,
|
||||
});
|
||||
const additionalTags = storagePointer ? [["s", storagePointer]] : [];
|
||||
|
||||
return buildVideoPostEvent({
|
||||
pubkey,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
dTagValue: stableDTag,
|
||||
content: contentObject,
|
||||
additionalTags,
|
||||
});
|
||||
}
|
||||
|
||||
export { summarizePublishResults };
|
||||
@@ -121,3 +121,37 @@ export function resolveInfoJsonUrl({ storagePointer, url } = {}) {
|
||||
|
||||
return normalizeInfoJsonBase(prefix);
|
||||
}
|
||||
|
||||
export function resolveStoragePointerValue({
|
||||
storagePointer,
|
||||
url,
|
||||
infoHash,
|
||||
fallbackId,
|
||||
provider,
|
||||
} = {}) {
|
||||
const normalized = normalizeStoragePointer(storagePointer);
|
||||
if (normalized) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
const derivedFromUrl = deriveStoragePointerFromUrl(url, provider || "url");
|
||||
if (derivedFromUrl) {
|
||||
return derivedFromUrl;
|
||||
}
|
||||
|
||||
if (typeof infoHash === "string" && infoHash.trim()) {
|
||||
return buildStoragePointerValue({
|
||||
provider: "btih",
|
||||
prefix: infoHash.trim().toLowerCase(),
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof fallbackId === "string" && fallbackId.trim()) {
|
||||
return buildStoragePointerValue({
|
||||
provider: "nostr",
|
||||
prefix: fallbackId.trim(),
|
||||
});
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
Reference in new issue
Block a user