Commit a0557323 by yixinjj

日志文件排队上传

1 parent 66959f50
......@@ -4,18 +4,36 @@ export default class LogsWorker {
logFile = null
constructor() {
this.logFile = uni.$logger.local.logger
this.isUploading = false
}
getLogFileList() {
return this.logFile.getLogFileList()
}
upload(deviceId, data) {
if (this.isUploading) {
const msg = `日志上传中,请稍后再试!`
uni.$logger.local.info(msg)
// this.ws.send(msg)
return
}
this.isUploading = true
const files = this.getLogFileList()
if (files?.length) {
files.sort((a, b) => a.name.localeCompare(b.name))
this.process(files, deviceId)
}
process(files, deviceId) {
files.forEach(file => this.post(file, deviceId))
}
async process(files, deviceId) {
if (files.length > 0) {
const file = files.shift()
await this.post(file, deviceId)
this.process(files, deviceId)
} else {
this.isUploading = false
}
}
post({ name, path }, deviceId) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: `${config.PROTOCAL}://${config.SERVER}:${config.HTTP_PORT}/${config.FILE_UPLOAD_URL}`,
filePath: path,
......@@ -28,14 +46,17 @@ export default class LogsWorker {
type: 'log'
},
success: res => {
uni.$logger.local.info(`文件上传成功! res->${serializeIfObject(res)}`)
uni.$logger.local.info(`文件上传成功! res->${serializeIfObject(res)} filePath->${path}`)
resolve()
},
fail: res => {
uni.$logger.local.error(`文件上传失败! res->${serializeIfObject(res)}`)
uni.$logger.local.error(`文件上传失败! res->${serializeIfObject(res)} filePath->${path} .请检查服务端是否有文件被打开`)
resolve()
}
})
})
}
work(deviceId, data,ws) {
work(deviceId, data, ws) {
this.ws = ws
this.upload(deviceId, data)
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!