okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
788e0b731
main
1export function validateChatImages ( images ){ if ( images === undefined ) return []; if ( ! Array . isArray ( images ) || images . length > 4 ) throw new Error ( 'Attach up to four pictures per message.' ); return images . map ( i => { if ( ! i || typeof i . url !== 'string' ||! /^data:image\/ ( png | jpeg | webp ) ;base64, [ A - Za - z0 - 9+/ ] + = { 0 , 2 } $ / . test ( i . url )) throw new Error ( 'Pictures must be attached PNG, JPEG or WebP files.' ); if ( Buffer . byteLength ( i . url . split ( ',' )[ 1 ], 'base64' ) > 6 * 1024 * 1024 ) throw new Error ( 'Choose pictures smaller than 6 MB.' ); return { url :i . url , name :String ( i . name ?? 'Picture' ). slice ( 0 , 256 )};});}