Session 2026-05-20: UI fixes, invoice filtering, file browser, request approvals, sub invoice task scope
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
// One-time: creates 00 Project Files folder inside every existing project folder in FileBrowser
|
||||
// Run: node scripts/backfill-project-files-folder.mjs
|
||||
import { readFileSync } from 'fs';
|
||||
import { resolve, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
|
||||
const __dir = dirname(fileURLToPath(import.meta.url));
|
||||
const envFile = resolve(__dir, '../.env.backfill');
|
||||
|
||||
const env = {};
|
||||
readFileSync(envFile, 'utf8').split('\n').forEach(line => {
|
||||
const m = line.match(/^([^#=]+)=(.*)$/);
|
||||
if (m) env[m[1].trim()] = m[2].trim().replace(/^["']|["']$/g, '');
|
||||
});
|
||||
|
||||
const SUPABASE_URL = env.VITE_SUPABASE_URL || env.SUPABASE_URL;
|
||||
const SERVICE_ROLE_KEY = env.SUPABASE_SERVICE_ROLE_KEY;
|
||||
const FB_URL = (env.FILEBROWSER_URL || '').replace(/\/+$/, '');
|
||||
const FB_TOKEN = env.FILEBROWSER_TOKEN;
|
||||
const CLIENT_ROOT = env.FILEBROWSER_CLIENT_ROOT || '/fourgebranding/Clients';
|
||||
const FB_SOURCE = 'files';
|
||||
|
||||
if (!SUPABASE_URL || !SERVICE_ROLE_KEY) { console.error('Missing Supabase env'); process.exit(1); }
|
||||
if (!FB_URL || !FB_TOKEN) { console.error('Missing FileBrowser env'); process.exit(1); }
|
||||
|
||||
const admin = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, { auth: { persistSession: false } });
|
||||
|
||||
function safeName(v) {
|
||||
return String(v || '').trim()
|
||||
.replace(/[\\/:*?"<>|#%{}^~[\]`]+/g, '-')
|
||||
.replace(/\s+/g, ' ')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
}
|
||||
|
||||
function joinPath(...parts) {
|
||||
const raw = parts.join('/');
|
||||
const clean = raw.split('/').filter(p => p && p !== '.');
|
||||
return `/${clean.join('/')}`;
|
||||
}
|
||||
|
||||
async function mkdir(path) {
|
||||
const qs = new URLSearchParams({ source: FB_SOURCE, path, isDir: 'true' }).toString();
|
||||
const res = await fetch(`${FB_URL}/api/resources?${qs}`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${FB_TOKEN}` },
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
if (!text.includes('already') && !text.includes('exist')) {
|
||||
console.warn(` mkdir ${path}: ${res.status} ${text.slice(0, 80)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { data: projects, error } = await admin
|
||||
.from('projects')
|
||||
.select('id, name, company:companies(name)');
|
||||
|
||||
if (error) { console.error('Query failed:', error.message); process.exit(1); }
|
||||
|
||||
console.log(`Found ${projects.length} projects`);
|
||||
|
||||
for (const p of projects) {
|
||||
const company = safeName(p.company?.name || '');
|
||||
const project = safeName(p.name || '');
|
||||
if (!company || !project) { console.log(` Skipping (missing name): ${p.id}`); continue; }
|
||||
|
||||
const projectDir = joinPath(CLIENT_ROOT, company, 'Projects', project);
|
||||
const targetDir = joinPath(projectDir, '00 Project Files');
|
||||
|
||||
await mkdir(joinPath(CLIENT_ROOT, company));
|
||||
await mkdir(joinPath(CLIENT_ROOT, company, 'Projects'));
|
||||
await mkdir(projectDir);
|
||||
await mkdir(targetDir);
|
||||
console.log(` ✓ ${company} / ${project} / 00 Project Files`);
|
||||
}
|
||||
|
||||
console.log('\nDone.');
|
||||
}
|
||||
|
||||
main().catch(err => { console.error(err); process.exit(1); });
|
||||
Reference in New Issue
Block a user