Compare commits

...

6 Commits

Author SHA1 Message Date
CrescentLeaf
31133f5704 rename: docker-update 2025-11-09 16:43:14 +08:00
CrescentLeaf
93dad0b896 client: 自动进行重新验证 2025-11-09 16:42:44 +08:00
CrescentLeaf
8969fb7cb6 ui: 笼统的错误提示 2025-11-09 16:42:44 +08:00
CrescentLeaf
82c7c3772e ui: 当未登录时不会提示部分数据拉取错误 2025-11-09 16:42:43 +08:00
CrescentLeaf
df217b167e 加载消息和初次打开加载消息的页面置底优化? 2025-11-09 16:42:43 +08:00
CrescentLeaf
2f85aef136 chore: 删除调试代码 2025-11-09 16:42:43 +08:00
7 changed files with 56 additions and 25 deletions

View File

@@ -24,11 +24,39 @@ class Client {
session_id: this.sessionId,
},
})
this.socket!.on("connect", async () => {
this.connected = true
const re = await this.auth(data.access_token as string)
if (re.code != 200)
checkApiSuccessOrSncakbar(re, "重连失败")
this.socket!.on("connect", () => {
const auth = async () => {
this.connected = true
const s = snackbar({
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.connected = false
@@ -100,7 +128,7 @@ class Client {
}
static async refreshAccessToken() {
const re = await this.invoke("User.refreshAccessToken", {
refresh_token: data.refresh_token
refresh_token: data.refresh_token
})
return re.data?.access_token as string
}
@@ -118,13 +146,13 @@ class Client {
}
static async uploadFileLikeApi(fileName: string, fileData: ArrayBuffer | Blob | Response, chatId?: string) {
const form = new FormData()
form.append("file",
fileData instanceof ArrayBuffer
? new File([fileData], fileName, { type: 'application/octet-stream' })
: (
fileData instanceof Blob ? fileData :
new File([await fileData.arrayBuffer()], fileName, { type: 'application/octet-stream' })
)
form.append("file",
fileData instanceof ArrayBuffer
? new File([fileData], fileName, { type: 'application/octet-stream' })
: (
fileData instanceof Blob ? fileData :
new File([await fileData.arrayBuffer()], fileName, { type: 'application/octet-stream' })
)
)
form.append('file_name', fileName)
chatId && form.append('chat_id', chatId)

View File

@@ -61,11 +61,9 @@ const sanitizeConfig = {
const markedInstance = new marked.Marked({
renderer: {
text({ text }) {
console.log('普通文字', text)
return `<chat-text>${escapeHTML(text)}</chat-text>`
},
em({ text }) {
console.log('斜体', text)
return `<chat-text em="true">${escapeHTML(text)}</chat-text>`
},
heading({ tokens, depth: _depth }) {
@@ -126,7 +124,7 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
top: 10000000000,
behavior: "smooth",
})
}, 300)
}, 500)
}
useAsyncEffect(getChatInfoAndInit, [target])
@@ -150,7 +148,7 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
const oldest = messagesList[0]
setMessagesList(returnMsgs.concat(messagesList))
setTimeout(() => chatPanelRef.current!.scrollTo({ top: $(`#chat_${target}_message_${oldest.id}`).get(0).offsetTop, behavior: 'smooth' }), 100)
setTimeout(() => chatPanelRef.current!.scrollTo({ top: $(`#chat_${target}_message_${oldest.id}`).get(0).offsetTop }), 200)
}
React.useEffect(() => {

View File

@@ -37,7 +37,6 @@ function prettyFlatParsedMessage(html: string) {
}
}
for (const e of elements) {
console.log(e)
// 当出现非文本元素时, 将文本聚合在一起
// 如果是其他类型, 虽然也执行聚合, 但是不会有外层包裹
checkContinuousElement(e.nodeName.toLowerCase())

View File

@@ -39,9 +39,10 @@ export default function ContactsList({
const re = await Client.invoke("User.getMyContacts", {
token: data.access_token,
})
if (re.code != 200)
return checkApiSuccessOrSncakbar(re, "获取所有对话列表失败")
if (re.code != 200) {
if (re.code != 401) checkApiSuccessOrSncakbar(re, "获取收藏对话列表失败")
return
}
const ls = re.data!.contacts_list as Chat[]
setContactsList(ls)
setSharedFavouriteChats(ls)

View File

@@ -35,9 +35,11 @@ export default function RecentsList({
const re = await Client.invoke("User.getMyRecentChats", {
token: data.access_token,
})
if (re.code != 200)
return checkApiSuccessOrSncakbar(re, "获取最近对话列表失败")
if (re.code != 200) {
if (re.code != 401) checkApiSuccessOrSncakbar(re, "获取最近对话列表失败")
return
}
setRecentsList(re.data!.recent_chats as RecentChat[])
}
updateRecents()

View File

@@ -86,7 +86,10 @@ interface SnackbarOptions extends Options {
export function checkApiSuccessOrSncakbar(re: ApiCallbackMessage, msg_ahead: string, opinions_override: Options = {}): Snackbar | null {
return re.code != 200 ? snackbar(
Object.assign({
message: `${msg_ahead}: ${re.msg} [${re.code}]`,
message: `${msg_ahead}: ${re.msg.indexOf("Failed to fetch") != -1
? "HTTP 请求失败"
: re.msg
} [${re.code}]`,
placement: "top",
} as SnackbarOptions, opinions_override)
) : null