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:
@@ -64,6 +64,9 @@ export default defineEventHandler(async (event) => {
|
||||
const audioMeta = media.type === 'audio'
|
||||
? await extractAudioMeta(id, media.data, media.mimeType)
|
||||
: null
|
||||
const videoThumb = media.type === 'video'
|
||||
? await extractVideoThumb(id, join(uploadDir(), fileName))
|
||||
: null
|
||||
await db.insert(uploads).values({
|
||||
id,
|
||||
userId: user.id,
|
||||
@@ -72,7 +75,7 @@ export default defineEventHandler(async (event) => {
|
||||
originalName: decodeURIComponent(basename(new URL(body.url).pathname) || body.url).slice(0, 255),
|
||||
mimeType: media.mimeType.slice(0, 100),
|
||||
size: media.data.length,
|
||||
previewImage: audioMeta?.cover ?? null,
|
||||
previewImage: videoThumb ?? audioMeta?.cover ?? null,
|
||||
audioMeta: audioMeta?.meta ?? null,
|
||||
})
|
||||
await ensureThreadSubscription(id, user.id)
|
||||
@@ -84,7 +87,9 @@ export default defineEventHandler(async (event) => {
|
||||
type === 'link' || type === 'twitch' ? fetchLinkPreview(body.url) : null,
|
||||
twitchTarget ? fetchTwitchPreview(twitchTarget) : null,
|
||||
])
|
||||
const remotePreviewImage = twitchPreview?.image ?? preview?.image ?? null
|
||||
const embedId = type === 'youtube' ? getYoutubeId(body.url) : null
|
||||
const remotePreviewImage = twitchPreview?.image ?? preview?.image
|
||||
?? (embedId ? youtubeThumbUrl(embedId) : null)
|
||||
const previewImage = remotePreviewImage
|
||||
? (await savePreviewImage(id, remotePreviewImage)) ?? remotePreviewImage
|
||||
: null
|
||||
@@ -137,6 +142,9 @@ export default defineEventHandler(async (event) => {
|
||||
const audioMeta = type === 'audio'
|
||||
? await extractAudioMeta(id, file.data, mimeType)
|
||||
: null
|
||||
const videoThumb = type === 'video'
|
||||
? await extractVideoThumb(id, join(uploadDir(), fileName))
|
||||
: null
|
||||
await db.insert(uploads).values({
|
||||
id,
|
||||
userId: user.id,
|
||||
@@ -145,7 +153,7 @@ export default defineEventHandler(async (event) => {
|
||||
originalName: (file.filename ?? fileName).slice(0, 255),
|
||||
mimeType: (mimeType || 'application/octet-stream').slice(0, 100),
|
||||
size: file.data.length,
|
||||
previewImage: audioMeta?.cover ?? null,
|
||||
previewImage: videoThumb ?? audioMeta?.cover ?? null,
|
||||
audioMeta: audioMeta?.meta ?? null,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user