Added torrent file upload support

This commit is contained in:
2025-10-31 13:53:07 +03:30
parent 616614cf30
commit 906eb10eb2
8 changed files with 378 additions and 85 deletions
+18
View File
@@ -0,0 +1,18 @@
import parseTorrent from "parse-torrent";
import type { MagnetUrl } from "../../shared/types/magnet";
export async function parseTorrentFileToMagnetUrl(
file: Buffer
): Promise<MagnetUrl> {
const parsed = await parseTorrent(file);
const magnet: MagnetUrl = {
xt: `urn:btih:${parsed.infoHash}`,
dn: Array.isArray(parsed.name) ? parsed.name.join(" ") : parsed.name,
tr: parsed.announce || [],
xs: parsed.urlList || [],
// as, kt, mt are rarely present in .torrent files, but you can add if needed
};
return magnet;
}