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:
@@ -50,7 +50,7 @@ export async function createTaskFolder(companyName, projectName, taskTitle) {
|
||||
`/Clients/${co}/Projects/${proj}/00 Project Files/`,
|
||||
`${base}/`,
|
||||
`${base}/Request Info/`,
|
||||
`${base}/Old Book/`,
|
||||
`${base}/Old Books/`,
|
||||
];
|
||||
for (const dir of mkdirs) {
|
||||
await fbq('mkdir', dir);
|
||||
|
||||
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user