This commit is contained in:
seb
2026-10-10 02:08:10 +02:00
parent d4e2b05cb0
commit 7f8661be3e
43 changed files with 3312 additions and 2339 deletions

View File

@@ -1,5 +1,7 @@
import * as db from '../../db/pic.js';
// #region Helpers
const FULL_HASH_RE = /^[a-zA-Z0-9]{8}$/;
/** Content-addressed by SHA-256 (Base62, 8 chars) — safe for long-lived browser cache (auth still required on first fetch). */
const CACHE_CONTROL = 'private, max-age=31536000, immutable';
@@ -34,6 +36,8 @@ function sendImmutableAvif(req, res, { buffer, contentType, fullHash }) {
return res.status(200).send(buffer);
}
// #endregion
/**
* Registers content-addressed image routes (requires auth).
* @param {import('express').Application} app
@@ -103,6 +107,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /image/:fullHash
const imagePaths = [`${basePath}/image/:fullHash`];
if (basePath) imagePaths.push('/image/:fullHash');
app.get(imagePaths, async (req, res) => {
@@ -125,6 +131,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /thumb/{fullHash}:
@@ -188,6 +196,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /thumb/:fullHash
const thumbPaths = [`${basePath}/thumb/:fullHash`];
if (basePath) thumbPaths.push('/thumb/:fullHash');
app.get(thumbPaths, async (req, res) => {
@@ -210,6 +220,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /smallthumb/{fullHash}:
@@ -273,6 +285,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /smallthumb/:fullHash
const smallThumbPaths = [`${basePath}/smallthumb/:fullHash`];
if (basePath) smallThumbPaths.push('/smallthumb/:fullHash');
app.get(smallThumbPaths, async (req, res) => {
@@ -294,4 +308,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}