From 205bdd704e36c5873d7ff8b217e042853281ed77 Mon Sep 17 00:00:00 2001 From: tbxark Date: Thu, 19 Sep 2024 11:01:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E4=B8=ADbool=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AFBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 30 +++++------------------------- dist/timestamp | 2 +- package.json | 2 +- src/config/merger.ts | 2 +- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 80b97020..939895f4 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha":"8c99bc8","timestamp":1725609436} \ No newline at end of file +{"sha":"bb11947","timestamp":1726714840} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 3f54e3ab..fb2ac9b1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,7 +36,7 @@ class ConfigMerger { if (exclude && exclude.includes(key)) { continue; } - const t = target[key] ? typeof target[key] : "string"; + const t = target[key] !== null && target[key] !== void 0 ? typeof target[key] : "string"; if (typeof source[key] !== "string") { target[key] = source[key]; continue; @@ -132,7 +132,6 @@ class EnvironmentConfig { HIDE_COMMAND_BUTTONS = []; SHOW_REPLY_BUTTON = false; EXTRA_MESSAGE_CONTEXT = false; - TELEGRAPH_ENABLE = false; STREAM_MODE = true; SAFE_MODE = true; DEBUG_MODE = false; @@ -212,8 +211,8 @@ const ENV_KEY_MAPPER = { WORKERS_AI_MODEL: "WORKERS_CHAT_MODEL" }; class Environment extends EnvironmentConfig { - BUILD_TIMESTAMP = 1725609436 ; - BUILD_VERSION = "8c99bc8" ; + BUILD_TIMESTAMP = 1726714840 ; + BUILD_VERSION = "bb11947" ; I18N = loadI18n(); PLUGINS_ENV = {}; USER_CONFIG = createAgentUserConfig(); @@ -417,22 +416,6 @@ async function fetchImage(url) { return blob; }); } -async function uploadImageToTelegraph(url) { - if (url.startsWith("https://telegra.ph")) { - return url; - } - const raw = await fetchImage(url); - const formData = new FormData(); - formData.append("file", raw, "blob"); - const resp = await fetch("https://telegra.ph/upload", { - method: "POST", - body: formData - }); - let [{ src }] = await resp.json(); - src = `https://telegra.ph${src}`; - IMAGE_CACHE.set(src, raw); - return src; -} async function urlToBase64String(url) { try { const { Buffer } = await import('node:buffer'); @@ -1747,11 +1730,8 @@ class ChatHandler { const id = findPhotoFileID(message.photo, ENV.TELEGRAM_PHOTO_SIZE_OFFSET); const api = createTelegramBotAPI(context.SHARE_CONTEXT.botToken); const file = await api.getFileWithReturns({ file_id: id }); - let url = file.result.file_path; + const url = file.result.file_path; if (url) { - if (ENV.TELEGRAPH_ENABLE) { - url = await uploadImageToTelegraph(url); - } params.images = [url]; } } @@ -2716,7 +2696,7 @@ class Router { return path.replace(/\/+(\/|$)/g, "$1"); } createRouteRegex(path) { - return RegExp(`^${path.replace(/(\/?\.?):(\w+)\+/g, "($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g, "($1(?<$2>[^$1/]+?))").replace(/\./g, "\\.").replace(/(\/?)\*/g, "($1.*)?")}/*$`); + return new RegExp(`^${path.replace(/(\/?\.?):(\w+)\+/g, "($1(?<$2>*))").replace(/(\/?\.?):(\w+)/g, "($1(?<$2>[^$1/]+?))").replace(/\./g, "\\.").replace(/(\/?)\*/g, "($1.*)?")}/*$`); } async fetch(request, ...args) { try { diff --git a/dist/timestamp b/dist/timestamp index 7d22b2c6..4e4af4c8 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1725609436 \ No newline at end of file +1726714840 \ No newline at end of file diff --git a/package.json b/package.json index cc85bf4d..a05f8c42 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "chatgpt-telegram-workers", "type": "module", - "version": "1.9.3", + "version": "1.9.4", "description": "The easiest and quickest way to deploy your own ChatGPT Telegram bot is to use a single file and simply copy and paste it. There is no need for any dependencies, local development environment configuration, domain names, or servers.", "author": "tbxark ", "license": "MIT", diff --git a/src/config/merger.ts b/src/config/merger.ts index 7d43130d..70a76a72 100644 --- a/src/config/merger.ts +++ b/src/config/merger.ts @@ -42,7 +42,7 @@ export class ConfigMerger { continue; } // 默认为字符串类型 - const t = target[key] ? typeof target[key] : 'string'; + const t = (target[key] !== null && target[key] !== undefined) ? typeof target[key] : 'string'; // 不是字符串直接赋值 if (typeof source[key] !== 'string') { target[key] = source[key];