mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-06-05 13:38:27 +01:00
wip
This commit is contained in:
@@ -21,7 +21,11 @@ export const ActiveDownload: React.FC<Props> = ({ ...props }) => {
|
|||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
if (!process) throw new Error("No active download");
|
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();
|
const tasks = await checkForExistingDownloads();
|
||||||
for (const task of tasks) task.stop();
|
for (const task of tasks) task.stop();
|
||||||
clearProcess();
|
clearProcess();
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ export const SettingToggles: React.FC<Props> = ({ ...props }) => {
|
|||||||
const [marlinUrl, setMarlinUrl] = useState<string>("");
|
const [marlinUrl, setMarlinUrl] = useState<string>("");
|
||||||
const [optimizedVersionsServerUrl, setOptimizedVersionsServerUrl] =
|
const [optimizedVersionsServerUrl, setOptimizedVersionsServerUrl] =
|
||||||
useState<string>("");
|
useState<string>("");
|
||||||
|
const [optimizedVersionsAuthHeader, setOptimizedVersionsAuthHeader] =
|
||||||
|
useState<string>("");
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -500,6 +502,51 @@ export const SettingToggles: React.FC<Props> = ({ ...props }) => {
|
|||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</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>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { toast } from "sonner-native";
|
import { toast } from "sonner-native";
|
||||||
@@ -42,6 +43,10 @@ function useDownloadProvider() {
|
|||||||
const [process, setProcess] = useState<ProcessItem | null>(null);
|
const [process, setProcess] = useState<ProcessItem | null>(null);
|
||||||
const [settings] = useSettings();
|
const [settings] = useSettings();
|
||||||
|
|
||||||
|
const authHeader = useMemo(() => {
|
||||||
|
return `Bearer ${settings?.optimizedVersionsAuthHeader}`;
|
||||||
|
}, [settings]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: downloadedFiles,
|
data: downloadedFiles,
|
||||||
isLoading,
|
isLoading,
|
||||||
@@ -105,8 +110,12 @@ function useDownloadProvider() {
|
|||||||
id: process.id,
|
id: process.id,
|
||||||
url: settings?.optimizedVersionsServerUrl + "download/" + process.id,
|
url: settings?.optimizedVersionsServerUrl + "download/" + process.id,
|
||||||
destination: `${directories.documents}/${process?.item.Id}.mp4`,
|
destination: `${directories.documents}/${process?.item.Id}.mp4`,
|
||||||
|
headers: {
|
||||||
|
Authorization: authHeader,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.begin(() => {
|
.begin(() => {
|
||||||
|
toast.info(`Download started for ${process.item.Name}`);
|
||||||
updateProcess((prev) => {
|
updateProcess((prev) => {
|
||||||
if (!prev) return null;
|
if (!prev) return null;
|
||||||
return {
|
return {
|
||||||
@@ -167,7 +176,8 @@ function useDownloadProvider() {
|
|||||||
if (process.state === "optimizing") {
|
if (process.state === "optimizing") {
|
||||||
const job = await checkJobStatus(
|
const job = await checkJobStatus(
|
||||||
process.id,
|
process.id,
|
||||||
settings?.optimizedVersionsServerUrl
|
settings?.optimizedVersionsServerUrl,
|
||||||
|
authHeader
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!job) {
|
if (!job) {
|
||||||
@@ -232,6 +242,7 @@ function useDownloadProvider() {
|
|||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
Authorization: authHeader,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -249,7 +260,7 @@ function useDownloadProvider() {
|
|||||||
state: "optimizing",
|
state: "optimizing",
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success(`Optimization job started for ${item.Name}`);
|
toast.success(`Optimization started for ${item.Name}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in startBackgroundDownload:", error);
|
console.error("Error in startBackgroundDownload:", error);
|
||||||
toast.error(`Failed to start download for ${item.Name}`);
|
toast.error(`Failed to start download for ${item.Name}`);
|
||||||
@@ -428,13 +439,17 @@ export function useDownload() {
|
|||||||
|
|
||||||
const checkJobStatus = async (
|
const checkJobStatus = async (
|
||||||
id: string,
|
id: string,
|
||||||
baseUrl: string
|
baseUrl: string,
|
||||||
|
authHeader?: string | null
|
||||||
): Promise<{
|
): Promise<{
|
||||||
progress: number;
|
progress: number;
|
||||||
status: "running" | "completed" | "failed" | "cancelled";
|
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) {
|
if (statusResponse.status !== 200) {
|
||||||
throw new Error("Failed to fetch job status");
|
throw new Error("Failed to fetch job status");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ type Settings = {
|
|||||||
forwardSkipTime: number;
|
forwardSkipTime: number;
|
||||||
rewindSkipTime: number;
|
rewindSkipTime: number;
|
||||||
optimizedVersionsServerUrl?: string | null;
|
optimizedVersionsServerUrl?: string | null;
|
||||||
|
optimizedVersionsAuthHeader?: string | null;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user