|
@@ -182,42 +182,9 @@ class Worker {
|
|
|
return `http://${userPart}${host}:${port}`
|
|
return `http://${userPart}${host}:${port}`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async createOssClientWithProxy(sts, scene = 'unknown') {
|
|
|
|
|
- const base = this.buildOssBaseClientConfig(sts)
|
|
|
|
|
- try {
|
|
|
|
|
- const proxyEnabled = await QgProxyManager.isOutboundProxyEnabled()
|
|
|
|
|
- if (!proxyEnabled) return { client: new OSS(base), viaProxy: false }
|
|
|
|
|
-
|
|
|
|
|
- const frag = await QgProxyManager.getOutboundAxiosFragment({ forceRefresh: false })
|
|
|
|
|
- const proxyUrl = this.buildProxyUrlFromFragment(frag)
|
|
|
|
|
- if (!proxyUrl) return { client: new OSS(base), viaProxy: false }
|
|
|
|
|
-
|
|
|
|
|
- this.logger.info(`[lepao.oss] ${scene} 上传出站=HTTP代理 ${frag.proxy.host}:${frag.proxy.port}`)
|
|
|
|
|
- return {
|
|
|
|
|
- client: new OSS({
|
|
|
|
|
- ...base,
|
|
|
|
|
- enableProxy: true,
|
|
|
|
|
- proxy: proxyUrl
|
|
|
|
|
- }),
|
|
|
|
|
- viaProxy: true
|
|
|
|
|
- }
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- this.logger.warn(`[lepao.oss] ${scene} 代理配置异常,降级直连: ${e.message || e}`)
|
|
|
|
|
- return { client: new OSS(base), viaProxy: false }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async putOssWithFallback(sts, ossPath, content, scene = 'unknown') {
|
|
|
|
|
- const primary = await this.createOssClientWithProxy(sts, scene)
|
|
|
|
|
- try {
|
|
|
|
|
- await primary.client.put(ossPath, content)
|
|
|
|
|
- return
|
|
|
|
|
- } catch (e1) {
|
|
|
|
|
- if (!primary.viaProxy) throw e1
|
|
|
|
|
- this.logger.warn(`[lepao.oss] ${scene} 代理上传失败,回退直连: ${e1.message || e1}`)
|
|
|
|
|
- const directClient = new OSS(this.buildOssBaseClientConfig(sts))
|
|
|
|
|
- await directClient.put(ossPath, content)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ async putOssWithFallback(sts, ossPath, content) {
|
|
|
|
|
+ const directClient = new OSS(this.buildOssBaseClientConfig(sts))
|
|
|
|
|
+ await directClient.put(ossPath, content)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
isRunSuccess(bindResponse) {
|
|
isRunSuccess(bindResponse) {
|
|
@@ -1316,7 +1283,7 @@ class Worker {
|
|
|
const boundary = String(Date.now())
|
|
const boundary = String(Date.now())
|
|
|
const timestamp = String(Date.now())
|
|
const timestamp = String(Date.now())
|
|
|
const ossPath = `Public/Upload/file/run_record/${boundary.slice(-3)}/${formattedToday}/${timestamp}-${Math.floor(Math.random() * 150)}.txt`
|
|
const ossPath = `Public/Upload/file/run_record/${boundary.slice(-3)}/${formattedToday}/${timestamp}-${Math.floor(Math.random() * 150)}.txt`
|
|
|
- await this.putOssWithFallback(sts, ossPath, Buffer.from(pathResult, 'utf-8'), 'run_record')
|
|
|
|
|
|
|
+ await this.putOssWithFallback(sts, ossPath, Buffer.from(pathResult, 'utf-8'))
|
|
|
|
|
|
|
|
return { oss_path: ossPath, point_data: point_data }
|
|
return { oss_path: ossPath, point_data: point_data }
|
|
|
})
|
|
})
|
|
@@ -1339,12 +1306,7 @@ class Worker {
|
|
|
const boundary = String(Date.now())
|
|
const boundary = String(Date.now())
|
|
|
const timestamp = String(Date.now())
|
|
const timestamp = String(Date.now())
|
|
|
const ossPath = `Public/Upload/file/run_gyroscope/${boundary.slice(-3)}/${formattedToday}/${timestamp}-${Math.floor(Math.random() * 150)}.txt`
|
|
const ossPath = `Public/Upload/file/run_gyroscope/${boundary.slice(-3)}/${formattedToday}/${timestamp}-${Math.floor(Math.random() * 150)}.txt`
|
|
|
- await this.putOssWithFallback(
|
|
|
|
|
- sts,
|
|
|
|
|
- ossPath,
|
|
|
|
|
- Buffer.from(JSON.stringify(gyrData), 'utf-8'),
|
|
|
|
|
- 'run_gyroscope'
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ await this.putOssWithFallback(sts, ossPath, Buffer.from(JSON.stringify(gyrData), 'utf-8'))
|
|
|
|
|
|
|
|
const data = {
|
|
const data = {
|
|
|
uid: req.uid,
|
|
uid: req.uid,
|