feat: customer's torrent streamer can be set

This commit is contained in:
ner committed 2025-08-14 14:29:30 +03:00
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 (
<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'>
<Input
autoFocus
@@ -1,29 +1,43 @@
import { useState } from 'react';
import { create, InstanceProps } from 'react-modal-promise';
import { Check } from 'lucide-react';
import { Button } from '@/components/ui/button';
import ButtonsGroup from '@/components/ui/buttons-group';
import { Modal } from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { useSetStreamUrl, useStreamUrl } from '@/hooks/useStreamUrl';
import { usePrefix, useSetPrefix } from '../../hooks/useMagnetHosts';
const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onReject }) => {
const prefix = usePrefix();
const setPrefix = useSetPrefix();
const [prefix, setPrefix] = useState(usePrefix());
const submitPrefix = useSetPrefix();
const [streamUrl, setStreamUrlValue] = useState(useStreamUrl());
const submitStreamUrl = useSetStreamUrl();
return (
<Modal className='m-auto p-2' onClose={onReject}>
<form
onSubmit={(event) => {
event.preventDefault();
submitStreamUrl(streamUrl);
submitPrefix(prefix);
onResolve(prefix);
}}
>
<ButtonsGroup className='h-10'>
<div className='flex flex-col gap-2'>
<Input
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}
className='h-full'
onChange={({ target: { value } }) => setPrefix(value)}
@@ -34,7 +48,7 @@ const showHostManagerModal = create<InstanceProps<string>>(({ onResolve, onRejec
>
<Check size={16} />
</Button>
</ButtonsGroup>
</div>
</form>
</Modal>
);
@@ -1,12 +1,12 @@
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 };
type Sources = { subtitles: Source[]; videos: Source[] };
const useFiles = (magnet: string) => {
const streamUrl = `${STREAM_URL}?link=${encodeURIComponent(magnet)}`;
const streamUrl = `${useStreamUrl()}?link=${encodeURIComponent(magnet)}`;
const query = useQuery<Stream>({
queryKey: ['files', magnet],
queryFn: () => fetch(`${streamUrl}&stat`).then((response) => response.json())
@@ -4,7 +4,7 @@ import { Cast, Download, ListVideo, Loader, Magnet, Play } from 'lucide-react';
import { Button } from '@/components/ui/button';
import ButtonsGroup from '@/components/ui/buttons-group';
import { Quality } from '@/data/parsers/yts/models';
import { STREAM_URL } from '@/env';
import { useStreamUrl } from '@/hooks/useStreamUrl';
import { cn } from '@/lib/utils';
import { providers } from '../../../../constants';
@@ -23,6 +23,7 @@ interface Props {
const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
const prefix = usePrefix();
const cast = useCastMagnet();
const streamUrl = useStreamUrl();
const supportedForStream = Boolean(
(provider === providers.yts.key &&
@@ -58,7 +59,7 @@ const Actions: FC<Props> = ({ torrent, backdrop, title, provider }) => {
className='absolute left-0 top-0 size-full'
target='_blank'
rel='noopener noreferrer'
href={`${STREAM_URL}?m3u&link=${encodeURIComponent(magnet)}`}
href={`${streamUrl}?m3u&link=${encodeURIComponent(magnet)}`}
/>
<ListVideo size={20} />
</Button>
+12
View File
@@ -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;