The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Export: a drafts folder that refuses the write leaves the draft in the exports folder (#140)
riverisbuildingb6b632a6a747
diff --git a/.changeset/drafts-folder-refused.md b/.changeset/drafts-folder-refused.mdnew file mode 100644index 0000000..170c976--- /dev/null+++ b/.changeset/drafts-folder-refused.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Export › Editing project › 剪映 or CapCut: when the app's drafts folder refuses the write (on Windows, security software often does), the draft is made in the exports folder instead of the export failing with "EPERM: operation not permitted, mkdir". The export says so, and where to move it.diff --git a/packages/openfilm/studio/server/exports.mjs b/packages/openfilm/studio/server/exports.mjsindex c7a87f8..7e5e045 100644--- a/packages/openfilm/studio/server/exports.mjs+++ b/packages/openfilm/studio/server/exports.mjs@@ -103,7 +103,7 @@ export { exportsRoot };* status: 'waiting' | 'running' | 'done' | 'failed' | 'cancelled', progress: number, phase: ExportPhase | null,* framesDone: number, framesTotal: number, rate: number, etaMs: number | null, encoder: string | null,* out?: string, outputs: string[], bytes: number | null, alpha: { any: boolean } | null, error?: string, cancelling?: boolean,- * at: number, startedAt: number | null, finishedAt: number | null }} ExportJob+ * at: number, startedAt: number | null, finishedAt: number | null, draftsRefused?: string }} ExportJob*/export class ExportError extends Error {@@ -687,6 +687,20 @@ async function rasterize(browser, file, w, h, out) {}}+/**+ * Whether a folder takes a new folder: one is made in it and removed. False when it refuses (EPERM, EACCES on+ * Windows when security software or the folder's permissions say no) or is not there.+ * @param {string} dir+ */+export async function writableFolder(dir) {+ try {+ await rmdir(await mkdtemp(join(dir, '.openfilm-')));+ return true;+ } catch {+ return false;+ }+}+/*** The export queue. `onChange(job)` is told every change of a job (its progress included), for the pages watching.* `captions(root)`: a film's subtitle cues and the person's style for them (captions.mjs by default).@@ -1033,8 +1047,11 @@ export function createExports({ onChange = () => {}, captions = subtitlesForExpoconst ask = /** @type {NleAsk} */ (job.ask);const fcp = ask.format === 'fcpxml';const app = ask.format === 'jianying' || ask.format === 'capcut' ? ask.format : null;- /* a draft goes where its app lists its drafts, when the app is on this computer */- const dir = (app && drafts(app)) || out;+ /* a draft goes where its app lists its drafts, when the app is on this computer; a drafts folder that refuses the+ write (security software, or the app's own permissions on it) leaves the draft in the exports folder, said so */+ const draftsDir = app ? drafts(app) : null;+ const dir = draftsDir && await writableFolder(draftsDir) ? draftsDir : out;+ if (draftsDir && dir !== draftsDir) update(job, { draftsRefused: draftsDir });const fps = nleFps(ask.fps ?? 30);const mode = ask.audio ?? 'clips';const title = safeName(job.name);diff --git a/packages/openfilm/studio/server/exports.test.mjs b/packages/openfilm/studio/server/exports.test.mjsindex ff89a08..069d768 100644--- a/packages/openfilm/studio/server/exports.test.mjs+++ b/packages/openfilm/studio/server/exports.test.mjs@@ -1,11 +1,11 @@import { test, before } from 'node:test';import assert from 'node:assert/strict';import { execFileSync, spawnSync } from 'node:child_process';-import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { homedir, tmpdir } from 'node:os';import { basename, join } from 'node:path';import { fileURLToPath } from 'node:url';-import { createExports, exportCapabilities, exportsRoot, ExportError, frameBox, dimsForShortEdge, projectFiles, projectSizes } from './exports.mjs';+import { createExports, exportCapabilities, exportsRoot, ExportError, frameBox, dimsForShortEdge, projectFiles, projectSizes, writableFolder } from './exports.mjs';import { encoders, hardwareEncoder } from '../../src/encoders.mjs';import { allocateLanes, containMotion, fadeKeyframes, frameSpan, nleRate, planNleTimeline, xmemlDocument } from './nle.mjs';import { fcpxmlDocument } from './fcpxml.mjs';@@ -822,6 +822,17 @@ test('剪映: the same timeline as a draft in 剪映\'s drafts folder, its mediaconst text = info.tracks.find((t) => t.type === 'text');assert.deepEqual(info.materials.texts.map((m) => JSON.parse(m.content).text), CUES.map((c) => c.text));assert.deepEqual(text.segments.map((s) => s.target_timerange.start), [0, 800_000]);+ /* a drafts folder that refuses the write: the draft in the exports folder, said so, rather than no draft */+ if (process.platform === 'win32' || process.getuid?.() === 0) return;+ chmodSync(drafts, 0o555);+ try {+ const refused = await ended(exports, exports.start(project('Cut', cut), { kind: 'nle', format: 'jianying', fps: 25 }));+ assert.equal(refused.status, 'done', refused.error);+ assert.equal(refused.draftsRefused, drafts);+ assert.ok(refused.out.startsWith(exportsRoot()), refused.out);+ } finally {+ chmodSync(drafts, 0o755);+ }});test('burned-in subtitles: drawn over the frame, bars included; a subtitle file beside the video', ffmpeg, async () => {@@ -1022,3 +1033,18 @@ test('platforms that take the same picture are drawn once, the others get its fiassert.deepEqual(done.map((j) => drawn.has(j.id)), [true, false, false, true], 'only the first of the same, and the one at another rate');assert.ok(readFileSync(done[1].out).equals(readFileSync(done[0].out)) && readFileSync(done[2].out).equals(readFileSync(done[0].out)), 'the same file');});++test("a drafts folder that refuses a new folder is told apart, and the probe leaves nothing behind", async () => {+ const dir = mkdtempSync(join(tmpdir(), 'of-drafts-'));+ assert.equal(await writableFolder(dir), true);+ assert.deepEqual(readdirSync(dir), [], 'the probe is removed');+ assert.equal(await writableFolder(join(dir, 'missing')), false);+ /* a folder Windows (or its security software) refuses is a folder without write permission here */+ if (process.platform === 'win32' || process.getuid?.() === 0) return;+ chmodSync(dir, 0o555);+ try {+ assert.equal(await writableFolder(dir), false);+ } finally {+ chmodSync(dir, 0o755);+ }+});diff --git a/packages/openfilm/studio/ui/src/components/export/ExportTray.tsx b/packages/openfilm/studio/ui/src/components/export/ExportTray.tsxindex 0555a6b..82c257c 100644--- a/packages/openfilm/studio/ui/src/components/export/ExportTray.tsx+++ b/packages/openfilm/studio/ui/src/components/export/ExportTray.tsx@@ -261,6 +261,7 @@ function JobLine({ job, cancelling, t }: { job: ExportJob; cancelling: boolean;return (<>{opaque && <p className="mt-0.5 text-[11.5px] leading-snug text-[var(--warn)]">{t('exportTray.notTransparent')}</p>}+ {job.draftsRefused ? <p className="mt-0.5 break-words text-[11.5px] leading-snug text-[var(--warn)]">{t('exportTray.draftsRefused').replace('{folder}', job.draftsRefused)}</p> : null}<p className="mt-0.5 truncate text-[11.5px] text-[var(--text-faint)]" title={job.outputs.join('\n')}>{[job.outputs.length === 1 ? basenameOf(job.outputs[0]!) : t('exportTray.files').replace('{n}', String(job.outputs.length)),job.bytes ? formatBytes(job.bytes) : '', took ? t('exportTray.took').replace('{time}', took) : ''].filter(Boolean).join(' · ')}diff --git a/packages/openfilm/studio/ui/src/i18n/en.ts b/packages/openfilm/studio/ui/src/i18n/en.tsindex 735bb91..1519c26 100644--- a/packages/openfilm/studio/ui/src/i18n/en.ts+++ b/packages/openfilm/studio/ui/src/i18n/en.ts@@ -504,6 +504,7 @@ export const en = {cancelled: 'Cancelled',cancelling: 'Cancelling…',failed: 'Export failed',+ draftsRefused: "The drafts folder refused the write (security software often does), so the draft is in the export folder: move it into {folder}.",notTransparent: 'No transparent pixels: this element paints its own background.',},player: {diff --git a/packages/openfilm/studio/ui/src/i18n/es.ts b/packages/openfilm/studio/ui/src/i18n/es.tsindex cd70228..f3e824e 100644--- a/packages/openfilm/studio/ui/src/i18n/es.ts+++ b/packages/openfilm/studio/ui/src/i18n/es.ts@@ -503,6 +503,7 @@ export const es: Words = {cancelled: 'Cancelada',cancelling: 'Cancelando…',failed: 'La exportación falló',+ draftsRefused: "La carpeta de borradores rechazó la escritura (suele hacerlo el software de seguridad), así que el borrador está en la carpeta de exportación: muévelo a {folder}.",notTransparent: 'No hay píxeles transparentes: este elemento pinta su propio fondo.',},player: {diff --git a/packages/openfilm/studio/ui/src/i18n/ja.ts b/packages/openfilm/studio/ui/src/i18n/ja.tsindex 1c1b11c..05d1e57 100644--- a/packages/openfilm/studio/ui/src/i18n/ja.ts+++ b/packages/openfilm/studio/ui/src/i18n/ja.ts@@ -503,6 +503,7 @@ export const ja: Words = {cancelled: 'キャンセル済み',cancelling: 'キャンセル中…',failed: '書き出しに失敗しました',+ draftsRefused: "下書きフォルダへの書き込みが拒否されたため(セキュリティソフトによることが多いです)、下書きは書き出しフォルダにあります。{folder} に移してください。",notTransparent: '透明なピクセルがありません。この要素は自身の背景を描画しています。',},player: {diff --git a/packages/openfilm/studio/ui/src/i18n/ko.ts b/packages/openfilm/studio/ui/src/i18n/ko.tsindex ad5dd3c..7e32999 100644--- a/packages/openfilm/studio/ui/src/i18n/ko.ts+++ b/packages/openfilm/studio/ui/src/i18n/ko.ts@@ -503,6 +503,7 @@ export const ko: Words = {cancelled: '취소됨',cancelling: '취소하는 중…',failed: '내보내기 실패',+ draftsRefused: "초안 폴더에 쓰기가 거부되어(보안 소프트웨어 때문인 경우가 많습니다) 초안은 내보내기 폴더에 있습니다. {folder}(으)로 옮기세요.",notTransparent: '투명한 픽셀이 없습니다. 이 요소가 자체 배경을 칠하고 있습니다.',},player: {diff --git a/packages/openfilm/studio/ui/src/i18n/zh-CN.ts b/packages/openfilm/studio/ui/src/i18n/zh-CN.tsindex eed716b..b4e0c00 100644--- a/packages/openfilm/studio/ui/src/i18n/zh-CN.ts+++ b/packages/openfilm/studio/ui/src/i18n/zh-CN.ts@@ -504,6 +504,7 @@ export const zhCN: Words = {cancelled: '已取消',cancelling: '正在取消…',failed: '导出失败',+ draftsRefused: "草稿文件夹拒绝写入(常见于安全软件拦截),草稿已放到导出文件夹:把它移到 {folder} 即可。",notTransparent: '没有透明像素:此元素绘制了自己的背景。',},player: {diff --git a/packages/openfilm/studio/ui/src/lib/export-jobs.ts b/packages/openfilm/studio/ui/src/lib/export-jobs.tsindex a78afbf..bb92912 100644--- a/packages/openfilm/studio/ui/src/lib/export-jobs.ts+++ b/packages/openfilm/studio/ui/src/lib/export-jobs.ts@@ -57,6 +57,8 @@ export interface ExportJob {bytes: number | null;/** Whether a transparent export lets anything through (sampled frames); null when not measured. */alpha: { any: boolean } | null;+ /** A draft's app's drafts folder that refused the write: the draft is in the exports folder instead. */+ draftsRefused?: string;error?: string;/** Cancel was asked and the export is stopping (still `running` until it has). */cancelling?: boolean;