forked from BRETT/BRETT
Locally stored thumbnails for video and YouTube uploads
- 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>
This commit is contained in:
@@ -3,7 +3,7 @@ import { extname, join } from 'node:path'
|
||||
import { eq, sql } from 'drizzle-orm'
|
||||
import { z } from 'zod'
|
||||
import { commentAttachments, comments, uploads } from '../../../db/schema'
|
||||
import { isAudioAttachment, MAX_COMMENT_ATTACHMENTS } from '~~/shared/utils/attachments'
|
||||
import { isAudioAttachment, isVideoAttachment, MAX_COMMENT_ATTACHMENTS } from '~~/shared/utils/attachments'
|
||||
|
||||
const bodySchema = z.object({
|
||||
content: z.string().trim().min(1).max(2000),
|
||||
@@ -82,6 +82,9 @@ export default defineEventHandler(async (event) => {
|
||||
const audioMeta = !file.voice && isAudioAttachment({ mimeType, name: filename })
|
||||
? await extractAudioMeta(`att-${commentId}-${i}`, data, mimeType)
|
||||
: null
|
||||
const videoThumb = !file.voice && isVideoAttachment({ mimeType, name: filename })
|
||||
? await extractVideoThumb(`att-${commentId}-${i}`, join(attachmentsDir(), storedName))
|
||||
: null
|
||||
const meta = file.voice ? { voice: true } : (audioMeta?.meta ?? null)
|
||||
const [row] = await db.insert(commentAttachments).values({
|
||||
commentId,
|
||||
@@ -89,7 +92,7 @@ export default defineEventHandler(async (event) => {
|
||||
originalName: filename.slice(0, 255),
|
||||
mimeType,
|
||||
size: data.length,
|
||||
cover: audioMeta?.cover ?? null,
|
||||
cover: videoThumb ?? audioMeta?.cover ?? null,
|
||||
meta,
|
||||
})
|
||||
attachments.push({
|
||||
@@ -98,7 +101,7 @@ export default defineEventHandler(async (event) => {
|
||||
url: `/uploads/attachments/${storedName}`,
|
||||
mimeType,
|
||||
size: data.length,
|
||||
cover: audioMeta?.cover ?? null,
|
||||
cover: videoThumb ?? audioMeta?.cover ?? null,
|
||||
meta,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user