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:
@@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
|
||||
const db = useDb()
|
||||
|
||||
const [upload] = await db
|
||||
.select({ fileName: uploads.fileName })
|
||||
.select({ fileName: uploads.fileName, previewImage: uploads.previewImage })
|
||||
.from(uploads)
|
||||
.where(eq(uploads.id, id))
|
||||
.limit(1)
|
||||
@@ -30,11 +30,15 @@ export default defineEventHandler(async (event) => {
|
||||
if (upload.fileName) {
|
||||
await unlink(join(uploadDir(), upload.fileName)).catch(() => {})
|
||||
}
|
||||
if (upload.previewImage?.startsWith('/uploads/')) {
|
||||
await unlink(join(process.cwd(), 'public', upload.previewImage)).catch(() => {})
|
||||
}
|
||||
for (const f of attachmentFiles) {
|
||||
await unlink(join(uploadDir(), 'attachments', f.fileName)).catch(() => {})
|
||||
if (f.cover) {
|
||||
await unlink(join(process.cwd(), 'public', f.cover)).catch(() => {})
|
||||
}
|
||||
}
|
||||
broadcastToAll({ type: 'upload-deleted', ids: [id] })
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user