This commit is contained in:
Fredrik Burmester
2024-09-28 20:24:39 +02:00
parent ddcb410df6
commit ff88c45d43
11 changed files with 26 additions and 111 deletions

View File

@@ -39,59 +39,6 @@ const downloads: React.FC = () => {
return Object.values(series); return Object.values(series);
}, [downloadedFiles]); }, [downloadedFiles]);
useEffect(() => {
(async () => {
const dir = FileSystem.documentDirectory;
if (dir) {
const items = await FileSystem.readDirectoryAsync(dir);
if (items.length === 0) {
console.log("No items found in the document directory.");
return;
}
for (const item of items) {
const fullPath = `${dir}${item}`;
const info = await FileSystem.getInfoAsync(fullPath);
if (info.exists) {
if (info.isDirectory) {
// List items in the directory
// const subItems = await FileSystem.readDirectoryAsync(fullPath);
// if (subItems.length === 0) {
// console.log(`Directory ${item} is empty.`);
// } else {
// console.log(`Items in ${item}:`, subItems);
// // If item ends in m3u8, print the content of the file
// const m3u8Files = subItems.filter((subItem) =>
// subItem.endsWith(".m3u8")
// );
// if (m3u8Files.length === 0) {
// console.log(`No .m3u8 files found in ${item}.`);
// } else {
// for (let subItem of m3u8Files) {
// console.log(
// `Content of ${subItem}:`,
// await FileSystem.readAsStringAsync(
// `${fullPath}/${subItem}`
// )
// );
// }
// }
// }
} else {
console.log(`${item} is a file`);
}
} else {
console.log(`${item} does not exist.`);
}
}
} else {
console.log("Document directory is not available.");
}
})();
}, []);
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
return ( return (
@@ -121,9 +68,9 @@ const downloads: React.FC = () => {
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
clearProcess(); clearProcess();
setQueue(async (prev) => { setQueue((prev) => {
if (!prev) return []; if (!prev) return [];
return [...(await prev).filter((i) => i.id !== q.id)]; return [...prev.filter((i) => i.id !== q.id)];
}); });
}} }}
> >

View File

