feat: fetch toloka's magnets

This commit is contained in:
ner committed 2024-10-27 12:14:40 +02:00
1 parent 8691c7d66d
commit 7d223e4d1b
2 files changed
+2 -12

No files matched your search

@@ -4,8 +4,6 @@ import { atomWithStorage } from 'jotai/utils';
import showHostManagerModal from '@/components/Preview/components/Torrents/components/HostManager';
import { STREAM_URL } from '../constants';
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:9090/magnet?magnet=', undefined, {
unstable_getOnInit: true
});
@@ -18,15 +16,7 @@ export const useCastMagnet = () => {
const prefix = usePrefix();
return useCallback(
async (link: string) => {
let magnet = link;
if (link && !link.startsWith('magnet')) {
magnet = await fetch(`${STREAM_URL}${encodeURIComponent(link)}&stat=true`)
.then((response) => response.json())
.then((torrent: Stream) => `magnet:?xt=urn:btih:${torrent.hash}&dn=${encodeURIComponent(torrent.name)}`);
}
(magnet: string) => {
const open = (prefix: string) => {
const link = window.open(`${prefix}${magnet}`, '_blank');
setTimeout(() => link?.close(), 1000);