mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-23 06:38:13 -05:00
🔨 Refactor: picgo server the way of uploading
This commit is contained in:
parent
ab762ef465
commit
cf895deb8d
@ -54,7 +54,7 @@ const handleTalkingData = (webContents: WebContents, options: IAnalyticsData) =>
|
||||
|
||||
class Uploader {
|
||||
private webContents: WebContents | null = null
|
||||
private uploading: boolean = false
|
||||
// private uploading: boolean = false
|
||||
constructor () {
|
||||
this.init()
|
||||
}
|
||||
@ -109,18 +109,18 @@ class Uploader {
|
||||
}
|
||||
|
||||
async upload (img?: IUploadOption): Promise<ImgInfo[]|false> {
|
||||
if (this.uploading) {
|
||||
showNotification({
|
||||
title: '上传失败',
|
||||
body: '前序上传还在继续,请稍后再试'
|
||||
})
|
||||
return Promise.resolve(false)
|
||||
}
|
||||
// if (this.uploading) {
|
||||
// showNotification({
|
||||
// title: '上传失败',
|
||||
// body: '前序上传还在继续,请稍后再试'
|
||||
// })
|
||||
// return Promise.resolve(false)
|
||||
// }
|
||||
try {
|
||||
const startTime = Date.now()
|
||||
this.uploading = true
|
||||
// this.uploading = true
|
||||
const output = await picgo.upload(img)
|
||||
this.uploading = false
|
||||
// this.uploading = false
|
||||
if (Array.isArray(output) && output.every((item: ImgInfo) => item.imgUrl)) {
|
||||
if (this.webContents) {
|
||||
handleTalkingData(this.webContents, {
|
||||
@ -135,7 +135,7 @@ class Uploader {
|
||||
return false
|
||||
}
|
||||
} catch (e) {
|
||||
this.uploading = false
|
||||
// this.uploading = false
|
||||
logger.error(e)
|
||||
setTimeout(() => {
|
||||
showNotification({
|
||||
|
@ -67,7 +67,7 @@ class Server {
|
||||
}
|
||||
})
|
||||
}
|
||||
logger.info(`[PicGo Server] get the request`)
|
||||
logger.info(`[PicGo Server] get the request`, body)
|
||||
const handler = routers.getHandler(request.url!)
|
||||
handler!({
|
||||
...postObj,
|
||||
|
@ -1,12 +1,10 @@
|
||||
import router from './router'
|
||||
import {
|
||||
uploadWithClipboardFiles,
|
||||
uploadWithFiles
|
||||
} from '@core/bus/apis'
|
||||
import {
|
||||
handleResponse
|
||||
} from './utils'
|
||||
import logger from '@core/picgo/logger'
|
||||
import windowManager from 'apis/app/window/windowManager'
|
||||
import { uploadChoosedFiles, uploadClipboardFiles } from 'apis/app/uploader/apis'
|
||||
|
||||
router.post('/upload', async ({
|
||||
response,
|
||||
@ -19,13 +17,13 @@ router.post('/upload', async ({
|
||||
if (list.length === 0) {
|
||||
// upload with clipboard
|
||||
logger.info('[PicGo Server] upload clipboard file')
|
||||
const res = await uploadWithClipboardFiles()
|
||||
if (res.success) {
|
||||
const res = await uploadClipboardFiles()
|
||||
if (res) {
|
||||
handleResponse({
|
||||
response,
|
||||
body: {
|
||||
success: true,
|
||||
result: res.result
|
||||
result: res
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@ -45,13 +43,14 @@ router.post('/upload', async ({
|
||||
path: item
|
||||
}
|
||||
})
|
||||
const res = await uploadWithFiles(pathList)
|
||||
if (res.success) {
|
||||
const win = windowManager.getAvailableWindow()
|
||||
const res = await uploadChoosedFiles(win.webContents, pathList)
|
||||
if (res.length) {
|
||||
handleResponse({
|
||||
response,
|
||||
body: {
|
||||
success: true,
|
||||
result: res.result
|
||||
result: res
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user