log: migration

This commit is contained in:
ner committed 2024-10-27 16:49:12 +02:00
commit 1fe912f4bd
16 files changed
+199 -372

No files matched your search

@@ -50,7 +50,7 @@ const Actions = ({ onClose, show, className }: Props) => {
<Bookmark size={14} className={cn({ 'fill-secondary-foreground': state?.watchlist })} />
</Button>
</ButtonsGroup>
<ButtonsGroup className='gap-0'>
<ButtonsGroup>
<Button
onClick={() => {
onClose?.();
@@ -64,7 +64,10 @@ const Actions = ({ onClose, show, className }: Props) => {
</Button>
<Button
aria-label='Watch'
className={cn({ 'bg-red-600': theme === 'light', 'bg-red-700': theme === 'dark' })}
className={cn('hover:shadow-lg hover:shadow-red-600/60 duration-200 transition-all hover:bg-red-600', {
'bg-red-600': theme === 'light',
'bg-red-700': theme === 'dark'
})}
variant='destructive'
onClick={() =>
showTorrentsModal({
@@ -1,10 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import { STREAM_URL as BASE_STREAM_URL } from '../../constants';
export type Source = { name: string; src: string; type: string };
type Sources = { subtitles: Source[]; videos: Source[] };
const useFiles = (magnet: string) => {
const STREAM_URL = `${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?link=${encodeURIComponent(magnet)}`;
const STREAM_URL = `${BASE_STREAM_URL}${encodeURIComponent(magnet)}`;
const query = useQuery<Stream>({
queryKey: ['files', magnet],
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { Cast, ListVideo, Magnet, Play } from 'lucide-react';
import { Cast, Download, ListVideo, Loader, Magnet, Play } from 'lucide-react';
import { Quality } from '@/api/parsers/yts/models';
import { Button } from '@/components/ui/button';
@@ -22,7 +22,6 @@ interface Props {
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
const prefix = usePrefix();
const cast = useCastMagnet();
const { mutateAsync, isPending } = useMagnet();
const supportedForStream = Boolean(
(provider === providers.yts.key &&
@@ -31,58 +30,63 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
torrent.container?.includes('mp4')
);
const fetchMagnet = useMagnet(torrent);
const magnet = fetchMagnet.data || torrent.magnet;
const supportedForCast = prefix && !prefix.includes('{host}');
const prefetchMagnet = (handler: (magnet: string) => void) => () => {
if (!torrent.download) return handler(torrent.magnet);
return mutateAsync(torrent.download).then((magnet) => handler(magnet));
};
return (
<ButtonsGroup className='ml-auto w-fit grow-0'>
{supportedForStream && (
<Button
disabled={isPending}
variant='destructive'
className={cn('flex-grow-0 px-3 bg-red-600')}
onClick={prefetchMagnet((magnet) => showPlayer({ magnet, backdrop, title }))}
title='Play'
>
<Play size={15} />
<div className='relative ml-auto w-fit grow-0'>
<ButtonsGroup>
{supportedForStream && (
<Button
variant='destructive'
className={cn(
'flex-grow-0 px-3 bg-red-600',
'hover:shadow-lg hover:shadow-red-600/60 duration-200 transition-all hover:bg-red-600'
)}
onClick={() => showPlayer({ magnet, backdrop, title })}
title='Play'
>
<Play size={15} />
</Button>
)}
<Button variant='outline' className='relative grow-0 px-3' title='Download m3u playlist'>
<a
className='absolute left-0 top-0 size-full'
href={`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(magnet)}`}
/>
<ListVideo size={20} />
</Button>
)}
<Button
disabled={isPending}
variant='outline'
className='relative grow-0 px-3'
title='Play using your native video player'
onClick={prefetchMagnet((magnet) => {
window.open(`${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?m3u&link=${encodeURIComponent(magnet)}`);
})}
>
<ListVideo size={20} />
</Button>
<Button
disabled={isPending}
className='relative grow-0 px-3'
variant='outline'
onClick={prefetchMagnet((magnet) => window.open(magnet))}
title='Download magnet'
>
<Magnet size={20} />
</Button>
{supportedForCast && (
<Button className='relative grow-0 px-3' variant='outline' title='Download magnet'>
<a className='absolute left-0 top-0 size-full' href={magnet} />
<Magnet size={20} />
</Button>
{supportedForCast && (
<Button className='grow-0 px-3' variant='outline' onClick={() => cast(magnet)}>
<Cast size={20} />
</Button>
)}
</ButtonsGroup>
{!magnet && (
<Button
disabled={isPending}
className='grow-0 px-3'
title='Fetch files'
variant='outline'
onClick={prefetchMagnet((magnet) => cast(magnet))}
disabled={fetchMagnet.isPending}
onClick={() => fetchMagnet.mutate()}
className={cn('z-10 h-8 absolute size-full left-0 top-0 rounded-md disabled:opacity-100')}
>
<Cast size={20} />
{fetchMagnet.isPending ? (
<div className='animate-spin'>
<Loader size={18} />
</div>
) : (
<Download size={18} />
)}
</Button>
)}
</ButtonsGroup>
</div>
);
};
@@ -1,9 +1,20 @@
import { useMutation } from '@tanstack/react-query';
import { fetchTLKMagnet } from '@/api';
const useMagnet = (torrent: Torrent) => {
return useMutation({
retry: 4,
mutationFn: async () => {
try {
const response = await fetch(`/api/magnet?url=${torrent.download}`);
const useMagnet = () => {
return useMutation({ mutationFn: fetchTLKMagnet });
if (!response.ok) return Promise.reject();
return response.json();
} catch (error) {
return Promise.reject(error);
}
}
});
};
export default useMagnet;
@@ -48,7 +48,7 @@ const TorrentsTable: FC<Props> = ({ title, torrents, backdrop, sort, sortable, p
const yearView = torrent.year && year.toString() != torrent.year && `[${torrent.year}]`;
return (
<Fragment key={torrent.magnet + torrent.id}>
<Fragment key={torrent.magnet + torrent.id + torrent.download}>
<TableRow className='table-row border-b-0 hover:bg-transparent md:hidden'>
<TableCell className='break-all p-2' colSpan={colSpan}>
<span className='flex w-full flex-wrap items-center gap-3'>
@@ -1,5 +1,7 @@
import { Sort } from '@/api/parsers';
export const STREAM_URL = `${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream?link=`;
type Options = { query: string; sort: Sort; imdbID: string };
const queryFn = ({ query, sort, imdbID, key }: Options & { key: keyof typeof providers }) =>
@@ -4,7 +4,7 @@ import { atomWithStorage } from 'jotai/utils';
import showHostManagerModal from '@/components/Preview/components/Torrents/components/HostManager';
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:65220/playuri?uri=', undefined, {
const magnetPrefixAtom = atomWithStorage<string>('magnet-prefix', 'http://{host}:9090/magnet?magnet=', undefined, {
unstable_getOnInit: true
});