@@ -13,37 +13,27 @@ const FolderSchema = v.optional(v.picklist([...ALLOWED_FOLDERS]));
1313const MAX_BASE64_SIZE = Math . ceil ( 10 * 1024 * 1024 * 1.37 ) ;
1414
1515const UploadSchema = v . object ( {
16- data : v . pipe (
17- v . string ( ) ,
18- v . maxLength ( MAX_BASE64_SIZE , "File too large (max 10MB)" ) ,
19- ) ,
16+ data : v . pipe ( v . string ( ) , v . maxLength ( MAX_BASE64_SIZE , "File too large (max 10MB)" ) ) ,
2017 type : v . picklist ( [ ...ACCEPTED_IMAGE_TYPES ] , "Unsupported image format" ) ,
2118 name : v . pipe ( v . string ( ) , v . maxLength ( 255 ) ) ,
2219 folder : FolderSchema ,
2320} ) ;
2421
25- export const upload = command (
26- UploadSchema ,
27- async ( { data, type, name, folder } ) => {
28- await requireUtCodeMember ( ) ;
22+ export const upload = command ( UploadSchema , async ( { data, type, name, folder } ) => {
23+ await requireUtCodeMember ( ) ;
2924
30- const path = folder ?? "uploads" ;
31- const inputBuffer = Buffer . from ( data , "base64" ) ;
25+ const path = folder ?? "uploads" ;
26+ const inputBuffer = Buffer . from ( data , "base64" ) ;
3227
33- // Compress and convert to WebP
34- const {
35- buffer,
36- type : outputType ,
37- extension,
38- } = await compressImage ( inputBuffer , type ) ;
28+ // Compress and convert to WebP
29+ const { buffer, type : outputType , extension } = await compressImage ( inputBuffer , type ) ;
3930
40- // Replace original extension with output extension
41- const baseName = name . replace ( / \. [ ^ . ] + $ / , "" ) ;
42- const outputName = `${ baseName } .${ extension } ` ;
31+ // Replace original extension with output extension
32+ const baseName = name . replace ( / \. [ ^ . ] + $ / , "" ) ;
33+ const outputName = `${ baseName } .${ extension } ` ;
4334
44- return await uploadBuffer ( buffer , outputType , outputName , path ) ;
45- } ,
46- ) ;
35+ return await uploadBuffer ( buffer , outputType , outputName , path ) ;
36+ } ) ;
4737
4838export const remove = command ( S3KeySchema , async ( key ) => {
4939 await requireUtCodeMember ( ) ;
0 commit comments