diff --git a/components/downloads/ActiveDownload.tsx b/components/downloads/ActiveDownload.tsx index f08e00f0..898feb59 100644 --- a/components/downloads/ActiveDownload.tsx +++ b/components/downloads/ActiveDownload.tsx @@ -18,10 +18,10 @@ export const ActiveDownload: React.FC = ({ ...props }) => { const [settings] = useSettings(); const cancelJobMutation = useMutation({ - mutationFn: async (id: string) => { - if (!process) return; + mutationFn: async () => { + if (!process) throw new Error("No active download"); - await axios.delete(settings?.optimizedVersionsServerUrl + id); + await axios.delete(settings?.optimizedVersionsServerUrl + process.id); const tasks = await checkForExistingDownloads(); for (const task of tasks) task.stop(); clearProcess(); @@ -29,7 +29,8 @@ export const ActiveDownload: React.FC = ({ ...props }) => { onSuccess: () => { toast.success("Download cancelled"); }, - onError: () => { + onError: (e) => { + console.log(e); toast.error("Failed to cancel download"); }, }); @@ -71,9 +72,7 @@ export const ActiveDownload: React.FC = ({ ...props }) => { {process.state} - cancelJobMutation.mutate(process.id)} - > + cancelJobMutation.mutate()}> diff --git a/hooks/useRemuxHlsToMp4.ts b/hooks/useRemuxHlsToMp4.ts index 0a41bb14..564f7c1d 100644 --- a/hooks/useRemuxHlsToMp4.ts +++ b/hooks/useRemuxHlsToMp4.ts @@ -30,6 +30,8 @@ export const useRemuxHlsToMp4 = (item: BaseItemDto) => { const startRemuxing = useCallback( async (url: string) => { + if (!item.Id) throw new Error("Item must have an Id"); + toast.success("Download started"); const command = `-y -loglevel quiet -thread_queue_size 512 -protocol_whitelist file,http,https,tcp,tls,crypto -multiple_requests 1 -tcp_nodelay 1 -fflags +genpts -i ${url} -c copy -bufsize 50M -max_muxing_queue_size 4096 ${output}`; @@ -41,7 +43,7 @@ export const useRemuxHlsToMp4 = (item: BaseItemDto) => { try { updateProcess({ - id: item.Id!, + id: item.Id, item, progress: 0, state: "downloading", @@ -53,7 +55,6 @@ export const useRemuxHlsToMp4 = (item: BaseItemDto) => { const fps = item.MediaStreams?.[0]?.RealFrameRate || 25; const totalFrames = videoLength * fps; const processedFrames = statistics.getVideoFrameNumber(); - const speed = statistics.getSpeed(); const percentage = totalFrames > 0 @@ -76,6 +77,7 @@ export const useRemuxHlsToMp4 = (item: BaseItemDto) => { const returnCode = await session.getReturnCode(); if (returnCode.isValueSuccess()) { + if (!item) throw new Error("Item is undefined"); await saveDownloadedItemInfo(item); toast.success("Download completed"); writeToLog( diff --git a/providers/DownloadProvider.tsx b/providers/DownloadProvider.tsx index 9718b941..71f3dccd 100644 --- a/providers/DownloadProvider.tsx +++ b/providers/DownloadProvider.tsx @@ -385,6 +385,8 @@ function useDownloadProvider() { } await AsyncStorage.setItem("downloadedItems", JSON.stringify(items)); + await queryClient.invalidateQueries({ queryKey: ["downloadedItems"] }); + refetch(); } catch (error) { console.error("Failed to save downloaded item information:", error); }