ce8a03ab16
- N124: denoise shim cleanup() now disconnects the noise gate AudioWorkletNode (var-scoped, guarded), releasing the gate processor thread instead of leaking it on every getUserMedia within a session. - N125: denoise-status postMessage now targets the parent origin (derived from the parentUrl widget param via new URL(...).origin, falling back to this frame's origin) instead of broadcasting with '*'. - N128: patch-folds.mjs fails hard (process.exit(1)) when the patch target is missing, so an unpatched folds can't silently ship. The idempotent "already applied" path still exits 0 (verified by re-run). - N120: the avatar-decoration CDN URL is now single-sourced in avatarDecorations.ts (DECORATION_CDN); syncDecorations.mjs extracts it by regex (can't import across the build/app boundary) and fails hard if renamed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
103 lines
3.6 KiB
JavaScript
103 lines
3.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Syncs avatarDecorations.ts with what's actually available on the Nextcloud CDN.
|
|
*
|
|
* Usage:
|
|
* npm run sync:decorations
|
|
*
|
|
* Workflow after deleting files from Nextcloud:
|
|
* 1. Delete decoration files from your Nextcloud share.
|
|
* 2. Run: npm run sync:decorations
|
|
* 3. It probes each catalog slug via HTTP HEAD and removes entries
|
|
* whose files returned 404. Empty categories are dropped automatically.
|
|
* 4. Commit the updated avatarDecorations.ts.
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const root = join(__dirname, '..');
|
|
const catalogPath = join(root, 'src', 'app', 'features', 'lotus', 'avatarDecorations.ts');
|
|
|
|
// Single source of truth: the CDN base URL lives in avatarDecorations.ts as
|
|
// `export const DECORATION_CDN`. We extract it from there at runtime rather than
|
|
// re-declaring it here, so the build script and the app can never drift. This
|
|
// .mjs script can't cleanly import the browser-side .ts module (it's outside the
|
|
// Vite/TS app graph), so we parse the constant out of the file text instead.
|
|
// If you migrate the CDN, change it ONLY in avatarDecorations.ts.
|
|
const catalog = readFileSync(catalogPath, 'utf8');
|
|
|
|
const cdnMatch = catalog.match(/export const DECORATION_CDN\s*=\s*['"]([^'"]+)['"]/);
|
|
if (!cdnMatch) {
|
|
console.error(
|
|
'Could not find `export const DECORATION_CDN` in avatarDecorations.ts — ' +
|
|
'the constant may have been renamed. Update scripts/syncDecorations.mjs.',
|
|
);
|
|
process.exit(1);
|
|
}
|
|
const CDN = cdnMatch[1];
|
|
|
|
// Extract all slugs from the catalog file
|
|
const slugMatches = [...catalog.matchAll(/slug: '([^']+)'/g)].map((m) => m[1]);
|
|
|
|
if (slugMatches.length === 0) {
|
|
console.error('No slugs found in catalog — check the file path.');
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`Checking ${slugMatches.length} decorations against ${CDN} …`);
|
|
console.log('(This makes one HEAD request per decoration)\n');
|
|
|
|
// Probe all slugs in parallel batches of 16
|
|
async function headCheck(slug) {
|
|
try {
|
|
const res = await fetch(`${CDN}/${slug}.png`, { method: 'HEAD' });
|
|
return { slug, ok: res.ok, status: res.status };
|
|
} catch {
|
|
return { slug, ok: false, status: 0 };
|
|
}
|
|
}
|
|
|
|
const BATCH = 16;
|
|
const results = [];
|
|
for (let i = 0; i < slugMatches.length; i += BATCH) {
|
|
const batch = slugMatches.slice(i, i + BATCH);
|
|
const batchResults = await Promise.all(batch.map(headCheck));
|
|
results.push(...batchResults);
|
|
}
|
|
|
|
const missing = results.filter((r) => !r.ok);
|
|
const found = results.filter((r) => r.ok);
|
|
|
|
if (missing.length === 0) {
|
|
console.log(`All ${found.length} decorations are available — catalog is up to date.`);
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log(`Found: ${found.length} Missing: ${missing.length}\n`);
|
|
missing.forEach((r) => console.log(` Removing (HTTP ${r.status}): ${r.slug}`));
|
|
|
|
const missingSet = new Set(missing.map((r) => r.slug));
|
|
|
|
// Remove individual entries for missing slugs
|
|
let updated = catalog.replace(/^[ \t]*\{ slug: '([^']+)', name: .+\},?\r?\n/gm, (match, slug) =>
|
|
missingSet.has(slug) ? '' : match,
|
|
);
|
|
|
|
// Drop category blocks that now have an empty decorations array
|
|
updated = updated.replace(
|
|
/ \{\n id: '[^']+',\n label: '[^']+',\n decorations: \[\n?[ \t]*\],?\n \},?\n/g,
|
|
'',
|
|
);
|
|
|
|
// Clean up stray blank lines
|
|
updated = updated.replace(/\n{3,}/g, '\n\n');
|
|
|
|
writeFileSync(catalogPath, updated, 'utf8');
|
|
console.log(
|
|
`\nDone. Removed ${missing.length} entr${missing.length === 1 ? 'y' : 'ies'} from the catalog.`,
|
|
);
|
|
console.log('Review with: git diff src/app/features/lotus/avatarDecorations.ts');
|