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

@ -490,9 +490,10 @@ export function kick(db = dbRef) {
export const fileOf = (job) => (job?.file ? filePath(job.file) : null);
/* A finished clip into the media library: copied into the uploads
directory under a random name, given a media row, and its working
file deleted. Returns the media row's id. */
/* A finished clip, or a whole downloaded video, into the media
library: copied into the uploads directory under a random name and
given a media row. A clip's working file is deleted; a video's is
kept for cutting. Returns the media row's id. */
export async function saveToLibrary(db, job, userId) {
const from = fileOf(job);
if (!from) throw new ClipError(410, "That clip's file is gone. Make it again.");
@ -528,7 +529,11 @@ export async function saveToLibrary(db, job, userId) {
const { size } = await stat(from);
const params = JSON.parse(job.params ?? "{}");
const stamp = (s) => `${Math.floor(s / 60)}m${String(Math.floor(s % 60)).padStart(2, "0")}s`;
const label = `${job.title ?? "Clip"} (${stamp(params.start ?? 0)} to ${stamp(params.end ?? 0)})${ext}`;
// A whole download is named for itself; a clip for its span.
const label =
job.kind === "source"
? `${job.title ?? "Video"}${ext}`
: `${job.title ?? "Clip"} (${stamp(params.start ?? 0)} to ${stamp(params.end ?? 0)})${ext}`;
id = await step("adding it to the media table", () =>
Number(
@ -546,8 +551,14 @@ export async function saveToLibrary(db, job, userId) {
throw err;
}
await rm(from, { force: true });
update(db, job.id, { saved_media_id: id, file: null });
// A clip's working file goes; a downloaded video's stays, to cut
// clips from (the day's sweep clears it).
if (job.kind === "source") {
update(db, job.id, { saved_media_id: id });
} else {
await rm(from, { force: true });
update(db, job.id, { saved_media_id: id, file: null });
}
return { id, url: `${PUBLIC_PREFIX}${filename}` };
}