mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
wip
This commit is contained in:
@@ -21,7 +21,11 @@ export const ActiveDownload: React.FC<Props> = ({ ...props }) => {
|
||||
mutationFn: async () => {
|
||||
if (!process) throw new Error("No active download");
|
||||
|
||||
await axios.delete(settings?.optimizedVersionsServerUrl + process.id);
|
||||
await axios.delete(settings?.optimizedVersionsServerUrl + process.id, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${settings?.optimizedVersionsAuthHeader}`,
|
||||
},
|
||||
});
|
||||
const tasks = await checkForExistingDownloads();
|
||||
for (const task of tasks) task.stop();
|
||||
clearProcess();
|
||||
|
||||
@@ -35,6 +35,8 @@ export const SettingToggles: React.FC<Props> = ({ ...props }) => {
|
||||
const [marlinUrl, setMarlinUrl] = useState<string>("");
|
||||
const [optimizedVersionsServerUrl, setOptimizedVersionsServerUrl] =
|
||||
useState<string>("");
|
||||
const [optimizedVersionsAuthHeader, setOptimizedVersionsAuthHeader] =
|
||||
useState<string>("");
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -500,6 +502,51 @@ export const SettingToggles: React.FC<Props> = ({ ...props }) => {
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
<View className="flex flex-col bg-neutral-900 px-4 py-4">
|
||||
<View className="flex flex-col shrink mb-2">
|
||||
<Text className="font-semibold">
|
||||
Optimized versions auth header
|
||||
</Text>
|
||||
<Text className="text-xs opacity-50">
|
||||
The auth header for the optimized versions server.
|
||||
</Text>
|
||||
</View>
|
||||
<View className="flex flex-row items-center space-x-2">
|
||||
<View className="shrink">
|
||||
<Input
|
||||
placeholder="Optimized versions server URL..."
|
||||
defaultValue={
|
||||
settings.optimizedVersionsAuthHeader
|
||||
? settings.optimizedVersionsAuthHeader
|
||||
: ""
|
||||
}
|
||||
value={optimizedVersionsAuthHeader}
|
||||
keyboardType="url"
|
||||
returnKeyType="done"
|
||||
autoCapitalize="none"
|
||||
textContentType="URL"
|
||||
onChangeText={(text) => setOptimizedVersionsAuthHeader(text)}
|
||||
/>
|
||||
</View>
|
||||
<Button
|
||||
color="purple"
|
||||
className=" w-16 h-12"
|
||||
onPress={() => {
|
||||
updateSettings({
|
||||
optimizedVersionsAuthHeader,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</View>
|
||||
|
||||
{settings.optimizedVersionsAuthHeader && (
|
||||
<Text className="text-neutral-500 mt-2">
|
||||
Current: {settings.optimizedVersionsAuthHeader}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -19,6 +19,7 @@ import React, {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { toast } from "sonner-native";
|
||||
@@ -42,6 +43,10 @@ function useDownloadProvider() {
|
||||
const [process, setProcess] = useState<ProcessItem | null>(null);
|
||||
const [settings] = useSettings();
|
||||
|
||||
const authHeader = useMemo(() => {
|
||||
return `Bearer ${settings?.optimizedVersionsAuthHeader}`;
|
||||
}, [settings]);
|
||||
|
||||
const {
|
||||
data: downloadedFiles,
|
||||
isLoading,
|
||||
@@ -105,8 +110,12 @@ function useDownloadProvider() {
|
||||
id: process.id,
|
||||
url: settings?.optimizedVersionsServerUrl + "download/" + process.id,
|
||||
destination: `${directories.documents}/${process?.item.Id}.mp4`,
|
||||
headers: {
|
||||
Authorization: authHeader,
|
||||
},
|
||||
})
|
||||
.begin(() => {
|
||||
toast.info(`Download started for ${process.item.Name}`);
|
||||
updateProcess((prev) => {
|
||||
if (!prev) return null;
|
||||
return {
|
||||
@@ -167,7 +176,8 @@ function useDownloadProvider() {
|
||||
if (process.state === "optimizing") {
|
||||
const job = await checkJobStatus(
|
||||
process.id,
|
||||
settings?.optimizedVersionsServerUrl
|
||||
settings?.optimizedVersionsServerUrl,
|
||||
authHeader
|
||||
);
|
||||
|
||||
if (!job) {
|
||||
@@ -232,6 +242,7 @@ function useDownloadProvider() {
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: authHeader,
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -249,7 +260,7 @@ function useDownloadProvider() {
|
||||
state: "optimizing",
|
||||
});
|
||||
|
||||
toast.success(`Optimization job started for ${item.Name}`);
|
||||
toast.success(`Optimization started for ${item.Name}`);
|
||||
} catch (error) {
|
||||
console.error("Error in startBackgroundDownload:", error);
|
||||
toast.error(`Failed to start download for ${item.Name}`);
|
||||
@@ -428,13 +439,17 @@ export function useDownload() {
|
||||
|
||||
const checkJobStatus = async (
|
||||
id: string,
|
||||
baseUrl: string
|
||||
baseUrl: string,
|
||||
authHeader?: string | null
|
||||
): Promise<{
|
||||
progress: number;
|
||||
status: "running" | "completed" | "failed" | "cancelled";
|
||||
}> => {
|
||||
const statusResponse = await axios.get(`${baseUrl}job-status/${id}`);
|
||||
|
||||
const statusResponse = await axios.get(`${baseUrl}job-status/${id}`, {
|
||||
headers: {
|
||||
Authorization: authHeader,
|
||||
},
|
||||
});
|
||||
if (statusResponse.status !== 200) {
|
||||
throw new Error("Failed to fetch job status");
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ type Settings = {
|
||||
forwardSkipTime: number;
|
||||
rewindSkipTime: number;
|
||||
optimizedVersionsServerUrl?: string | null;
|
||||
optimizedVersionsAuthHeader?: string | null;
|
||||
};
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user