Skip to content

Commit

Permalink
fix: fix configuration not being read correctly;
Browse files Browse the repository at this point in the history
chore: simplify the process of getting file url
  • Loading branch information
adolphnov committed Aug 10, 2024
1 parent 4035f15 commit 3707885
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sha": "5beae95", "timestamp": 1723266518}
{"sha": "4035f15", "timestamp": 1723299614}
25 changes: 11 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ var Environment = class {
// -- 版本数据 --
//
// 当前版本
BUILD_TIMESTAMP = 1723266518;
BUILD_TIMESTAMP = 1723299614;
// 当前版本 commit id
BUILD_VERSION = "5beae95";
BUILD_VERSION = "4035f15";
// -- 基础配置 --
/**
* @type {I18n | null}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(" | ")}`;
Expand Down
2 changes: 1 addition & 1 deletion dist/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1723266518
1723299614
10 changes: 5 additions & 5 deletions src/config/middle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENV } from "./env.js";
import { getFileInfo } from '../telegram/telegram.js';
import { getFileUrl } from '../telegram/telegram.js';

/**
* 提取消息类型与文件url
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(' | ')}`;
}
Expand Down
15 changes: 6 additions & 9 deletions src/telegram/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,18 @@ export async function getBot(token) {
* 获取TG文件信息
* @param {string} file_id
* @param {string} token
* @return {Promise<Response}
* @return {string}
*/
export async function getFileInfo(file_id, token) {
const resp = await fetchWithRetry(`${ENV.TELEGRAM_API_DOMAIN}/bot${token}/getFile?file_id=${file_id}`, {
export 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 '';
}

0 comments on commit 3707885

Please sign in to comment.