forked from BRETT/BRETT
Initial Commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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.type === 'youtube' && embedId
|
||||
? youtubeThumbUrl(embedId)
|
||||
: row.type === 'image' ? url : row.type === 'link' || row.type === 'twitch' || row.type === 'audio' ? row.previewImage : null
|
||||
return { id: row.id, thumbUrl }
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user