fix scan routing and zip download errors
This commit is contained in:
+6
-2
@@ -111,7 +111,9 @@ const download = options => new Promise((resolve, reject) => {
|
||||
if (res.statusCode === 401) {
|
||||
clearAuth()
|
||||
}
|
||||
reject(new Error(`下载失败:${res.statusCode}`))
|
||||
const error = new Error(`下载失败:${res.statusCode}`)
|
||||
error.statusCode = res.statusCode
|
||||
reject(error)
|
||||
},
|
||||
fail: err => {
|
||||
reject(new Error(err.errMsg || '下载失败'))
|
||||
@@ -137,7 +139,9 @@ const downloadUrl = options => new Promise((resolve, reject) => {
|
||||
if (res.statusCode === 401) {
|
||||
clearAuth()
|
||||
}
|
||||
reject(new Error(`下载失败:${res.statusCode}`))
|
||||
const error = new Error(`下载失败:${res.statusCode}`)
|
||||
error.statusCode = res.statusCode
|
||||
reject(error)
|
||||
},
|
||||
fail: err => {
|
||||
reject(new Error(err.errMsg || '下载失败'))
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
const ERP_LOGIN_PAGE = '/pages/erpLoginConfirm/erpLoginConfirm'
|
||||
const ERP_LOGIN_PAGE_PATH = 'pages/erpLoginConfirm/erpLoginConfirm'
|
||||
|
||||
const decodeRepeated = value => {
|
||||
let text = String(value || '').trim()
|
||||
for (let index = 0; index < 3; index += 1) {
|
||||
try {
|
||||
const decoded = decodeURIComponent(text)
|
||||
if (decoded === text) {
|
||||
break
|
||||
}
|
||||
text = decoded
|
||||
} catch (error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
const extractParam = (value, names) => {
|
||||
const raw = decodeRepeated(value)
|
||||
for (let index = 0; index < names.length; index += 1) {
|
||||
const name = names[index]
|
||||
const matched = raw.match(new RegExp(`(?:^|[?&])${name}=([^&]+)`))
|
||||
if (matched && matched[1]) {
|
||||
return decodeRepeated(matched[1])
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const extractRawParam = (value, names) => {
|
||||
const raw = String(value || '').trim()
|
||||
for (let index = 0; index < names.length; index += 1) {
|
||||
const name = names[index]
|
||||
const matched = raw.match(new RegExp(`(?:^|[?&])${name}=([^&]+)`))
|
||||
if (matched && matched[1]) {
|
||||
return matched[1]
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const erpSceneFromText = value => {
|
||||
const rawText = String(value || '').trim()
|
||||
const rawScene = extractRawParam(rawText, ['scene'])
|
||||
if (rawScene) {
|
||||
const decodedScene = decodeRepeated(rawScene)
|
||||
const nested = erpSceneFromText(decodedScene)
|
||||
if (nested) {
|
||||
return nested
|
||||
}
|
||||
const sceneTicket = extractParam(decodedScene, ['ticket', 't'])
|
||||
const sessionId = extractParam(rawText, ['session_id', 'sessionId', 's'])
|
||||
if (sceneTicket && sessionId) {
|
||||
return `t=${sceneTicket}&s=${sessionId}`
|
||||
}
|
||||
}
|
||||
const raw = decodeRepeated(value)
|
||||
if (!raw) {
|
||||
return ''
|
||||
}
|
||||
const nestedScene = extractParam(raw, ['scene'])
|
||||
if (nestedScene) {
|
||||
const nested = erpSceneFromText(nestedScene)
|
||||
if (nested) {
|
||||
return nested
|
||||
}
|
||||
}
|
||||
const ticket = extractParam(raw, ['ticket', 't'])
|
||||
const sessionId = extractParam(raw, ['session_id', 'sessionId', 's'])
|
||||
if (!ticket || !sessionId) {
|
||||
return ''
|
||||
}
|
||||
return `t=${ticket}&s=${sessionId}`
|
||||
}
|
||||
|
||||
const isErpLoginPath = value => decodeRepeated(value).replace(/^\/+/, '').includes(ERP_LOGIN_PAGE_PATH)
|
||||
|
||||
const buildErpLoginConfirmUrlFromScanResult = scanResult => {
|
||||
const candidates = [
|
||||
scanResult && scanResult.path,
|
||||
scanResult && scanResult.result,
|
||||
scanResult && scanResult.rawData,
|
||||
]
|
||||
for (let index = 0; index < candidates.length; index += 1) {
|
||||
const candidate = decodeRepeated(candidates[index])
|
||||
if (!candidate) {
|
||||
continue
|
||||
}
|
||||
const scene = erpSceneFromText(candidate)
|
||||
if (scene && (isErpLoginPath(candidate) || !extractParam(scene, ['mold']))) {
|
||||
return `${ERP_LOGIN_PAGE}?scene=${encodeURIComponent(scene)}`
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildErpLoginConfirmUrlFromScanResult,
|
||||
decodeRepeated,
|
||||
}
|
||||
Reference in New Issue
Block a user