Skip to content

Commit 48369f2

Browse files
committed
升级版本
1 parent e9306a7 commit 48369f2

File tree

1 file changed

+0
-112
lines changed

1 file changed

+0
-112
lines changed

electron/mapi/server/api.ts

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import fs from 'node:fs'
88
import User, {UserApi} from "../user/main";
99
import {EncodeUtil, MemoryCacheUtil, MemoryMapCacheUtil} from "../../lib/util";
1010
import {ServerContext, ServerFunctionDataType} from "./type";
11-
import {UploadUtil} from "../../lib/upload";
1211

1312
const request = async (url, data?: {}, option?: {}) => {
1413
option = Object.assign({
@@ -268,115 +267,6 @@ const launcherPrepareConfigJson = async (data: any) => {
268267
return configJson
269268
}
270269

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-
380270
export default {
381271
GradioClient: Client,
382272
GradioHandleFile: handle_file,
@@ -397,6 +287,4 @@ export default {
397287
base64Decode: EncodeUtil.base64Decode,
398288
launcherSubmitAndQuery,
399289
launcherPrepareConfigJson,
400-
launcherCloudSubmit,
401-
launcherCloudQuery,
402290
}

0 commit comments

Comments
 (0)