diff --git a/js/feedEngine/engine.js b/js/feedEngine/engine.js index 0652a313..11ab00e7 100644 --- a/js/feedEngine/engine.js +++ b/js/feedEngine/engine.js @@ -230,4 +230,4 @@ export function createFeedEngine({ logger } = {}) { }; } -export { DEFAULT_FEED_CONFIG, DEFAULT_CONFIG_SCHEMA }; +export { }; diff --git a/js/feedEngine/index.js b/js/feedEngine/index.js index 4f03bd02..95e4e11b 100644 --- a/js/feedEngine/index.js +++ b/js/feedEngine/index.js @@ -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, diff --git a/js/magnet.js b/js/magnet.js deleted file mode 100644 index 8329f286..00000000 --- a/js/magnet.js +++ /dev/null @@ -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); -} diff --git a/js/nostr/nip71.js b/js/nostr/nip71.js index 3f528c6f..7696d8f9 100644 --- a/js/nostr/nip71.js +++ b/js/nostr/nip71.js @@ -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"; diff --git a/js/services/videoNotePayload.js b/js/services/videoNotePayload.js index 32489c43..4dab6e33 100644 --- a/js/services/videoNotePayload.js +++ b/js/services/videoNotePayload.js @@ -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 { diff --git a/js/ui/components/EditModal.js b/js/ui/components/EditModal.js index cb9ba308..90e2bd80 100644 --- a/js/ui/components/EditModal.js +++ b/js/ui/components/EditModal.js @@ -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 { diff --git a/tests/magnet-utils.test.mjs b/tests/magnet-utils.test.mjs index 8a3b6a0f..efe42b0d 100644 --- a/tests/magnet-utils.test.mjs +++ b/tests/magnet-utils.test.mjs @@ -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"