@@ -74,7 +74,7 @@ export class FileCreate extends Endpoint {
7474 let duration : string = c . env . SHARE_DURATION
7575 let isEphemeral = false
7676 let isEncrypted = false
77- let objectId = ''
77+ let objectId : string | Array < { objectId : string } > = ''
7878 let hash = ''
7979 const contentType = c . req . header ( 'Content-Type' )
8080 if (
@@ -85,7 +85,7 @@ export class FileCreate extends Endpoint {
8585 const file = formData . get ( 'file' ) as File
8686
8787 const fileInfo = this . getFormDataField < null | {
88- objectId : string
88+ objectId : string | Array < { objectId : string } >
8989 name : string
9090 type ?: string
9191 size : number
@@ -116,7 +116,10 @@ export class FileCreate extends Endpoint {
116116 size = blob . size
117117 }
118118
119- if ( ( ! data || data . byteLength === 0 ) && ! objectId ) {
119+ if (
120+ ( ! data || data . byteLength === 0 ) &&
121+ ( ! objectId || ( Array . isArray ( objectId ) && ! objectId . length ) )
122+ ) {
120123 return this . error ( '分享内容为空' )
121124 }
122125
@@ -128,15 +131,22 @@ export class FileCreate extends Endpoint {
128131 }
129132
130133 const kv = this . getKV ( c )
131- const key = objectId || createId ( )
134+ const key = objectId && ! Array . isArray ( objectId ) ? objectId : createId ( )
135+ // 直接上传
132136 if ( data && data . byteLength ) {
133137 await kv . put ( key , data )
134138 hash = await sha256 ( data )
135- } else {
139+ // 单个
140+ } else if ( typeof objectId === 'string' ) {
136141 const cacheFile = await kv . get ( objectId , 'stream' )
137142 if ( ! cacheFile ) {
138143 return this . error ( '分片上传的文件不存在' )
139144 }
145+ // 分片存储
146+ } else if ( Array . isArray ( objectId ) && objectId . length ) {
147+ await kv . put ( key , 'chunks' , {
148+ metadata : objectId ,
149+ } )
140150 }
141151
142152 const db = this . getDB ( c )
0 commit comments