feat: customer's torrent streamer can be set
This commit is contained in:
1 parent
0f5c73c183
commit
cd3fabc0d8
5 files changed
+38
-11
No files matched your search
@@ -47,7 +47,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='block max-w-[932px] p-0' onClose={onResolve} scrollRef={scrollRef}>
|
<Modal className='block max-w-[932px] p-0' onClose={onResolve} scrollRef={scrollRef}>
|
||||||
<div className='p-2'>
|
<div className='sticky top-[-2px] z-20 rounded-xl bg-background p-2'>
|
||||||
<ButtonsGroup className='h-10'>
|
<ButtonsGroup className='h-10'>
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
|
|||||||
@@ -1,29 +1,43 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
import { create, InstanceProps } from 'react-modal-promise';
|
import { create, InstanceProps } from 'react-modal-promise';
|
||||||
import { Check } from 'lucide-react';
|
import { Check } from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
|
||||||
import { Modal } from '@/components/ui/dialog';
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { useSetStreamUrl, useStreamUrl } from '@/hooks/useStreamUrl';
|
||||||
|
|
||||||
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
|
||||||
|
|
||||||
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
|
||||||
const prefix = usePrefix();
|
const [prefix, setPrefix] = useState(usePrefix());
|
||||||
const setPrefix = useSetPrefix();
|
const submitPrefix = useSetPrefix();
|
||||||
|
const [streamUrl, setStreamUrlValue] = useState(useStreamUrl());
|
||||||
|
const submitStreamUrl = useSetStreamUrl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='m-auto p-2' onClose={onReject}>
|
<Modal className='m-auto p-2' onClose={onReject}>
|
||||||
<form
|
<form
|
||||||
onSubmit={(event) => {
|
onSubmit={(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
submitStreamUrl(streamUrl);
|
||||||
|
submitPrefix(prefix);
|
||||||
|
|
||||||
onResolve(prefix);
|
onResolve(prefix);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ButtonsGroup className='h-10'>
|
<div className='flex flex-col gap-2'>
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder='Enter address of your torrents streamer'
|
placeholder='Enter address of your torrent streamer'
|
||||||
|
value={streamUrl}
|
||||||
|
className='h-full'
|
||||||
|
onChange={({ target: { value } }) => setStreamUrlValue(value)}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
autoFocus
|
||||||
|
placeholder='Enter address of your magnet launcher'
|
||||||
value={prefix}
|
value={prefix}
|
||||||
className='h-full'
|
className='h-full'
|
||||||
onChange={({ target: { value } }) => setPrefix(value)}
|
onChange={({ target: { value } }) => setPrefix(value)}
|
||||||
@@ -34,7 +48,7 @@ const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onRejec
|
|||||||
>
|
>
|
||||||
<Check size={16} />
|
<Check size={16} />
|
||||||
</Button>
|
</Button>
|
||||||
</ButtonsGroup>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { STREAM_URL } from '@/env';
|
import { useStreamUrl } from '@/hooks/useStreamUrl';
|
||||||
|
|
||||||
export type Source = { name: string; src: string; type: string };
|
export type Source = { name: string; src: string; type: string };
|
||||||
type Sources = { subtitles: Source[]; videos: Source[] };
|
type Sources = { subtitles: Source[]; videos: Source[] };
|
||||||
|
|
||||||
const useFiles = (magnet: string) => {
|
const useFiles = (magnet: string) => {
|
||||||
const streamUrl = `${STREAM_URL}?link=${encodeURIComponent(magnet)}`;
|
const streamUrl = `${useStreamUrl()}?link=${encodeURIComponent(magnet)}`;
|
||||||
const query = useQuery<Stream>({
|
const query = useQuery<Stream>({
|
||||||
queryKey: ['files', magnet],
|
queryKey: ['files', magnet],
|
||||||
queryFn: () => fetch(`${streamUrl}&stat`).then((response) => response.json())
|
queryFn: () => fetch(`${streamUrl}&stat`).then((response) => response.json())
|
||||||
|
|||||||
+3
-2
@@ -4,7 +4,7 @@ import { Cast, Download, ListVideo, Loader, Magnet, Play } from 'lucide-react';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
import ButtonsGroup from '@/components/ui/buttons-group';
|
||||||
import { Quality } from '@/data/parsers/yts/models';
|
import { Quality } from '@/data/parsers/yts/models';
|
||||||
import { STREAM_URL } from '@/env';
|
import { useStreamUrl } from '@/hooks/useStreamUrl';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
import { providers } from '../../../../constants';
|
import { providers } from '../../../../constants';
|
||||||
@@ -23,6 +23,7 @@ interface Props {
|
|||||||
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
||||||
const prefix = usePrefix();
|
const prefix = usePrefix();
|
||||||
const cast = useCastMagnet();
|
const cast = useCastMagnet();
|
||||||
|
const streamUrl = useStreamUrl();
|
||||||
|
|
||||||
const supportedForStream = Boolean(
|
const supportedForStream = Boolean(
|
||||||
(provider === providers.yts.key &&
|
(provider === providers.yts.key &&
|
||||||
@@ -58,7 +59,7 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
|
|||||||
className='absolute left-0 top-0 size-full'
|
className='absolute left-0 top-0 size-full'
|
||||||
target='_blank'
|
target='_blank'
|
||||||
rel='noopener noreferrer'
|
rel='noopener noreferrer'
|
||||||
href={`${STREAM_URL}?m3u&link=${encodeURIComponent(magnet)}`}
|
href={`${streamUrl}?m3u&link=${encodeURIComponent(magnet)}`}
|
||||||
/>
|
/>
|
||||||
<ListVideo size={20} />
|
<ListVideo size={20} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
|
|
||||||
|
import { STREAM_URL } from '@/env';
|
||||||
|
|
||||||
|
const streamUrlAtom = atomWithStorage<string>('stream url', STREAM_URL, undefined, {
|
||||||
|
unstable_getOnInit: true
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useSetStreamUrl = () => useSetAtom(streamUrlAtom);
|
||||||
|
|
||||||
|
export const useStreamUrl = () => useAtomValue(streamUrlAtom) || STREAM_URL;
|
||||||
Reference in new issue
Block a user