Select and confirm uploaded Studio 2 source and hero stills
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { imageDimensions } from '../../utils/resolution'
|
||||
export default defineEventHandler(async event => {
|
||||
const parts=await readMultipartFormData(event)
|
||||
const image=parts?.find(p=>p.name==='image' && p.filename && p.data?.length)
|
||||
const field=(name:string)=>parts?.find(p=>p.name===name)?.data.toString('utf8') || ''
|
||||
if (!image) throw createError({statusCode:400,statusMessage:'Choose an image to upload.'})
|
||||
const {owner}=assertLibraryOwner(event),folderId=field('folderId')
|
||||
assertFolderAccess(event,folderId)
|
||||
const size=imageDimensions(image.data)
|
||||
if (!size) throw createError({statusCode:400,statusMessage:'Use a PNG, JPEG, WebP, GIF, or BMP image.'})
|
||||
const filename=image.filename!.split(/[\\/]/).at(-1)!
|
||||
const still=await saveStill({ownerKey:owner,folderId,filename,name:filename.replace(/\.[^.]+$/,''),data:image.data,...size,hideInput:field('hideInput')==='true',role:'input'})
|
||||
if (!still) throw createError({statusCode:400,statusMessage:'This file was recognized as an internal video handoff frame and was not added. Choose a regular source image.'})
|
||||
return {still,...publicLibrary(event,{light:true})}
|
||||
})
|
||||
Reference in New Issue
Block a user