@@ -375,16 +375,15 @@ type FileLike = {
375375 arrayBuffer : ( ) => Promise < ArrayBuffer >
376376}
377377
378- function isFileLike ( entry : FormDataEntryValue ) : entry is FileLike {
379- if ( typeof entry === 'string' ) return false
380- if ( typeof File !== 'undefined' && entry instanceof File ) return true
378+ type FileLikeEntry = FormDataEntryValue & FileLike
379+
380+ function toFileLike ( entry : FormDataEntryValue ) : FileLikeEntry | null {
381+ if ( typeof entry === 'string' ) return null
381382 const candidate = entry as Partial < FileLike >
382- return (
383- typeof candidate . name === 'string' &&
384- typeof candidate . size === 'number' &&
385- typeof candidate . type === 'string' &&
386- typeof candidate . arrayBuffer === 'function'
387- )
383+ if ( typeof candidate . name !== 'string' ) return null
384+ if ( typeof candidate . size !== 'number' ) return null
385+ if ( typeof candidate . arrayBuffer !== 'function' ) return null
386+ return entry as FileLikeEntry
388387}
389388
390389async function skillsPostRouterV1Handler ( ctx : ActionCtx , request : Request ) {
@@ -496,13 +495,14 @@ async function parseMultipartPublish(
496495 } > = [ ]
497496
498497 for ( const entry of form . getAll ( 'files' ) ) {
499- if ( ! isFileLike ( entry ) ) continue
500- const path = entry . name
501- const size = entry . size
502- const contentType = entry . type || undefined
503- const buffer = new Uint8Array ( await entry . arrayBuffer ( ) )
498+ const file = toFileLike ( entry )
499+ if ( ! file ) continue
500+ const path = file . name
501+ const size = file . size
502+ const contentType = file . type || undefined
503+ const buffer = new Uint8Array ( await file . arrayBuffer ( ) )
504504 const sha256 = await sha256Hex ( buffer )
505- const storageId = await ctx . storage . store ( entry )
505+ const storageId = await ctx . storage . store ( file as Blob )
506506 files . push ( { path, size, storageId, sha256, contentType } )
507507 }
508508
@@ -685,8 +685,8 @@ function toOptionalNumber(value: string | null) {
685685}
686686
687687async function sha256Hex ( bytes : Uint8Array ) {
688- const buffer = bytes . buffer . slice ( bytes . byteOffset , bytes . byteOffset + bytes . byteLength )
689- const digest = await crypto . subtle . digest ( 'SHA-256' , buffer )
688+ const normalized = new Uint8Array ( bytes )
689+ const digest = await crypto . subtle . digest ( 'SHA-256' , normalized . buffer )
690690 return toHex ( new Uint8Array ( digest ) )
691691}
692692
0 commit comments