From 12861b80a1100e0da96c88512cc4d22bac432ef1 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Fri, 28 Nov 2025 23:10:50 +0800 Subject: [PATCH] =?UTF-8?q?chore(client-protocol):=20=E6=8A=BD=E5=8F=96?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=9F=BA=20http=20url=20=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client-protocol/LingChairClient.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/client-protocol/LingChairClient.ts b/client-protocol/LingChairClient.ts index 063ec8d..80790ab 100644 --- a/client-protocol/LingChairClient.ts +++ b/client-protocol/LingChairClient.ts @@ -168,6 +168,18 @@ export default class LingChairClient { return false } } + getBaseHttpUrl() { + const url = new URL(this.server_url) + return (({ + 'ws:': 'http:', + 'wss:': 'https:', + 'http:': 'http:', + 'https:': 'https:', + })[url.protocol] || 'http:') + '//' + url.host + } + getUrlForFileByHash(file_hash?: string, defaultUrl?: string) { + return file_hash ? (this.getBaseHttpUrl() + '/uploaded_files/' + file_hash) : defaultUrl + } async registerOrThrow({ nickname, username, @@ -201,13 +213,8 @@ export default class LingChairClient { ) form.append('file_name', fileName) chatId && form.append('chat_id', chatId) - const url = new URL(this.server_url) - const re = await fetch((({ - 'ws:': 'http:', - 'wss:': 'https:', - 'http:': 'http:', - 'https:': 'https:', - })[url.protocol] || 'http:') + '//' + url.host + '/upload_file', { + + const re = await fetch(this.getBaseHttpUrl() + '/upload_file', { method: 'POST', headers: { "Token": this.access_token,