Video frame stills for featured cards; newsletter Pick from fix
- Image fields take frameFrom/frameWhen: "Frame at" saves a still from the row's YouTube or Facebook link to /uploads/thumbnails/ (POST /api/admin/video-frame, grabFrame in clips.js). Used on video featured cards. - clock/parseClock moved to src/lib/clock.ts, shared with Video clips. - Newsletter: new drafts no longer store source 'events' (the Pick from select's blank choice), which showed as "events no longer exists"; older drafts load it as blank. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3b45944094
commit
b8012c75e9
9 changed files with 172 additions and 25 deletions
|
|
@ -41,6 +41,7 @@ import {
|
|||
store,
|
||||
} from "../media.js";
|
||||
import { fetchImage, previewLink } from "../linkPreview.js";
|
||||
import { ClipError, grabFrame } from "../clips.js";
|
||||
import { NO_STORE } from "../shape.js";
|
||||
|
||||
const media = new Hono();
|
||||
|
|
@ -204,6 +205,26 @@ media.post("/link-preview", requireRole("editor"), async (c) => {
|
|||
);
|
||||
});
|
||||
|
||||
/* A frame of a YouTube or Facebook video at `seconds`, saved as a
|
||||
thumbnail for a video card's picture. */
|
||||
media.post("/video-frame", requireRole("editor"), async (c) => {
|
||||
const user = c.get("user");
|
||||
let body;
|
||||
try {
|
||||
body = (await c.req.json()) ?? {};
|
||||
} catch {
|
||||
return c.json({ error: "Expected a JSON body." }, 400);
|
||||
}
|
||||
const row = await addToLibrary(c.get("db"), await grabFrame(body.url, Number(body.seconds)), {
|
||||
originalName: `video frame ${Math.floor(Number(body.seconds))}s`,
|
||||
folder: "thumbnails",
|
||||
keepOriginal: false,
|
||||
userId: user.id,
|
||||
});
|
||||
console.log(`video frame ${String(body.url).slice(0, 200)} at ${body.seconds}s by ${user.email}`);
|
||||
return c.json({ media: shape(row) }, 201, NO_STORE);
|
||||
});
|
||||
|
||||
/* Every TEXT column of every content table, searched for any of the
|
||||
exact values a record can use to name the file: its /uploads/
|
||||
path, that path escaped, or (for a file copied in by hand and
|
||||
|
|
@ -273,7 +294,7 @@ media.delete("/media/:id", requireRole("admin"), async (c) => {
|
|||
});
|
||||
|
||||
media.onError((err, c) => {
|
||||
if (err instanceof MediaError) return c.json({ error: err.message }, err.status, NO_STORE);
|
||||
if (err instanceof MediaError || err instanceof ClipError) return c.json({ error: err.message }, err.status, NO_STORE);
|
||||
console.error(err);
|
||||
return c.json({ error: "Something went wrong." }, 500);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue