Add a file library in Google Drive for pages to link to

Tools → Media → Files uploads PDF, Office (.docx, .xlsx, .pptx), MP3,
M4A and zip files, up to 50 MB, to the shared drive's Blog folder and
shares each as anyone with the link can view (migration 048). A file's
name and contents must agree.

Content block links get "Choose a file" (paragraph, button and image
links, list and link items, link cards). A link card also takes the
file's name and Drive's picture of its first page, fetched after
upload and saved into the image library; cards to Drive say "Google
Drive". Deleting a file says first what still links to it.

Setup and the nginx block: docs/google-drive-and-mail.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 18:37:15 -05:00
parent 36c9226bd9
commit 934598f954
13 changed files with 772 additions and 33 deletions

View file

@ -52,7 +52,7 @@ const SCAN_EVERY_MS = 30_000;
let lastScan = 0;
/* Tables that can't hold an image path, or mustn't be searched. */
const NOT_CONTENT = new Set(["media", "admin_users", "sessions", "feedback", "sqlite_sequence"]);
const NOT_CONTENT = new Set(["media", "drive_files", "admin_users", "sessions", "feedback", "feedback_files", "sqlite_sequence"]);
function shape(row) {
return {
@ -77,7 +77,7 @@ const SELECT = `SELECT m.*, u.name AS uploaded_by_name, u.email AS uploaded_by_e
/* Writes the file, then its row; a failed insert takes the file
back out so nothing is left on disk that the library can't see. */
async function addToLibrary(db, buf, { originalName, keepOriginal, userId }) {
export async function addToLibrary(db, buf, { originalName, keepOriginal, userId }) {
const stored = await store(buf, { keepOriginal });
try {
const { lastInsertRowid } = db
@ -203,13 +203,18 @@ media.post("/link-preview", requireRole("editor"), async (c) => {
same place. Read from the live schema rather than a list of image
columns, so a new image field is covered the day it's added. */
function usesOf(db, filename) {
const values = [
...new Set([
`${PUBLIC_PREFIX}${filename}`,
`${PUBLIC_PREFIX}${encodeURIComponent(filename)}`,
filename,
]),
];
return recordsNaming(db, [
`${PUBLIC_PREFIX}${filename}`,
`${PUBLIC_PREFIX}${encodeURIComponent(filename)}`,
filename,
]);
}
/* Which content tables have a TEXT column holding exactly one of
`values`: [{ table, count }]. Also how Tools → Media → Files finds
what links to a file (routes/files.js). */
export function recordsNaming(db, values) {
values = [...new Set(values)];
const tables = db
.prepare(`SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT LIKE 'sqlite_%'`)
.all()