forked from BRETT/BRETT
- Server-side video thumbnails: ffmpeg-static grabs a frame at ~1s, scales it to 480px and stores it under /uploads/thumbs/ at upload time (direct files, remote URLs and comment attachments) - YouTube thumbnails are downloaded once at upload time instead of being hotlinked from i.ytimg.com on every render; remote URL kept as fallback for legacy rows - thumbUrl now covers video/audio/youtube/twitch in grid meta, profile uploads and notifications - Generated thumbnail files are removed on single/bulk delete Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { inArray } from 'drizzle-orm'
|
|
import { uploads } from '../../db/schema'
|
|
|
|
// Nachgeladene Thumbnails pro Upload für das Grid — bewusst ohne Joins,
|
|
// die Kommentarzahl kommt denormalisiert direkt aus der Upload-Liste
|
|
export default defineEventHandler(async (event) => {
|
|
const ids = String(getQuery(event).ids ?? '')
|
|
.split(',')
|
|
.filter(id => /^[A-Za-z0-9]{1,16}$/.test(id))
|
|
.slice(0, 200)
|
|
if (!ids.length) return []
|
|
|
|
const db = useDb()
|
|
const rows = await db
|
|
.select({
|
|
id: uploads.id,
|
|
type: uploads.type,
|
|
fileName: uploads.fileName,
|
|
externalUrl: uploads.externalUrl,
|
|
previewImage: uploads.previewImage,
|
|
})
|
|
.from(uploads)
|
|
.where(inArray(uploads.id, ids))
|
|
|
|
return rows.map((row) => {
|
|
const url = row.externalUrl ?? `/uploads/${row.fileName}`
|
|
const embedId = row.type === 'youtube' && row.externalUrl ? getYoutubeId(row.externalUrl) : null
|
|
const thumbUrl = row.previewImage
|
|
?? (row.type === 'youtube' && embedId ? youtubeThumbUrl(embedId) : row.type === 'image' ? url : null)
|
|
return { id: row.id, thumbUrl }
|
|
})
|
|
})
|