From 3707885a439aa323e608e4b39ab87dbf02813ceb Mon Sep 17 00:00:00 2001 From: adolphzhang Date: Sat, 10 Aug 2024 22:20:35 +0800 Subject: [PATCH] fix: fix configuration not being read correctly; chore: simplify the process of getting file url --- dist/buildinfo.json | 2 +- dist/index.js | 25 +++++++++++-------------- dist/timestamp | 2 +- src/config/middle.js | 10 +++++----- src/telegram/telegram.js | 15 ++++++--------- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 67f3a85cd..86ff5eb3a 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "5beae95", "timestamp": 1723266518} +{"sha": "4035f15", "timestamp": 1723299614} diff --git a/dist/index.js b/dist/index.js index 39c6428ad..59d17e9e9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -153,9 +153,9 @@ var Environment = class { // -- 版本数据 -- // // 当前版本 - BUILD_TIMESTAMP = 1723266518; + BUILD_TIMESTAMP = 1723299614; // 当前版本 commit id - BUILD_VERSION = "5beae95"; + BUILD_VERSION = "4035f15"; // -- 基础配置 -- /** * @type {I18n | null} @@ -1007,20 +1007,17 @@ async function getBot(token) { return resp; } } -async function getFileInfo(file_id, token) { - const resp = await fetchWithRetry(`${ENV.TELEGRAM_API_DOMAIN}/bot${token}/getFile?file_id=${file_id}`, { +async function getFileUrl(file_id, token) { + const resp = await fetch(`${ENV.TELEGRAM_API_DOMAIN}/bot${token}/getFile?file_id=${file_id}`, { method: "POST", headers: { "Content-Type": "application/json" } }).then((r) => r.json()); - if (resp.ok) { - return { - ok: true, - file_path: resp.result.file_path - }; + if (resp.ok && resp.result.file_path) { + return resp.result.file_path; } - return resp; + return ""; } // src/agent/stream.js @@ -2292,12 +2289,12 @@ async function extractMessageType(message, botToken) { msgText: message.text || message.caption }; if (file_id) { - const file_info = await getFileInfo(file_id, botToken); - if (!file_info.file_path) { + const file_url = await getFileUrl(file_id, botToken); + if (!file_url) { console.log("[FILE FAILED]: " + msgType); throw new Error("file url get failed."); } - info.file_url = `${ENV.TELEGRAM_API_DOMAIN}/file/bot${botToken}/${file_info.file_path}`; + info.file_url = `${ENV.TELEGRAM_API_DOMAIN}/file/bot${botToken}/${file_url}`; console.log("file url: " + info.file_url); } return info; @@ -2365,7 +2362,7 @@ var MiddleInfo = class { if (ENV.CALL_INFO) call_info = (this.call_info && this.call_info + "\n").replace("$$f_t$$", ""); let info = stepInfo + call_info + `${this.model} ${time}s`; - const show_info = this.processes?.[this.step_index - 1]?.show_info || this._bp_config.ENABLE_SHOWINFO; + const show_info = this.processes[this.step_index - 1]?.show_info ?? this._bp_config.ENABLE_SHOWINFO; if (show_info && this.token_info[this.step_index - 1]) { info += ` Token: ${Object.values(this.token_info[this.step_index - 1]).join(" | ")}`; diff --git a/dist/timestamp b/dist/timestamp index 584a37f72..a232fd18c 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1723266518 +1723299614 diff --git a/src/config/middle.js b/src/config/middle.js index 3142c6f75..c02c2e0e7 100644 --- a/src/config/middle.js +++ b/src/config/middle.js @@ -1,5 +1,5 @@ import { ENV } from "./env.js"; -import { getFileInfo } from '../telegram/telegram.js'; +import { getFileUrl } from '../telegram/telegram.js'; /** * 提取消息类型与文件url @@ -63,12 +63,12 @@ async function extractMessageType(message, botToken) { msgText: message.text || message.caption, }; if (file_id) { - const file_info = await getFileInfo(file_id, botToken); - if (!file_info.file_path) { + const file_url = await getFileUrl(file_id, botToken); + if (!file_url) { console.log('[FILE FAILED]: ' + msgType); throw new Error('file url get failed.'); } - info.file_url = `${ENV.TELEGRAM_API_DOMAIN}/file/bot${botToken}/${file_info.file_path}`; + info.file_url = `${ENV.TELEGRAM_API_DOMAIN}/file/bot${botToken}/${file_url}`; console.log("file url: " + info.file_url); } @@ -156,7 +156,7 @@ export class MiddleInfo { if (ENV.CALL_INFO) call_info = (this.call_info && (this.call_info + '\n')).replace('$$f_t$$', ''); let info = stepInfo + call_info + `${this.model} ${time}s`; - const show_info = this.processes?.[this.step_index - 1]?.show_info || this._bp_config.ENABLE_SHOWINFO; + const show_info = this.processes[this.step_index - 1]?.show_info ?? this._bp_config.ENABLE_SHOWINFO; if (show_info && this.token_info[this.step_index - 1]) { info += `\nToken: ${Object.values(this.token_info[this.step_index - 1]).join(' | ')}`; } diff --git a/src/telegram/telegram.js b/src/telegram/telegram.js index da1dbb84e..97665e5c5 100644 --- a/src/telegram/telegram.js +++ b/src/telegram/telegram.js @@ -425,21 +425,18 @@ export async function getBot(token) { * 获取TG文件信息 * @param {string} file_id * @param {string} token - * @return {Promise r.json()); - if (resp.ok) { - return { - ok: true, - file_path: resp.result.file_path - }; + if (resp.ok && resp.result.file_path) { + return resp.result.file_path; } - return resp; + return ''; }