-
Notifications
You must be signed in to change notification settings - Fork 856
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from TBXark/dev
fix: 修复1.8.0 pre-release已知BUG
- Loading branch information
Showing
54 changed files
with
2,384 additions
and
696 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
config | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
FROM node:18 AS build | ||
|
||
FROM node:20 | ||
WORKDIR /app | ||
COPY package*.json index.js ./ | ||
RUN npm install | ||
COPY ./build/index.js /app/index.js | ||
RUN apt-get update && apt-get install -y sqlite3 | ||
VOLUME /app/config | ||
ENV CONFIG_PATH=/app/config.json | ||
ENV CACHE_PATH=/app/cache.json | ||
EXPOSE 8787 | ||
|
||
CMD [ "node", "index.js" ] | ||
CMD [ "node", "index.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Docker | ||
|
||
### 1. Build image | ||
|
||
```bash | ||
yarn && yarn run docker | ||
``` | ||
|
||
### 2. Run container | ||
|
||
```bash | ||
docker run -v $(pwd)/config.json:/app/config.json -p 8787:8787 chatgpt-telegram-bot:latest --name chatgpt-telegram-bot | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {build} from '../script/esbuild.config.js'; | ||
|
||
build('../../dist/buildinfo.json', 'build/index.js').catch(() => process.exit(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,23 @@ | ||
import adapter from 'cloudflare-worker-adapter'; | ||
import {default as worker} from 'chatgpt-telegram-workers'; | ||
import {default as adapter} from 'cloudflare-worker-adapter'; | ||
import {default as worker} from '../../main.js'; | ||
import fs from 'fs'; | ||
import {createCache} from 'cloudflare-worker-adapter/cache'; | ||
|
||
|
||
const config = JSON.parse(fs.readFileSync('./config/config.json', 'utf-8')); | ||
|
||
// 配置数据库 | ||
let cache; | ||
switch (config?.database?.type) { | ||
case 'local': | ||
// eslint-disable-next-line no-case-declarations | ||
const {LocalCache} = await import('cloudflare-worker-adapter/cache/local.js'); | ||
cache = new LocalCache(config.database.uri); | ||
break; | ||
case 'sqlite': | ||
// eslint-disable-next-line no-case-declarations | ||
const {SqliteCache} = await import('cloudflare-worker-adapter/cache/sqlite.js'); | ||
cache = new SqliteCache(config.database.uri); | ||
break; | ||
case 'redis': | ||
// eslint-disable-next-line no-case-declarations | ||
const {RedisCache} = await import('cloudflare-worker-adapter/cache/redis.js'); | ||
cache = new RedisCache(config.database.uri); | ||
break; | ||
default: | ||
// eslint-disable-next-line no-case-declarations | ||
const {MemoryCache} = await import('cloudflare-worker-adapter/cache/memory.js'); | ||
cache = new MemoryCache(); | ||
break; | ||
} | ||
const { | ||
CONFIG_PATH = './config/config.json', | ||
TOML_PATH = './config/config.toml', | ||
} = process.env; | ||
|
||
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8')); | ||
const cache = await createCache(config?.database?.type, config?.database); | ||
console.log(`database: ${config?.database?.type} is ready`); | ||
|
||
adapter.startServer( | ||
8787, | ||
'127.0.0.1', | ||
'./config/config.toml', | ||
{DATABASE: cache}, | ||
{server: config.server}, | ||
TOML_PATH, | ||
{ DATABASE: cache }, | ||
{ server: config.server }, | ||
worker.fetch, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@eslint/js@^9.8.0": | ||
version "9.9.0" | ||
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.9.0.tgz#d8437adda50b3ed4401964517b64b4f59b0e2638" | ||
integrity sha512-hhetes6ZHP3BlXLxmd8K2SNgkhNSi+UcecbnwWKwpP7kyi/uC75DJ1lOOBO3xrC4jyojtGE3YxKZPHfk4yrgug== | ||
|
||
"@gar/promisify@^1.0.1": | ||
version "1.1.3" | ||
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6" | ||
|
@@ -144,10 +149,6 @@ cacache@^15.2.0: | |
tar "^6.0.2" | ||
unique-filename "^1.1.1" | ||
|
||
"chatgpt-telegram-workers@github:TBXark/ChatGPT-Telegram-Workers#dev": | ||
version "1.7.0" | ||
resolved "https://codeload.github.com/TBXark/ChatGPT-Telegram-Workers/tar.gz/36495eb82a134f73f8eb4518bd5cca7692b3e4a5" | ||
|
||
chownr@^1.1.1: | ||
version "1.1.4" | ||
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" | ||
|
@@ -163,9 +164,10 @@ clean-stack@^2.0.0: | |
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" | ||
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A== | ||
|
||
"cloudflare-worker-adapter@github:TBXark/cloudflare-worker-adapter": | ||
version "1.0.1" | ||
resolved "https://codeload.github.com/TBXark/cloudflare-worker-adapter/tar.gz/48062ba3705f5a282e9d45c85e84d8c5017231b5" | ||
[email protected]: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/cloudflare-worker-adapter/-/cloudflare-worker-adapter-1.0.3.tgz#c87dda4b9f036c1b6887e36b52dbc4da8de198a0" | ||
integrity sha512-Eyd2JsmGvzSt46fG2spccARgIhlcTXcpPVGIwxpG9ocC229LVYtw+JZ1R6FbMUVplFjrPqNJ2zK+tqX2pkBoKw== | ||
dependencies: | ||
ioredis "^5.4.1" | ||
node-fetch "^3.3.2" | ||
|
@@ -198,9 +200,9 @@ data-uri-to-buffer@^4.0.0: | |
integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== | ||
|
||
debug@4, debug@^4.3.3, debug@^4.3.4: | ||
version "4.3.5" | ||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e" | ||
integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg== | ||
version "4.3.6" | ||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.6.tgz#2ab2c38fbaffebf8aa95fdfe6d88438c7a13c52b" | ||
integrity sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg== | ||
dependencies: | ||
ms "2.1.2" | ||
|
||
|
@@ -613,9 +615,9 @@ node-abi@^3.3.0: | |
semver "^7.3.5" | ||
|
||
node-addon-api@^7.0.0: | ||
version "7.1.0" | ||
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.0.tgz#71f609369379c08e251c558527a107107b5e0fdb" | ||
integrity sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g== | ||
version "7.1.1" | ||
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.1.tgz#1aba6693b0f255258a049d621329329322aad558" | ||
integrity sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ== | ||
|
||
node-domexception@^1.0.0: | ||
version "1.0.0" | ||
|
@@ -776,9 +778,9 @@ safe-buffer@^5.0.1, safe-buffer@~5.2.0: | |
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== | ||
|
||
semver@^7.3.5: | ||
version "7.6.2" | ||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" | ||
integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w== | ||
version "7.6.3" | ||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143" | ||
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A== | ||
|
||
set-blocking@^2.0.0: | ||
version "2.0.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
config.json | ||
cache.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM node:20 | ||
WORKDIR /app | ||
COPY ./build/index.js /app/index.js | ||
ENV CONFIG_PATH=/app/config.json | ||
ENV CACHE_PATH=/app/cache.json | ||
CMD [ "node", "index.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 本地部署(无需域名版本) | ||
|
||
## 使用步骤 | ||
1. 使用 `npm run config` 将toml配置文件转换为json配置文件 | ||
|
||
### 本地运行 | ||
1. 使用 `npm run start` 启动服务 | ||
|
||
### Docker运行 | ||
1. 使用 `npm run docker` 构建镜像 | ||
2. 使用 `docker run -v $(pwd)/config.json:/app/config.json -v $(pwd)/cache.json:/app/cache.json chatgpt-telegram-bot:latest --name chatgpt-telegram-bot` 运行容器 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import fs from 'node:fs'; | ||
import toml from 'toml'; | ||
|
||
const TOML_PATH = '../../wrangler.toml'; | ||
const raw = fs.readFileSync(TOML_PATH, 'utf-8'); | ||
const config = toml.parse(raw); | ||
fs.writeFileSync('./config.json', JSON.stringify(config, null, ' ')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {build} from '../script/esbuild.config.js'; | ||
|
||
build('../../dist/buildinfo.json', 'build/index.js').catch(() => process.exit(1)); |
Oops, something went wrong.