Let a downloaded video be saved whole, before or without cutting

Save to library and Save to Drive on a finished download, not only on
clips. The download stays on the server to cut clips from either way;
a clip's library save still clears its working file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-30 00:14:26 -05:00
parent 6ccbc03b52
commit 06a0e07a79
4 changed files with 54 additions and 11 deletions

View file

@ -11,9 +11,11 @@
GET /clips/:id/download a finished clip, as an attachment;
its file is deleted once it has
gone out in full, unless saved
POST /clips/:id/save a finished clip into the media
POST /clips/:id/save a finished clip, or a whole
downloaded video, into the media
library
POST /clips/:id/drive { folder }: a finished clip into a
POST /clips/:id/drive { folder }: a finished clip (or a
whole downloaded video) into a
folder under Media in Drive, as a
Files entry (routes/files.js)
DELETE /clips/:id a job and its files (a source
@ -214,8 +216,9 @@ clips.get("/clips/:id/download", async (c) => {
clips.post("/clips/:id/save", async (c) => {
const db = c.get("db");
const job = findOr404(c);
if (job.kind !== "clip" || job.status !== "done") throw new ClipError(400, "Only a finished clip can be saved.");
if (job.status !== "done") throw new ClipError(400, "Only a finished download or clip can be saved.");
if (job.saved_media_id) throw new ClipError(409, "It's already in the media library.");
if (!job.file) throw new ClipError(410, "Its file is gone from the server.");
const media = await saveToLibrary(db, job, c.get("user").id);
console.log(`clips: clip ${job.id} saved to the library by ${c.get("user").email}`);
return c.json({ media, job: shape(db.prepare(`${SELECT} WHERE j.id = ?`).get(job.id)) }, 200, NO_STORE);
@ -227,7 +230,7 @@ clips.post("/clips/:id/save", async (c) => {
clips.post("/clips/:id/drive", async (c) => {
const db = c.get("db");
const job = findOr404(c);
if (job.kind !== "clip" || job.status !== "done") throw new ClipError(400, "Only a finished clip can be saved.");
if (job.status !== "done") throw new ClipError(400, "Only a finished download or clip can be saved.");
if (job.saved_drive_file_id) throw new ClipError(409, "It's already in Drive.");
if (!driveReady()) throw new ClipError(400, "Google Drive isn't set up on the server (docs/google-drive-and-mail.md).");
const folder = cleanFolder((await body(c)).folder);
@ -239,7 +242,11 @@ clips.post("/clips/:id/drive", async (c) => {
const mime = audio ? "audio/mpeg" : "video/mp4";
const params = job.params ? JSON.parse(job.params) : {};
const stamp = (s) => `${Math.floor(s / 60)}m${String(Math.floor(s % 60)).padStart(2, "0")}s`;
const name = `${(job.title ?? "Clip").replace(/[\u0000-\u001f"\\/]+/g, " ").trim().slice(0, 120) || "Clip"} (${stamp(params.start ?? 0)} to ${stamp(params.end ?? 0)}).${audio ? "mp3" : "mp4"}`;
const title = (job.title ?? "").replace(/[\u0000-\u001f"\\/]+/g, " ").trim().slice(0, 120);
const name =
job.kind === "source"
? `${title || "Video"}.mp4`
: `${title || "Clip"} (${stamp(params.start ?? 0)} to ${stamp(params.end ?? 0)}).${audio ? "mp3" : "mp4"}`;
let uploaded;
try {