mirror of
https://github.com/nexu-io/openmotion.git
synced 2026-12-01 23:51:42 +08:00
* Fix workflow draft handling, media previews, and exports * Align Explore spotlight regression tests with the launch order * Use a finite MCP response in the SPA routing regression * Seed soundtrack duration from the workflow brief --------- Co-authored-by: stevenguotj <stevenguotj@users.noreply.github.com>
23 lines
975 B
TypeScript
23 lines
975 B
TypeScript
export function renderFilenameStem(title: string | undefined): string {
|
|
const cleaned = (title ?? '').toWellFormed().normalize('NFC')
|
|
.replace(/[<>:"/\\|?*\u0000-\u001f\u007f]/gu, '_').trim();
|
|
let stem = '';
|
|
for (const char of cleaned) {
|
|
if (Buffer.byteLength(stem + char, 'utf8') > 200) break;
|
|
stem += char;
|
|
}
|
|
stem = stem.replace(/[. ]+$/u, '') || 'OpenMotion';
|
|
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(stem)) stem = '_' + stem;
|
|
return stem;
|
|
}
|
|
|
|
export function mediaFilename(title: string, extension: string): string {
|
|
const name = title.trim();
|
|
const withoutExtension = extension && name.toLowerCase().endsWith(extension.toLowerCase())
|
|
? name.slice(0, -extension.length)
|
|
: name;
|
|
const version = withoutExtension.match(/ v[1-9]\d{0,5}$/u)?.[0] ?? '';
|
|
const stem = renderFilenameStem(withoutExtension.slice(0, withoutExtension.length - version.length)).replace(/^\.+/u, '_');
|
|
return stem + version + extension;
|
|
}
|