41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
export async function listFolder(folder, recursive) {
|
|
try {
|
|
const url =
|
|
`/dumas/api/load_images_folder/list?path=${encodeURIComponent(folder)}` +
|
|
`&recursive=${recursive ? 1 : 0}`;
|
|
const response = await fetch(url, { cache: "no-store" });
|
|
return await response.json();
|
|
} catch (error) {
|
|
return { ok: false, message: String(error), files: [] };
|
|
}
|
|
}
|
|
|
|
export function thumbURL(folder, rel, mtime) {
|
|
return (
|
|
`/dumas/api/load_images_folder/thumb?path=${encodeURIComponent(folder)}` +
|
|
`&file=${encodeURIComponent(rel)}&mt=${Math.floor(mtime || 0)}`
|
|
);
|
|
}
|
|
|
|
export async function browseFolder(path) {
|
|
try {
|
|
const response = await fetch(
|
|
`/dumas/api/load_images_folder/browse?path=${encodeURIComponent(path || "")}`,
|
|
);
|
|
return await response.json();
|
|
} catch (error) {
|
|
return { ok: false, message: String(error), dirs: [] };
|
|
}
|
|
}
|
|
|
|
export async function pickNativeFolder(startPath) {
|
|
try {
|
|
const response = await fetch(
|
|
`/dumas/api/load_images_folder/pick_native?path=${encodeURIComponent(startPath || "")}`,
|
|
);
|
|
return await response.json();
|
|
} catch (error) {
|
|
return { ok: false, message: String(error) };
|
|
}
|
|
}
|