Skip to content

Commit

Permalink
chore: 分离插件预览页面
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Nov 14, 2024
1 parent 257dae7 commit 061a0d4
Show file tree
Hide file tree
Showing 34 changed files with 141 additions and 171 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 20
- run: make init && make all
- run: npm install -g pnpm
- run: pnpm install
- run: pnpm run build:all
4 changes: 3 additions & 1 deletion .github/workflows/cloudflare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
cat << 'EOF' > wrangler.toml
${{secrets.WRANGLER_TOML}}
EOF
- run: make init && make workers
- run: npm install -g pnpm
- run: pnpm install
- run: pnpm run build:all
- run: CLOUDFLARE_API_TOKEN=${{ secrets.CF_API_TOKEN }} pnpm run wrangler deploy --config=wrangler.toml > /dev/null

- name: Check CF_WORKERS_DOMAIN exists
Expand Down
53 changes: 0 additions & 53 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You can customize the system initialization information so that your debugged pe
- Streaming output
- Multi-language support
- Text-to-image generation
- [Plugin System](plugins), customizable plugins.
- [Plugin System](doc/en/PLUGINS.md), customizable plugins.


## Documentation
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ChatGPT-Telegram-Workers
- 流式输出
- 多语言支持
- 文字生成图片
- [插件系统](plugins),可以自定义插件
- [插件系统](doc/cn/PLUGINS.md),可以自定义插件


## 文档
Expand Down
4 changes: 2 additions & 2 deletions plugins/README_CN.md → doc/cn/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@ PLUGIN_ENV_access_token = "xxxx"

## 插件示例

1. [DNS查询插件示例](dns.json)
2. [字典查询插件示例](dicten.json)
1. [DNS查询插件示例](../../plugins/dns.json)
2. [字典查询插件示例](../../plugins/dicten.json)
4 changes: 2 additions & 2 deletions plugins/README.md → doc/en/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ It will be parsed as.

## Plugin Examples

1. [DNS Query Plugin Example](dns.json)
2. [Dictionary Query Plugin Example](dicten.json)
1. [DNS Query Plugin Example](../../plugins/dns.json)
2. [Dictionary Query Plugin Example](../../plugins/dicten.json)
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@
"scripts": {
"lint": "eslint --fix *.js *.ts packages plugins scripts",
"version": "tsx scripts/gen-version.ts",
"build:core": "make core",
"build:next": "make next",
"build:local": "make local",
"build:vercel": "make vercel",
"build:workers": "make workers",
"build:workers-next": "make workers-next",
"build:all": "make all",
"build:plugins": "pnpm run --filter @chatgpt-telegram-workers/plugins build",
"build:core": "pnpm run --filter @chatgpt-telegram-workers/core build",
"build:next": "pnpm run --filter @chatgpt-telegram-workers/next build",
"build:local": "pnpm run --filter @chatgpt-telegram-workers/local build",
"build:vercel": "pnpm run --filter @chatgpt-telegram-workers/vercel build",
"build:workers": "pnpm run --filter @chatgpt-telegram-workers/workers build",
"build:workers-next": "pnpm run --filter @chatgpt-telegram-workers/workers-next build",
"build:all": "pnpm -r run build",
"build:docker": "pnpm -r run build:all && docker build -t chatgpt-telegram-workers:latest .",
"build:dockerx": "pnpm -r run build:all && docker buildx build --platform linux/amd64,linux/arm64 -t chatgpt-telegram-workers:latest .",
"build:dist": "pnpm run version && pnpm -r run build:all && cp -r packages/apps/workers/dist/* dist/",
"deploy:dist": "pnpm run build:dist && wrangler deploy",
"start:local": "CONFIG_PATH=$INIT_CWD/config.json TOML_PATH=$INIT_CWD/wrangler.toml pnpm run --filter @chatgpt-telegram-workers/local start",
"clean": "pnpm -r run clean",
"wrangler": "wrangler"
},
"workspaces": [
"packages/app/*",
"packages/lib/*",
"packages/plugins/*"
"packages/lib/*"
],
"devDependencies": {
"wrangler": "^3.86.1",
Expand Down
50 changes: 1 addition & 49 deletions packages/apps/interpolate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatGPT-Telegram-Workers</title>
<script type="module" src="./dist/index.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
Expand Down Expand Up @@ -130,54 +129,7 @@ <h2>preview</h2>
<footer class="footer">
Find the source code on <a href="https://github.com/TBXark/ChatGPT-Telegram-Workers" target="_blank">ChatGPT-Telegram-Workers</a>
</footer>

<script type="module">

import interpolate from './dist/index.js';

function updatePreview() {
const template = document.getElementById('template').value;
const data = document.getElementById('data').value;
try {
document.getElementById('preview').innerHTML = interpolate(template, JSON.parse(data));
} catch (e) {
document.getElementById('preview').innerHTML = `<span style="color: red;">${e.message}</span>`;
}
}
document.getElementById('template').addEventListener('input', updatePreview);
document.getElementById('data').addEventListener('input', updatePreview);

document.getElementById('template').value = `
<b>DNS query: {{Question[0].name}}</b>
<code>Status: {{#if TC}}TC,{{/if}}{{#if RD}}RD,{{/if}}{{#if RA}}RA,{{/if}}{{#if AD}}AD,{{/if}}{{#if CD}}CD,{{/if}}{{Status}}</code>
<b>Answer</b>{{#each answer in Answer}}
<code>{{answer.name}}, {{answer.type}}, (TTL: {{answer.TTL}}),{{answer.data}}</code>{{/each}}
`
document.getElementById('data').value = JSON.stringify({
"Status": 0,
"TC": false,
"RD": true,
"RA": true,
"AD": false,
"CD": false,
"Question": [
{
"name": "google.com",
"type": 1
}
],
"Answer": [
{
"name": "google.com",
"type": 1,
"TTL": 300,
"data": "172.217.24.110"
}
]
}, null, 2)
updatePreview()
</script>
<script type="module" src="./src/index.ts"></script>
</body>

</html>
2 changes: 1 addition & 1 deletion packages/apps/interpolate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "pnpm vite"
},
"dependencies": {
"@chatgpt-telegram-workers/interp": "workspace:*"
"@chatgpt-telegram-workers/plugins": "workspace:*"
},
"devDependencies": {
}
Expand Down
51 changes: 49 additions & 2 deletions packages/apps/interpolate/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
import { interpolate } from '@chatgpt-telegram-workers/interp';
import { interpolate } from '@chatgpt-telegram-workers/plugins';

