@@ -149,22 +149,61 @@ async function gzipBase64(obj: any): Promise<string> {
149149 return b64 ;
150150}
151151
152+ /**
153+ * Generates a presigned URL and object key
154+ */
155+ async function generateObjectKey ( metadataType : string , database_id : number ) : Promise < { url : string , key : string } > {
156+ const iframeInfo = getParsedIframeInfo ( )
157+ const request = {
158+ origin : iframeInfo . origin ,
159+ r : iframeInfo . r ,
160+ metadata_type : metadataType ,
161+ database_id : `${ database_id } `
162+ } ;
163+
164+ const response = await axios . post (
165+ `${ configs . DEEPRESEARCH_BASE_URL } /metadata/generate_key` ,
166+ request
167+ ) ;
168+
169+ return response . data ;
170+ }
171+
152172async function uploadMetadata ( metadataType : string , data : any , metadataHash : string , database_id : number ) : Promise < string | undefined > {
153173 // Check if this hash is already being uploaded
154174 if ( ongoingUploads . has ( metadataHash ) ) {
155175 console . log ( `[minusx] Upload already in progress for hash ${ metadataHash } , waiting...` )
156176 return await ongoingUploads . get ( metadataHash ) ! ;
157177 }
158178
159- // Create and store the upload promise
160179 const uploadPromise = ( async ( ) => {
161- // Stringify data, gzip it, and base64 encode
162180 let metadata_value = { [ metadataType ] : data }
181+
163182 try {
164183 const compressedData = await gzipBase64 ( data ) ;
165- metadata_value = {
166- type : 'gzip' ,
167- [ metadataType ] : compressedData
184+
185+ try {
186+ const objectData = await generateObjectKey ( metadataType , database_id ) ;
187+
188+ await axios . put ( objectData . url , compressedData , {
189+ headers : {
190+ 'Content-Type' : 'application/octet-stream' ,
191+ }
192+ } ) ;
193+ console . log ( '[minusx] Successfull new obj flow:' , objectData ) ;
194+
195+ metadata_value = {
196+ type : 'gzip_objstore' ,
197+ [ metadataType ] : objectData
198+ }
199+ } catch ( objError ) {
200+ console . warn ( `Failed to process ${ metadataType } , falling back to older method:` , objError ) ;
201+
202+ // Fallback to direct upload
203+ metadata_value = {
204+ type : 'gzip' ,
205+ [ metadataType ] : compressedData
206+ }
168207 }
169208 } catch ( error ) {
170209 console . warn ( `Failed to compress ${ metadataType } data, using uncompressed version` , error ) ;
@@ -173,7 +212,7 @@ async function uploadMetadata(metadataType: string, data: any, metadataHash: str
173212 const metadataItem : MetadataItem = {
174213 metadata_type : metadataType ,
175214 metadata_value,
176- version : '1 .0' ,
215+ version : '2 .0' , // Update version for new implementation
177216 metadata_hash : metadataHash ,
178217 database_id : `${ database_id } `
179218 } ;
0 commit comments