@@ -39,7 +39,6 @@ export default function settings() {
code: text, code: text,
userId: user?.Id, userId: user?.Id,
}); });
console.log(res.status, res.statusText, res.data);
if (res.status === 200) { if (res.status === 200) {
Haptics.notificationAsync( Haptics.notificationAsync(
Haptics.NotificationFeedbackType.Success Haptics.NotificationFeedbackType.Success

View File

@@ -20,8 +20,6 @@ const page: React.FC = () => {
seasonIndex: string; seasonIndex: string;
}; };
console.log("seasonIndex", seasonIndex);
const [api] = useAtom(apiAtom); const [api] = useAtom(apiAtom);
const [user] = useAtom(userAtom); const [user] = useAtom(userAtom);

View File

@@ -69,13 +69,11 @@ const Page = () => {
useEffect(() => { useEffect(() => {
const sop = getSortOrderPreference(libraryId, sortOrderPreference); const sop = getSortOrderPreference(libraryId, sortOrderPreference);
if (sop) { if (sop) {
console.log("getSortOrderPreference ~", sop, libraryId);
_setSortOrder([sop]); _setSortOrder([sop]);
} else { } else {
_setSortOrder([SortOrderOption.Ascending]); _setSortOrder([SortOrderOption.Ascending]);
} }
const obp = getSortByPreference(libraryId, sortByPreference); const obp = getSortByPreference(libraryId, sortByPreference);
console.log("getSortByPreference ~", obp, libraryId);
if (obp) { if (obp) {
_setSortBy([obp]); _setSortBy([obp]);
} else { } else {
@@ -87,7 +85,6 @@ const Page = () => {
(sortBy: SortByOption[]) => { (sortBy: SortByOption[]) => {
const sop = getSortByPreference(libraryId, sortByPreference); const sop = getSortByPreference(libraryId, sortByPreference);
if (sortBy[0] !== sop) { if (sortBy[0] !== sop) {
console.log("setSortByPreference ~", sortBy[0], libraryId);
setSortByPreference({ ...sortByPreference, [libraryId]: sortBy[0] }); setSortByPreference({ ...sortByPreference, [libraryId]: sortBy[0] });
} }
_setSortBy(sortBy); _setSortBy(sortBy);
@@ -99,7 +96,6 @@ const Page = () => {
(sortOrder: SortOrderOption[]) => { (sortOrder: SortOrderOption[]) => {
const sop = getSortOrderPreference(libraryId, sortOrderPreference); const sop = getSortOrderPreference(libraryId, sortOrderPreference);
if (sortOrder[0] !== sop) { if (sortOrder[0] !== sop) {
console.log("setSortOrderPreference ~", sortOrder[0], libraryId);
setOderByPreference({ setOderByPreference({
...sortOrderPreference, ...sortOrderPreference,
[libraryId]: sortOrder[0], [libraryId]: sortOrder[0],

View File

@@ -99,7 +99,6 @@ function Layout() {
useEffect(() => { useEffect(() => {
const subscription = ScreenOrientation.addOrientationChangeListener( const subscription = ScreenOrientation.addOrientationChangeListener(
(event) => { (event) => {
console.log(event.orientationInfo.orientation);
setOrientation(event.orientationInfo.orientation); setOrientation(event.orientationInfo.orientation);
} }
); );

View File

@@ -29,6 +29,7 @@ import { Loader } from "./Loader";
import { MediaSourceSelector } from "./MediaSourceSelector"; import { MediaSourceSelector } from "./MediaSourceSelector";
import ProgressCircle from "./ProgressCircle"; import ProgressCircle from "./ProgressCircle";
import { SubtitleTrackSelector } from "./SubtitleTrackSelector"; import { SubtitleTrackSelector } from "./SubtitleTrackSelector";
import { toast } from "sonner-native";
interface DownloadProps extends ViewProps { interface DownloadProps extends ViewProps {
item: BaseItemDto; item: BaseItemDto;
@@ -65,9 +66,7 @@ export const DownloadItem: React.FC<DownloadProps> = ({ item, ...props }) => {
bottomSheetModalRef.current?.present(); bottomSheetModalRef.current?.present();
}, []); }, []);
const handleSheetChanges = useCallback((index: number) => { const handleSheetChanges = useCallback((index: number) => {}, []);
console.log("handleSheetChanges", index);
}, []);
const closeModal = useCallback(() => { const closeModal = useCallback(() => {
bottomSheetModalRef.current?.dismiss(); bottomSheetModalRef.current?.dismiss();
@@ -286,22 +285,19 @@ export const DownloadItem: React.FC<DownloadProps> = ({ item, ...props }) => {
onPress={() => { onPress={() => {
if (userCanDownload === true) { if (userCanDownload === true) {
if (!item.Id) { if (!item.Id) {
Alert.alert("Error", "Item ID is undefined."); throw new Error("No item id");
return;
} }
closeModal(); closeModal();
queueActions.enqueue(queue, setQueue, { initiateDownload();
id: item.Id, // Remove for now
execute: async () => { // queueActions.enqueue(queue, setQueue, {
await initiateDownload(); // id: item.Id,
}, // execute: async () => {
item, // },
}); // item,
// });
} else { } else {
Alert.alert( toast.error("You are not allowed to download files.");
"Disabled",
"This user is not allowed to download files."
);
} }
}} }}
color="purple" color="purple"

View File

@@ -118,8 +118,6 @@ export const ItemContent: React.FC<{ id: string }> = React.memo(({ id }) => {
itemId: id, itemId: id,
}); });
console.log("itemID", res?.Id);
return res; return res;
}, },
enabled: !!id && !!api, enabled: !!id && !!api,

View File

@@ -163,7 +163,6 @@ export const PlayButton: React.FC<Props> = ({ item, url, ...props }) => {
}); });
break; break;
case 1: case 1:
console.log("Device");
setCurrentlyPlayingState({ item, url }); setCurrentlyPlayingState({ item, url });
router.push("/play"); router.push("/play");
break; break;

View File

@@ -76,7 +76,6 @@ export const ActiveDownload: React.FC<Props> = ({ ...props }) => {
<View className="p-4 flex flex-row items-center justify-between w-full"> <View className="p-4 flex flex-row items-center justify-between w-full">
<View> <View>
<Text className="font-semibold">{process.item.Name}</Text> <Text className="font-semibold">{process.item.Name}</Text>
<Text className="text-xs opacity-50">{process.item.Id}</Text>
<Text className="text-xs opacity-50">{process.item.Type}</Text> <Text className="text-xs opacity-50">{process.item.Type}</Text>
<View className="flex flex-row items-center space-x-2 mt-1 text-purple-600"> <View className="flex flex-row items-center space-x-2 mt-1 text-purple-600">
<Text className="text-xs">{process.progress.toFixed(0)}%</Text> <Text className="text-xs">{process.progress.toFixed(0)}%</Text>

View File

@@ -14,6 +14,7 @@ import {
} from "@tanstack/react-query"; } from "@tanstack/react-query";
import axios from "axios"; import axios from "axios";
import * as FileSystem from "expo-file-system"; import * as FileSystem from "expo-file-system";
import { useRouter } from "expo-router";
import React, { import React, {
createContext, createContext,
useCallback, useCallback,
@@ -42,7 +43,7 @@ function useDownloadProvider() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [process, setProcess] = useState<ProcessItem | null>(null); const [process, setProcess] = useState<ProcessItem | null>(null);
const [settings] = useSettings(); const [settings] = useSettings();
const router = useRouter();
const authHeader = useMemo(() => { const authHeader = useMemo(() => {
return `Bearer ${settings?.optimizedVersionsAuthHeader}`; return `Bearer ${settings?.optimizedVersionsAuthHeader}`;
}, [settings]); }, [settings]);
@@ -185,8 +186,6 @@ function useDownloadProvider() {
return; return;
} }
// console.log("Job ~", job);
// Update the local process state with the state from the server. // Update the local process state with the state from the server.
let newState: ProcessItem["state"] = "optimizing"; let newState: ProcessItem["state"] = "optimizing";
if (job.status === "completed") { if (job.status === "completed") {
@@ -260,7 +259,14 @@ function useDownloadProvider() {
state: "optimizing", state: "optimizing",
}); });
toast.success(`Optimization started for ${item.Name}`); toast.success(`Optimization started for ${item.Name}`, {
action: {
label: "Go to download",
onClick: () => {
router.push("/downloads");
},
},
});
} 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}`);

View File

@@ -10,31 +10,9 @@ export interface Job {
execute: () => void | Promise<void>; execute: () => void | Promise<void>;
} }
export const runningAtom = atomWithStorage<boolean>("queueRunning", false, { export const runningAtom = atom<boolean>(false);
getItem: async (key) => {
const value = await AsyncStorage.getItem(key);
return value ? JSON.parse(value) : false;
},
setItem: async (key, value) => {
await AsyncStorage.setItem(key, JSON.stringify(value));
},
removeItem: async (key) => {
await AsyncStorage.removeItem(key);
},
});
export const queueAtom = atomWithStorage<Job[]>("queueJobs", [], { export const queueAtom = atom<Job[]>([]);
getItem: async (key) => {
const value = await AsyncStorage.getItem(key);
return value ? JSON.parse(value) : [];
},
setItem: async (key, value) => {
await AsyncStorage.setItem(key, JSON.stringify(value));
},
removeItem: async (key) => {
await AsyncStorage.removeItem(key);
},
});
export const queueActions = { export const queueActions = {
enqueue: (queue: Job[], setQueue: (update: Job[]) => void, job: Job) => { enqueue: (queue: Job[], setQueue: (update: Job[]) => void, job: Job) => {