fix(studio): review round 1 for imported-course editing
- Media exclusions move from the editable root .gitignore to the repo's info/exclude, and dirtyFiles never counts files listed in media.json, so an author's or remote's .gitignore cannot block publish or Sync. Publish and Sync refuse commits that track a file over referenced media. - Importer jobs (code-repo, pdf-deck, transcribe) and the cover route run under the course lock now shared with the studio (core withCourseLock) and re-check the course inside it; after conversion they fail with "this course is now edited in the studio". Convert answers 409 while an import job for the course is queued or running, and the job re-checks. - Crash-safe conversion: the import folder is hidden (.converting-<id>) before the published worktree exists; cross-filesystem moves copy into a staging dir, fsync, verify size and sha256, then rename; the source is retired as .converted-<id>.<n>. Recovery runs at server start and before every convert; a re-run of a finished conversion reports success. The loader skips dot-folders. - Minor: no raw NUL bytes in source, link fallback only on EXDEV/EPERM/EMLINK, referenced media are not read whole by the editor, missing media are logged, mediaDir JSDoc, docs on per-author copies across filesystems. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
08e62ff683
commit
771d755da4
17 files changed
+618
-88
No files matched your search
@@ -3,7 +3,7 @@ import { join, relative, resolve } from "node:path";
|
||||
import type { Feature, RouteHandler } from "@stc/contracts";
|
||||
import { serveMedia } from "@stc/core";
|
||||
import { assertAllowedPath, importRoots, OUTSIDE } from "./roots";
|
||||
import { coverCacheDir, coursesDir, exists, isPlainId, managedCourse, saveManifest, type Deps } from "./context";
|
||||
import { coverCacheDir, coursesDir, exists, isPlainId, saveManifest, STUDIO_OWNED, withManagedCourse, type Deps } from "./context";
|
||||
|
||||
export const KINDS = ["packt-video", "code-repo", "pdf-deck", "video-folder"] as const;
|
||||
const OPTION_KEYS = ["title", "courseId", "attachTo", "media", "transcribe"] as const;
|
||||
@@ -90,13 +90,18 @@ export function importRoutes(deps: () => Deps): Feature["routes"] {
|
||||
if (!isPlainId(rc.params.courseId!)) return json({ error: "Invalid course id" }, 400);
|
||||
const src = join(coverCacheDir(d, rc.params.courseId!), name);
|
||||
if (!(await exists(src))) return json({ error: "No such candidate" }, 404);
|
||||
let course;
|
||||
try { course = await managedCourse(d, rc.params.courseId); } catch (e) { return json({ error: (e as Error).message }, 404); }
|
||||
await mkdir(join(course.dir, "media"), { recursive: true });
|
||||
await copyFile(src, join(course.dir, "media", "cover.jpg"));
|
||||
course.manifest.cover = "media/cover.jpg";
|
||||
await saveManifest(course.dir, course.manifest);
|
||||
await d.ctx.courses.reload(course.id);
|
||||
try {
|
||||
await withManagedCourse(d, rc.params.courseId, async (course) => {
|
||||
await mkdir(join(course.dir, "media"), { recursive: true });
|
||||
await copyFile(src, join(course.dir, "media", "cover.jpg"));
|
||||
course.manifest.cover = "media/cover.jpg";
|
||||
await saveManifest(course.dir, course.manifest);
|
||||
await d.ctx.courses.reload(course.id);
|
||||
});
|
||||
} catch (e) {
|
||||
const msg = (e as Error).message;
|
||||
return json({ error: msg }, msg === STUDIO_OWNED ? 409 : 404);
|
||||
}
|
||||
return json({ cover: "media/cover.jpg" });
|
||||
}),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user