client: 自动进行重新验证
This commit is contained in:
@@ -24,11 +24,39 @@ class Client {
|
|||||||
session_id: this.sessionId,
|
session_id: this.sessionId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
this.socket!.on("connect", async () => {
|
this.socket!.on("connect", () => {
|
||||||
this.connected = true
|
const auth = async () => {
|
||||||
const re = await this.auth(data.access_token as string)
|
this.connected = true
|
||||||
if (re.code != 200)
|
const s = snackbar({
|
||||||
checkApiSuccessOrSncakbar(re, "重连失败")
|
message: '重新验证中...',
|
||||||
|
placement: 'top',
|
||||||
|
autoCloseDelay: 0,
|
||||||
|
})
|
||||||
|
let i = 1
|
||||||
|
const id = setInterval(() => {
|
||||||
|
s.textContent = `重新验证中... (${i}s)`
|
||||||
|
i++
|
||||||
|
}, 1000)
|
||||||
|
const re = await this.auth(data.access_token as string, 6000)
|
||||||
|
if (re.code != 200) {
|
||||||
|
if (re.code == -1) {
|
||||||
|
auth()
|
||||||
|
} else if (re.code != 401) {
|
||||||
|
const s2 = checkApiSuccessOrSncakbar(re, "重新验证失败")
|
||||||
|
s2!.autoCloseDelay = 0
|
||||||
|
s2!.action = "重试"
|
||||||
|
s2!.addEventListener('action-click', () => {
|
||||||
|
auth()
|
||||||
|
})
|
||||||
|
this.socket!.once("disconnect", () => {
|
||||||
|
s2!.open = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.open = false
|
||||||
|
clearTimeout(id)
|
||||||
|
}
|
||||||
|
auth()
|
||||||
})
|
})
|
||||||
this.socket!.on("disconnect", () => {
|
this.socket!.on("disconnect", () => {
|
||||||
this.connected = false
|
this.connected = false
|
||||||
@@ -120,11 +148,11 @@ class Client {
|
|||||||
const form = new FormData()
|
const form = new FormData()
|
||||||
form.append("file",
|
form.append("file",
|
||||||
fileData instanceof ArrayBuffer
|
fileData instanceof ArrayBuffer
|
||||||
? new File([fileData], fileName, { type: 'application/octet-stream' })
|
? new File([fileData], fileName, { type: 'application/octet-stream' })
|
||||||
: (
|
: (
|
||||||
fileData instanceof Blob ? fileData :
|
fileData instanceof Blob ? fileData :
|
||||||
new File([await fileData.arrayBuffer()], fileName, { type: 'application/octet-stream' })
|
new File([await fileData.arrayBuffer()], fileName, { type: 'application/octet-stream' })
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
form.append('file_name', fileName)
|
form.append('file_name', fileName)
|
||||||
chatId && form.append('chat_id', chatId)
|
chatId && form.append('chat_id', chatId)
|
||||||
|
|||||||
Reference in New Issue
Block a user