Merge pull request #1517 from PR0M3TH3AN/ai/dead-code-20241109-13460810475188800782

chore(ai): remove dead code (magnet.js and unused exports)
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-22 15:32:43 -05:00
commit 9774af7f4e
7 files changed
+24 -123

No files matched your search

+1 -1
View File
@@ -230,4 +230,4 @@ export function createFeedEngine({ logger } = {}) {
};
}
export { DEFAULT_FEED_CONFIG, DEFAULT_CONFIG_SCHEMA };
export { };
+1 -5
View File
@@ -1,10 +1,6 @@
// js/feedEngine/index.js
export {
createFeedEngine,
DEFAULT_FEED_CONFIG,
DEFAULT_CONFIG_SCHEMA,
} from "./engine.js";
export { createFeedEngine } from "./engine.js";
export {
createDedupeByRootStage,
createBlacklistFilterStage,
-59
View File
@@ -1,59 +0,0 @@
import {
buildMagnetUri,
ensureTrackers,
ensureTorrentHint,
ensureWebSeeds,
formatAbsoluteUrl,
normalizeMagnetInput,
resolveAppProtocol,
extractMagnetHints as sharedExtractMagnetHints,
} from "./magnetShared.js";
export const extractMagnetHints = sharedExtractMagnetHints;
export function normalizeAndAugmentMagnet(rawValue, { ws = "", xs = "" } = {}) {
const {
initial,
canonicalValue,
isMagnet,
normalizedScheme,
fragment,
params,
} = normalizeMagnetInput(rawValue);
if (!initial) {
return "";
}
if (!isMagnet) {
return canonicalValue;
}
ensureTrackers(params);
const normalizedXs = typeof xs === "string" ? xs.trim() : "";
if (normalizedXs) {
ensureTorrentHint(params, normalizedXs, { requireHttp: false });
}
const wsList = Array.isArray(ws)
? ws
: typeof ws === "string"
? [ws]
: [];
if (wsList.length > 0) {
const allowHttpSeed = resolveAppProtocol() === "http:";
const formattedList = wsList
.map((item) => (typeof item === "string" ? item.trim() : ""))
.filter((item) => item)
.map((item) => formatAbsoluteUrl(item));
ensureWebSeeds(params, formattedList, {
allowHttp: allowHttpSeed,
allowUnparsed: true,
});
}
return buildMagnetUri(normalizedScheme, params, fragment);
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { deriveTitleFromEvent } from "../videoEventUtils.js";
import { extractMagnetHints } from "../magnet.js";
import { extractMagnetHints } from "../magnetShared.js";
import { devLogger } from "../utils/logger.js";
import { getCachedNostrTools } from "./toolkit.js";
+6 -5
View File
@@ -1,4 +1,5 @@
import { extractMagnetHints, normalizeAndAugmentMagnet } from "../magnet.js";
import { extractMagnetHints } from "../magnetShared.js";
import { normalizeAndAugmentMagnet } from "../magnetUtils.js";
export const VIDEO_NOTE_ERROR_CODES = {
MISSING_TITLE: "missing_title",
@@ -387,12 +388,12 @@ export function normalizeVideoNotePayload(input) {
wsList.push(legacyFormData.url);
}
const normalizedMagnet = normalizeAndAugmentMagnet(legacyFormData.magnet, {
ws: wsList,
const result = normalizeAndAugmentMagnet(legacyFormData.magnet, {
webSeed: wsList,
xs,
});
legacyFormData.magnet = normalizedMagnet;
const hints = extractMagnetHints(normalizedMagnet);
legacyFormData.magnet = result.magnet;
const hints = extractMagnetHints(result.magnet);
legacyFormData.ws = hints.ws || "";
legacyFormData.xs = hints.xs || "";
} else {
+6 -5
View File
@@ -1,4 +1,5 @@
import { extractMagnetHints, normalizeAndAugmentMagnet } from "../../magnet.js";
import { extractMagnetHints } from "../../magnetShared.js";
import { normalizeAndAugmentMagnet } from "../../magnetUtils.js";
import { createModalAccessibility } from "./modalAccessibility.js";
import { Nip71FormManager } from "./nip71FormManager.js";
@@ -1038,12 +1039,12 @@ export class EditModal {
}
if (finalMagnet) {
const normalizedMagnet = normalizeAndAugmentMagnet(finalMagnet, {
ws: finalWs,
const result = normalizeAndAugmentMagnet(finalMagnet, {
webSeed: finalWs,
xs: finalXs,
});
finalMagnet = normalizedMagnet;
const hints = extractMagnetHints(normalizedMagnet);
finalMagnet = result.magnet;
const hints = extractMagnetHints(finalMagnet);
finalWs = hints.ws;
finalXs = hints.xs;
} else {
+9 -47
View File
@@ -6,10 +6,7 @@ import {
normalizeAndAugmentMagnet as normalizeMagnetObject,
safeDecodeMagnet,
} from "../js/magnetUtils.js";
import {
extractMagnetHints,
normalizeAndAugmentMagnet as normalizeMagnetString,
} from "../js/magnet.js";
import { extractMagnetHints } from "../js/magnetShared.js";
function getParamValues(magnet, key) {
const parsed = new URL(magnet);
@@ -47,36 +44,23 @@ test("safeDecodeMagnet leaves plain strings untouched", () => {
);
});
test("bare hashes normalize consistently across helpers", () => {
test("bare hashes normalize consistently", () => {
const infoHash = "0123456789abcdef0123456789abcdef01234567";
const objectResult = normalizeMagnetObject(infoHash);
const stringResult = normalizeMagnetString(infoHash);
assert.ok(objectResult.didChange, "Bare hashes should mark didChange true");
assert.equal(
stringResult,
objectResult.magnet,
"String helper should match object helper output"
);
const xtValues = getParamValues(stringResult, "xt");
const xtValues = getParamValues(objectResult.magnet, "xt");
assert.deepEqual(xtValues, [`urn:btih:${infoHash}`]);
assertDefaultTrackersPresent(stringResult);
assertDefaultTrackersPresent(objectResult.magnet);
});
test("legacy %3A payloads decode across helpers", () => {
test("legacy %3A payloads decode", () => {
const infoHash = "abcdefabcdefabcdefabcdefabcdefabcdefabcd";
const encoded = `magnet:?xt=urn%3Abtih%3A${infoHash}&dn=Example`;
const objectResult = normalizeMagnetObject(encoded);
const stringResult = normalizeMagnetString(encoded);
assert.equal(
stringResult,
objectResult.magnet,
"Helpers should agree on encoded xt payload normalization"
);
const xtValues = getParamValues(stringResult, "xt");
const xtValues = getParamValues(objectResult.magnet, "xt");
assert.deepEqual(xtValues, [`urn:btih:${infoHash}`]);
});
@@ -96,18 +80,7 @@ test("duplicate trackers and hints stay in sync", () => {
webSeed: "https://cdn.example.com/files/",
});
const stringResult = normalizeMagnetString(baseMagnet, {
ws: "https://cdn.example.com/files/", // ensure string helper adds hint
xs: "https://cdn.example.com/video.torrent",
});
assert.equal(
stringResult,
objectResult.magnet,
"Helpers should emit identical magnets after augmentation"
);
const trackers = getParamValues(stringResult, "tr");
const trackers = getParamValues(objectResult.magnet, "tr");
const openwebCount = trackers.filter(
(value) => value === "wss://tracker.openwebtorrent.com"
).length;
@@ -117,10 +90,10 @@ test("duplicate trackers and hints stay in sync", () => {
"HTTP tracker candidates should be ignored"
);
const webSeeds = getParamValues(stringResult, "ws");
const webSeeds = getParamValues(objectResult.magnet, "ws");
assert.deepEqual(webSeeds, ["https://cdn.example.com/files/"]);
const xsValues = getParamValues(stringResult, "xs");
const xsValues = getParamValues(objectResult.magnet, "xs");
assert.deepEqual(xsValues, ["https://cdn.example.com/video.torrent"]);
});
@@ -170,15 +143,6 @@ test("extractMagnetHints returns first ws/xs pair", () => {
});
});
test("string helper skips insecure ws hints on HTTPS origins", () => {
const infoHash = "0123456789abcdef0123456789abcdef01234567";
const normalized = normalizeMagnetString(`magnet:?xt=urn:btih:${infoHash}`, {
ws: "http://cdn.example.com/video-base/",
});
const parsed = new URL(normalized);
assert.equal(parsed.searchParams.getAll("ws").length, 0);
});
test("object helper reports didChange when output differs", () => {
const infoHash = "abcdef0123456789abcdef0123456789abcdef01";
const result = normalizeMagnetObject(`magnet:?xt=urn:btih:${infoHash}`, {
@@ -190,9 +154,7 @@ test("object helper reports didChange when output differs", () => {
test("helpers trim fragments from non-magnet values", () => {
const url = "https://example.com/video.mp4#fragment";
const objectResult = normalizeMagnetObject(url);
const stringResult = normalizeMagnetString(url);
assert.equal(objectResult.magnet, "https://example.com/video.mp4");
assert.equal(stringResult, "https://example.com/video.mp4");
assert.ok(
objectResult.didChange,
"Dropping the fragment should be reflected in didChange"