feat: series
This commit is contained in:
1 parent
b2eef6c494
commit
1e31520c92
25 files changed
+435
-223
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
import showHostManagerModal from '@/components/Movie/components/Torrents/HostManager';
|
||||
|
||||
const hostAtom = atomWithStorage<string>('magnet-host', '', undefined, {
|
||||
unstable_getOnInit: true
|
||||
});
|
||||
|
||||
export const useHost = () => useAtomValue(hostAtom);
|
||||
|
||||
export const useSetHost = () => useSetAtom(hostAtom);
|
||||
|
||||
export const useCastMagnet = () => {
|
||||
const hosts = useHost();
|
||||
|
||||
return useCallback(
|
||||
(magnet: string) => {
|
||||
const open = (hosts: string) =>
|
||||
hosts.split(',').forEach((host) => {
|
||||
const link = window.open(`http://${host}:65220/playuri?uri=${magnet}`, '_blank');
|
||||
setTimeout(() => link?.close(), 1000);
|
||||
});
|
||||
|
||||
if (!hosts) return showHostManagerModal().then(open);
|
||||
|
||||
return Promise.resolve(open(hosts));
|
||||
},
|
||||
[hosts]
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
import { useCastMagnet } from './useMagnetHosts';
|
||||
|
||||
const useUrlToMagnet = () => {
|
||||
const router = useRouter();
|
||||
const encodedUrl = useSearchParams().toString();
|
||||
|
||||
const cast = useCastMagnet();
|
||||
|
||||
useEffect(() => {
|
||||
if (!encodedUrl.includes('magnet')) return;
|
||||
|
||||
const url = decodeURIComponent(encodedUrl);
|
||||
|
||||
return void cast(url).finally(() => router.replace('/'));
|
||||
}, [encodedUrl]);
|
||||
};
|
||||
|
||||
export default useUrlToMagnet;
|
||||
Reference in new issue
Block a user