fix: standardize Old Book → Old Books folder name

- filebrowserFolders.js: createTaskFolder now creates Old Books
- fbq-backfill: creates Old Books; migrateOldBook() merges/renames
  existing Old Book folders into Old Books on each backfill run

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Krao Hasanee
2026-05-31 11:07:59 -04:00
parent 5b3060e190
commit 94d9c3904b
2 changed files with 42 additions and 2 deletions
+41 -1
View File
@@ -32,6 +32,45 @@ function mime(name: string) {
return m[e] ?? 'application/octet-stream';
}
async function listDir(path: string): Promise<{ name: string; type: string }[] | null> {
const r = await fetch(`${FBQ_URL}/api/resources?source=${SOURCE}&path=${encodeURIComponent(path)}`, { headers: fbqH });
if (!r.ok) return null;
const data = await r.json().catch(() => null);
return [...(data?.folders ?? []), ...(data?.files ?? [])];
}
async function renameDir(fromPath: string, toPath: string) {
await fetch(`${FBQ_URL}/api/resources?source=${SOURCE}`, {
method: 'PATCH',
headers: { ...fbqH, 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'rename', items: [{ fromSource: SOURCE, fromPath, toSource: SOURCE, toPath }], overwrite: false }),
});
}
async function deleteDir(path: string) {
await fetch(`${FBQ_URL}/api/resources?source=${SOURCE}&path=${encodeURIComponent(path.endsWith('/') ? path : path + '/')}`, {
method: 'DELETE', headers: fbqH,
});
}
async function migrateOldBook(base: string) {
const src = `${base}/Old Book`;
const dst = `${base}/Old Books`;
const srcItems = await listDir(src);
if (srcItems === null) return; // Old Book doesn't exist
const dstItems = await listDir(dst);
if (dstItems === null) {
// Old Books doesn't exist — simple rename
await renameDir(src, dst);
} else {
// Both exist — move each item from Old Book into Old Books, then delete Old Book
for (const item of srcItems) {
await renameDir(`${src}/${item.name}`, `${dst}/${item.name}`);
}
await deleteDir(src);
}
}
async function chunkAll<T>(items: T[], fn: (item: T) => Promise<void>, size = 8) {
for (let i = 0; i < items.length; i += size) {
await Promise.all(items.slice(i, i + size).map(fn));
@@ -90,7 +129,8 @@ Deno.serve(async () => {
]);
const taskIsNew = await mkdir(base);
await Promise.all([mkdir(`${base}/Request Info`), mkdir(`${base}/Old Book`)]);
await Promise.all([mkdir(`${base}/Request Info`), mkdir(`${base}/Old Books`)]);
await migrateOldBook(base);
if (taskIsNew) { newTasks.push({ task, base, co, pr }); created++; }
else skipped++;