Skip to content

Commit

Permalink
🐛 Fix: multiple uploading in the same time will cause output conflict
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #666
  • Loading branch information
Molunerfinn committed May 9, 2021
1 parent cf895de commit 06b67e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"keycode": "^2.2.0",
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"picgo": "^1.4.19",
"picgo": "^1.4.21",
"qrcode.vue": "^1.7.0",
"vue": "^2.6.10",
"vue-gallery": "^2.0.1",
Expand Down
14 changes: 2 additions & 12 deletions src/main/apis/app/uploader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,10 @@ class Uploader {
}

async upload (img?: IUploadOption): Promise<ImgInfo[]|false> {
// if (this.uploading) {
// showNotification({
// title: '上传失败',
// body: '前序上传还在继续,请稍后再试'
// })
// return Promise.resolve(false)
// }
try {
const startTime = Date.now()
// this.uploading = true
const output = await picgo.upload(img)
// this.uploading = false
if (Array.isArray(output) && output.every((item: ImgInfo) => item.imgUrl)) {
if (Array.isArray(output) && output.some((item: ImgInfo) => item.imgUrl)) {
if (this.webContents) {
handleTalkingData(this.webContents, {
fromClipboard: !img,
Expand All @@ -130,12 +121,11 @@ class Uploader {
duration: Date.now() - startTime
} as IAnalyticsData)
}
return output
return output.filter(item => item.imgUrl)
} else {
return false
}
} catch (e) {
// this.uploading = false
logger.error(e)
setTimeout(() => {
showNotification({
Expand Down
12 changes: 9 additions & 3 deletions src/main/server/routerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {
import logger from '@core/picgo/logger'
import windowManager from 'apis/app/window/windowManager'
import { uploadChoosedFiles, uploadClipboardFiles } from 'apis/app/uploader/apis'
import { app } from 'electron'
import path from 'path'
const STORE_PATH = app.getPath('userData')
const LOG_PATH = path.join(STORE_PATH, 'picgo.log')

const errorMessage = `upload error. see ${LOG_PATH} for more detail.`

router.post('/upload', async ({
response,
Expand All @@ -31,7 +37,7 @@ router.post('/upload', async ({
response,
body: {
success: false,
message: 'upload error'
message: errorMessage
}
})
}
Expand All @@ -58,7 +64,7 @@ router.post('/upload', async ({
response,
body: {
success: false,
message: 'upload error'
message: errorMessage
}
})
}
Expand All @@ -69,7 +75,7 @@ router.post('/upload', async ({
response,
body: {
success: false,
message: err
message: errorMessage
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8306,10 +8306,10 @@ performance-now@^2.1.0:
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=

picgo@^1.4.19:
version "1.4.19"
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.4.19.tgz#cbd4b39f1d1a2a5f231e62a7fdbf87f53298f2a8"
integrity sha512-Y1BUrwq9rzEDQ06ZV5ZR8WRZqQe5hAHNVs4F/nEtwWBfr2YFwPxdce0b/rEPMZDSM7dfCWrts2M1qZC8VxB2+g==
picgo@^1.4.21:
version "1.4.21"
resolved "https://registry.yarnpkg.com/picgo/-/picgo-1.4.21.tgz#5ebbacda85200d63f5f83128b1c1b37c10cd80f3"
integrity sha512-WxPVNbWa2LPFfPftRvdFqf1fwUn6TrBn2vm12hSMHUjhdU+7nK3uysBfL5R9/vOAk+OPt3bU74zRHYi6gME+Dw==
dependencies:
chalk "^2.4.1"
commander "^2.17.0"
Expand Down

0 comments on commit 06b67e5

Please sign in to comment.