Changeset f79a471 in Klonkt for src/server.js
- Timestamp:
- 06/28/2026 04:32:37 PM (2 months ago)
- Branches:
- main
- Children:
- 74c5abc
- Parents:
- 1ff0043
- git-author:
- Robin Genis <roboburr@…> (06/28/2026 04:31:09 PM)
- git-committer:
- Robin Genis <roboburr@…> (06/28/2026 04:32:37 PM)
- File:
-
- 1 edited
-
src/server.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/server.js
r1ff0043 rf79a471 20 20 import { SqliteSessionStore } from './services/SqliteSessionStore.js'; 21 21 import { ensurePrimarySite } from './services/ensurePrimarySite.js'; 22 import { getThumbnail, THUMB_SIZES } from './services/ThumbnailService.js'; 22 23 import { resolveSite, loadAudioTracks, loadTheme } from './middleware/site.js'; 23 24 import { isViewer } from './middleware/auth.js'; … … 213 214 214 215 app.use('/assets', express.static(path.join(__dirname, 'assets'), { maxAge: isDev ? 0 : '1y' })); 216 217 // On-demand cover thumbnails: /media/thumb/<w>/<path> → a small lanczos-downscaled WebP 218 // (cached on disk), so the browser doesn't jaggily shrink a high-res cover for the grid/ 219 // list. Mounted BEFORE the /media static so it catches the thumb path first. 220 app.get('/media/thumb/:w/*', async (req, res) => { 221 const w = parseInt(req.params.w, 10); 222 const rel = req.params[0] || ''; 223 if (!THUMB_SIZES.has(w)) return res.status(400).end(); 224 let file = null; 225 try { file = await getThumbnail(rel, w); } catch { /* fall through to original */ } 226 if (!file) { 227 // Generation unavailable/failed → serve the original instead of 404'ing. 228 return res.redirect(302, '/media/' + rel.split('/').map(encodeURIComponent).join('/')); 229 } 230 res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin'); 231 res.setHeader('Cache-Control', isDev ? 'no-cache' : 'public, max-age=31536000, immutable'); 232 res.type('webp'); 233 res.sendFile(file); 234 }); 235 215 236 app.use('/media', express.static(process.env.MEDIA_PATH || './storage/media', { 216 237 // Public media (post covers, avatars) must be cross-origin embeddable by other
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)