export default interpolate;
const templateEle = document.getElementById('template') as HTMLInputElement;
const dataEle = document.getElementById('data') as HTMLInputElement;
const previewEle = document.getElementById('preview') as HTMLElement;

function updatePreview() {
const template = templateEle.value;
const data = dataEle.value;
try {
previewEle.innerHTML = interpolate(template, JSON.parse(data));
} catch (e) {
previewEle.innerHTML = `<span style="color: red;">${(e as Error).message}</span>`;
}
}

templateEle.addEventListener('input', updatePreview);
dataEle.addEventListener('input', updatePreview);

templateEle.value = `
<b>DNS query: {{Question[0].name}}</b>
<code>Status: {{#if TC}}TC,{{/if}}{{#if RD}}RD,{{/if}}{{#if RA}}RA,{{/if}}{{#if AD}}AD,{{/if}}{{#if CD}}CD,{{/if}}{{Status}}</code>
<b>Answer</b>{{#each answer in Answer}}
<code>{{answer.name}}, {{answer.type}}, (TTL: {{answer.TTL}}),{{answer.data}}</code>{{/each}}
`;

dataEle.value = JSON.stringify({
Status: 0,
TC: false,
RD: true,
RA: true,
AD: false,
CD: false,
Question: [
{
name: 'google.com',
type: 1,
},
],
Answer: [
{
name: 'google.com',
type: 1,
TTL: 300,
data: '172.217.24.110',
},
],
}, null, 2);
updatePreview();
18 changes: 9 additions & 9 deletions packages/apps/interpolate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"references": [
{ "path": "../../lib/interp" },
],
"include": ["src/**/*"]
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"references": [
{ "path": "../../lib/plugins" }
],
"include": ["src/**/*"]
}
20 changes: 15 additions & 5 deletions packages/apps/interpolate/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { createShareConfig } from '../../../vite.config.shared';
import { defineConfig } from 'vite';

export default createShareConfig({
root: __dirname,
nodeExternals: true,
excludeMonoRepoPackages: true,
export default defineConfig({
root: '.',
build: {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: 'index.html',
output: {
entryFileNames: 'index.js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
},
},
},
});
18 changes: 9 additions & 9 deletions packages/apps/local/package.docker.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@chatgpt-telegram-workers/local",
"type": "module",
"version": "1.10.2",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"cloudflare-worker-adapter": "^1.3.3"
}
"name": "@chatgpt-telegram-workers/local",
"type": "module",
"version": "1.10.2",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"cloudflare-worker-adapter": "^1.3.3"
}
}
4 changes: 2 additions & 2 deletions packages/apps/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"cloudflare-worker-adapter": "^1.3.3"
},
"devDependencies": {
"telegram-bot-api-types": "^7.11.0",
"@types/react": "^18.3.11",
"@vercel/node": "^3.2.24",
"@types/react": "^18.3.11"
"telegram-bot-api-types": "^7.11.0"
}
}
2 changes: 1 addition & 1 deletion packages/apps/vercel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"references": [
{ "path": "../../lib/core" }
],
"include": ["src/**/*"],
"include": ["src/**/*"]
}
4 changes: 2 additions & 2 deletions packages/apps/workers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
"rootDir": "./src",
"outDir": "./dist"
},
"references": [
{ "path": "../../lib/core" }
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "rm -rf dist"
},
"dependencies": {
"@chatgpt-telegram-workers/interp": "workspace:*"
"@chatgpt-telegram-workers/plugins": "workspace:*"
},
"devDependencies": {
"telegram-bot-api-types": "^7.11.0",
Expand Down
1 change: 1 addition & 0 deletions packages/lib/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './config/env';
export * from './route';
export * from './telegram/api';
export * from './telegram/handler';
export * from '@chatgpt-telegram-workers/plugins';

export const Workers = {
async fetch(request: Request, env: any): Promise<Response> {
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/core/src/telegram/command/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { RequestTemplate } from '@chatgpt-telegram-workers/plugins';
import type * as Telegram from 'telegram-bot-api-types';
import type { WorkerContext } from '../../config/context';
import type { RequestTemplate } from '../../plugins/template';
import type { CommandHandler } from './types';
import { executeRequest, formatInput } from '@chatgpt-telegram-workers/plugins';
import { ENV } from '../../config/env';
import { executeRequest, formatInput } from '../../plugins/template';
import { MessageSender } from '../utils/send';
import { loadChatRoleWithContext } from './auth';
import {
Expand Down
Loading

0 comments on commit 061a0d4

Please sign in to comment.