@@ -8,7 +8,6 @@ import fs from 'node:fs'
8
8
import User , { UserApi } from "../user/main" ;
9
9
import { EncodeUtil , MemoryCacheUtil , MemoryMapCacheUtil } from "../../lib/util" ;
10
10
import { ServerContext , ServerFunctionDataType } from "./type" ;
11
- import { UploadUtil } from "../../lib/upload" ;
12
11
13
12
const request = async ( url , data ?: { } , option ?: { } ) => {
14
13
option = Object . assign ( {
@@ -268,115 +267,6 @@ const launcherPrepareConfigJson = async (data: any) => {
268
267
return configJson
269
268
}
270
269
271
- const launcherCloudSubmit = async ( context : ServerContext , data : ServerFunctionDataType , option ?: {
272
- result ?: {
273
- taskId ?: string ,
274
- } ,
275
- uploadFileKeys ?: [ ]
276
- } ) : Promise < void > => {
277
- // console.log('launcherCloudSubmitAndQuery.data', {data})
278
- option = Object . assign ( {
279
- result : {
280
- taskId : '' ,
281
- } ,
282
- uploadFileKeys : [ ] ,
283
- } , option )
284
- let taskId = option . result . taskId || ''
285
- if ( ! taskId ) {
286
- const resCheck = await UserApi . post < {
287
- uploadType : string ,
288
- } > ( 'aigcpanel/task/check' , data , {
289
- catchException : false
290
- } )
291
- // console.log('resCheck', resCheck)
292
- if ( resCheck . code ) {
293
- throw resCheck . msg
294
- }
295
- if ( resCheck . data . uploadType && option . uploadFileKeys && option . uploadFileKeys . length > 0 && data [ 'modelConfig' ] ) {
296
- for ( let key of option . uploadFileKeys ) {
297
- if ( key in data [ 'modelConfig' ] ) {
298
- const uploadRes = await UploadUtil . upload ( resCheck . data . uploadType as any , data [ 'modelConfig' ] [ key ] )
299
- // console.log('uploadRes', uploadRes)
300
- if ( uploadRes . success ) {
301
- data [ 'modelConfig' ] [ key ] = uploadRes . url
302
- }
303
- }
304
- }
305
- }
306
- const resSubmit = await UserApi . post < {
307
- taskId : string ,
308
- } > ( 'aigcpanel/task/submit' , data , {
309
- catchException : false
310
- } )
311
- if ( resSubmit . code ) {
312
- throw resSubmit . msg
313
- }
314
- taskId = resSubmit . data . taskId
315
- // console.log('resSubmit', resSubmit)
316
- context . send ( 'taskResult' , { id : data . id , result : { taskId} } )
317
- }
318
- }
319
-
320
- const launcherCloudQuery = async ( context : ServerContext , data : ServerFunctionDataType , option ?: {
321
- result ?: {
322
- taskId ?: string ,
323
- } ,
324
- } ) : Promise < {
325
- status : 'process' | 'success' ,
326
- param : any ,
327
- result : any ,
328
- endTime : number ,
329
- } > => {
330
- // console.log('launcherCloudSubmitAndQuery.data', {data})
331
- option = Object . assign ( {
332
- result : {
333
- taskId : '' ,
334
- } ,
335
- timeout : 24 * 3600 ,
336
- uploadFileKeys : [ ] ,
337
- } , option )
338
- let taskId = option . result . taskId || ''
339
- if ( ! taskId ) {
340
- throw new Error ( 'taskId is empty' )
341
- }
342
- const launcherResult = {
343
- status : 'process' as 'process' | 'success' ,
344
- param : { } ,
345
- result : { } ,
346
- endTime : 0 ,
347
- }
348
- const queryRet = await UserApi . post < {
349
- status : 'queue' | 'process' | 'success' | 'fail' | 'error' ,
350
- taskId : string ,
351
- result : any ,
352
- } > ( `aigcpanel/task/query` , {
353
- taskId
354
- } ) as any
355
- // console.log('queryRet', JSON.stringify(queryRet))
356
- if ( queryRet . code ) {
357
- throw new Error ( queryRet . msg )
358
- }
359
- const oldStatus = MemoryMapCacheUtil . get ( 'CloudTaskStatus' , taskId )
360
- if ( oldStatus !== queryRet . data . status ) {
361
- if ( 'process' === queryRet . data . status ) {
362
- context . send ( 'taskRunning' , { id : data . id } )
363
- }
364
- MemoryMapCacheUtil . set ( 'CloudTaskStatus' , taskId , queryRet . data . status )
365
- context . send ( 'taskStatus' , { id : data . id , status : queryRet . data . status } )
366
- }
367
- if ( 'success' === queryRet . data . status ) {
368
- launcherResult . status = 'success'
369
- launcherResult . endTime = Date . now ( )
370
- launcherResult . result = queryRet . data . result
371
- } else if ( 'fail' === queryRet . data . status || 'error' === queryRet . data . status ) {
372
- if ( queryRet . data . result && queryRet . data . result . msg ) {
373
- throw queryRet . data . result . msg
374
- }
375
- throw queryRet . data . status
376
- }
377
- return launcherResult
378
- }
379
-
380
270
export default {
381
271
GradioClient : Client ,
382
272
GradioHandleFile : handle_file ,
@@ -397,6 +287,4 @@ export default {
397
287
base64Decode : EncodeUtil . base64Decode ,
398
288
launcherSubmitAndQuery,
399
289
launcherPrepareConfigJson,
400
- launcherCloudSubmit,
401
- launcherCloudQuery,
402
290
}
0 commit comments