chore: remove Node launcher and non-Gitea deploy configs
Drop start.mjs, vercel.json, zeabur.yaml, the Vercel Node entrypoint api/chat-stream.js, and the GitHub-only publish/release workflows (ghcr, dockerhub, release, release-artifacts). Deployment is docker-image only, hosted on Gitea.
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
name: Build and Publish GHCR Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
ghcr:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Resolve image name
|
||||
id: image
|
||||
run: |
|
||||
echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ steps.image.outputs.name }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=sha,prefix=sha-
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v6
|
||||
env:
|
||||
DOCKER_BUILD_RECORD_UPLOAD: "false"
|
||||
DOCKER_BUILD_SUMMARY: "false"
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
BUILD_VERSION=${{ github.ref_name }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
@@ -1,207 +0,0 @@
|
||||
name: Release Artifacts
|
||||
|
||||
on:
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release_tag:
|
||||
description: "Release tag to build/publish (e.g. v2.1.6)"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build-and-upload:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
RELEASE_TAG: ${{ github.event.release.tag_name || github.event.inputs.release_tag }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26.x"
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
cache: "npm"
|
||||
cache-dependency-path: webui/package-lock.json
|
||||
|
||||
- name: Release Blocking Gates
|
||||
run: |
|
||||
./tests/scripts/check-stage6-manual-smoke.sh
|
||||
./tests/scripts/check-refactor-line-gate.sh
|
||||
./tests/scripts/run-unit-all.sh
|
||||
|
||||
- name: Build WebUI
|
||||
run: |
|
||||
npm ci --prefix webui
|
||||
npm run build --prefix webui
|
||||
|
||||
- name: Build Multi-Platform Archives
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${RELEASE_TAG}"
|
||||
BUILD_VERSION="${TAG}"
|
||||
if [ -z "${BUILD_VERSION}" ] && [ -f VERSION ]; then
|
||||
BUILD_VERSION="$(cat VERSION | tr -d '[:space:]')"
|
||||
fi
|
||||
mkdir -p dist
|
||||
|
||||
targets=(
|
||||
"linux/amd64"
|
||||
"linux/arm64"
|
||||
"darwin/amd64"
|
||||
"darwin/arm64"
|
||||
"windows/amd64"
|
||||
)
|
||||
|
||||
for target in "${targets[@]}"; do
|
||||
GOOS="${target%/*}"
|
||||
GOARCH="${target#*/}"
|
||||
PKG="ds2api_${TAG}_${GOOS}_${GOARCH}"
|
||||
STAGE="dist/${PKG}"
|
||||
BIN="ds2api"
|
||||
if [ "${GOOS}" = "windows" ]; then
|
||||
BIN="ds2api.exe"
|
||||
fi
|
||||
|
||||
mkdir -p "${STAGE}/static"
|
||||
CGO_ENABLED=0 GOOS="${GOOS}" GOARCH="${GOARCH}" \
|
||||
go build -trimpath -ldflags="-s -w -X ds2api/internal/version.BuildVersion=${BUILD_VERSION}" -o "${STAGE}/${BIN}" ./cmd/ds2api
|
||||
|
||||
cp config.example.json .env.example LICENSE README.MD "${STAGE}/"
|
||||
cp -R static/admin "${STAGE}/static/admin"
|
||||
|
||||
if [ "${GOOS}" = "windows" ]; then
|
||||
(cd dist && zip -rq "${PKG}.zip" "${PKG}")
|
||||
else
|
||||
tar -C dist -czf "dist/${PKG}.tar.gz" "${PKG}"
|
||||
fi
|
||||
|
||||
rm -rf "${STAGE}"
|
||||
done
|
||||
|
||||
- name: Prepare Docker release inputs
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${RELEASE_TAG}"
|
||||
mkdir -p dist/docker-input
|
||||
cp "dist/ds2api_${TAG}_linux_amd64.tar.gz" "dist/docker-input/linux_amd64.tar.gz"
|
||||
cp "dist/ds2api_${TAG}_linux_arm64.tar.gz" "dist/docker-input/linux_arm64.tar.gz"
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Wait for GHCR endpoint
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for i in {1..6}; do
|
||||
code="$(curl -sS -o /dev/null -w '%{http_code}' --max-time 15 https://ghcr.io/v2/ || true)"
|
||||
if [ "${code}" = "200" ] || [ "${code}" = "401" ] || [ "${code}" = "405" ]; then
|
||||
exit 0
|
||||
fi
|
||||
sleep "$((i * 10))"
|
||||
done
|
||||
echo "GHCR endpoint is unreachable after multiple retries (last status: ${code:-unknown})." >&2
|
||||
exit 1
|
||||
|
||||
- name: Log in to GHCR (with retry)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for i in {1..6}; do
|
||||
if echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin; then
|
||||
exit 0
|
||||
fi
|
||||
sleep "$((i * 10))"
|
||||
done
|
||||
echo "Failed to login to GHCR after multiple retries." >&2
|
||||
exit 1
|
||||
|
||||
- name: Extract Docker metadata
|
||||
id: meta_release
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=raw,value=${{ env.RELEASE_TAG }}
|
||||
type=raw,value=latest
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
uses: docker/build-push-action@v6
|
||||
env:
|
||||
DOCKER_BUILD_RECORD_UPLOAD: "false"
|
||||
DOCKER_BUILD_SUMMARY: "false"
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
target: runtime-from-dist
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.meta_release.outputs.tags }}
|
||||
labels: ${{ steps.meta_release.outputs.labels }}
|
||||
|
||||
- name: Export Docker image archives for release assets
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${RELEASE_TAG}"
|
||||
|
||||
docker buildx build \
|
||||
--platform linux/amd64 \
|
||||
--target runtime-from-dist \
|
||||
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_amd64.tar" \
|
||||
.
|
||||
|
||||
docker buildx build \
|
||||
--platform linux/arm64 \
|
||||
--target runtime-from-dist \
|
||||
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_arm64.tar" \
|
||||
.
|
||||
|
||||
gzip -f "dist/ds2api_${TAG}_docker_linux_amd64.tar"
|
||||
gzip -f "dist/ds2api_${TAG}_docker_linux_arm64.tar"
|
||||
|
||||
- name: Generate checksums
|
||||
run: |
|
||||
set -euo pipefail
|
||||
(cd dist && sha256sum *.tar.gz *.zip > sha256sums.txt)
|
||||
|
||||
- name: Validate release tag
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${RELEASE_TAG}"
|
||||
if [ -z "${TAG}" ]; then
|
||||
echo "release tag is empty; set release_tag when using workflow_dispatch." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Upload Release Assets
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
TAG="${RELEASE_TAG}"
|
||||
FILES=(
|
||||
dist/*.tar.gz
|
||||
dist/*.zip
|
||||
dist/sha256sums.txt
|
||||
)
|
||||
|
||||
if gh release view "${TAG}" >/dev/null 2>&1; then
|
||||
gh release upload "${TAG}" "${FILES[@]}" --clobber
|
||||
else
|
||||
gh release create "${TAG}" "${FILES[@]}" --title "${TAG}" --notes ""
|
||||
fi
|
||||
@@ -1,129 +0,0 @@
|
||||
name: Release to Docker Hub
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version_type:
|
||||
description: '版本类型'
|
||||
required: true
|
||||
default: 'patch'
|
||||
type: choice
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get current version
|
||||
id: get_version
|
||||
run: |
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||
TAG_VERSION=${LATEST_TAG#v}
|
||||
|
||||
if [ -f VERSION ]; then
|
||||
FILE_VERSION=$(cat VERSION | tr -d '[:space:]')
|
||||
else
|
||||
FILE_VERSION="0.0.0"
|
||||
fi
|
||||
|
||||
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
|
||||
|
||||
if version_gt "$FILE_VERSION" "$TAG_VERSION"; then
|
||||
VERSION="$FILE_VERSION"
|
||||
else
|
||||
VERSION="$TAG_VERSION"
|
||||
fi
|
||||
|
||||
echo "Current version: $VERSION"
|
||||
echo "current_version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Calculate next version
|
||||
id: next_version
|
||||
env:
|
||||
VERSION_TYPE: ${{ github.event.inputs.version_type }}
|
||||
run: |
|
||||
VERSION="${{ steps.get_version.outputs.current_version }}"
|
||||
BASE_VERSION=$(echo "$VERSION" | sed 's/-.*$//')
|
||||
|
||||
IFS='.' read -r -a version_parts <<< "$BASE_VERSION"
|
||||
MAJOR="${version_parts[0]:-0}"
|
||||
MINOR="${version_parts[1]:-0}"
|
||||
PATCH="${version_parts[2]:-0}"
|
||||
|
||||
case "$VERSION_TYPE" in
|
||||
major)
|
||||
NEW_VERSION="$((MAJOR + 1)).0.0"
|
||||
;;
|
||||
minor)
|
||||
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
|
||||
;;
|
||||
*)
|
||||
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "New version: $NEW_VERSION"
|
||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update VERSION file
|
||||
run: |
|
||||
echo "${{ steps.next_version.outputs.new_version }}" > VERSION
|
||||
|
||||
- name: Commit VERSION and create tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
git add VERSION
|
||||
if ! git diff --cached --quiet; then
|
||||
git commit -m "chore: bump version to ${{ steps.next_version.outputs.new_tag }} [skip ci]"
|
||||
fi
|
||||
|
||||
NEW_TAG="${{ steps.next_version.outputs.new_tag }}"
|
||||
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
|
||||
git push origin HEAD:main "$NEW_TAG"
|
||||
|
||||
# Docker 构建并推送到 Docker Hub
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/ds2api:${{ steps.next_version.outputs.new_tag }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/ds2api:${{ steps.next_version.outputs.new_version }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/ds2api:latest
|
||||
labels: |
|
||||
org.opencontainers.image.version=${{ steps.next_version.outputs.new_version }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
build-args: |
|
||||
BUILD_VERSION=${{ steps.next_version.outputs.new_tag }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
@@ -1,130 +0,0 @@
|
||||
name: Release to Aliyun CR
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version_type:
|
||||
description: '版本类型'
|
||||
required: true
|
||||
default: 'patch'
|
||||
type: choice
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get current version
|
||||
id: get_version
|
||||
run: |
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||
TAG_VERSION=${LATEST_TAG#v}
|
||||
|
||||
if [ -f VERSION ]; then
|
||||
FILE_VERSION=$(cat VERSION | tr -d '[:space:]')
|
||||
else
|
||||
FILE_VERSION="0.0.0"
|
||||
fi
|
||||
|
||||
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
|
||||
|
||||
if version_gt "$FILE_VERSION" "$TAG_VERSION"; then
|
||||
VERSION="$FILE_VERSION"
|
||||
else
|
||||
VERSION="$TAG_VERSION"
|
||||
fi
|
||||
|
||||
echo "Current version: $VERSION"
|
||||
echo "current_version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Calculate next version
|
||||
id: next_version
|
||||
env:
|
||||
VERSION_TYPE: ${{ github.event.inputs.version_type }}
|
||||
run: |
|
||||
VERSION="${{ steps.get_version.outputs.current_version }}"
|
||||
BASE_VERSION=$(echo "$VERSION" | sed 's/-.*$//')
|
||||
|
||||
IFS='.' read -r -a version_parts <<< "$BASE_VERSION"
|
||||
MAJOR="${version_parts[0]:-0}"
|
||||
MINOR="${version_parts[1]:-0}"
|
||||
PATCH="${version_parts[2]:-0}"
|
||||
|
||||
case "$VERSION_TYPE" in
|
||||
major)
|
||||
NEW_VERSION="$((MAJOR + 1)).0.0"
|
||||
;;
|
||||
minor)
|
||||
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
|
||||
;;
|
||||
*)
|
||||
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "New version: $NEW_VERSION"
|
||||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update VERSION file
|
||||
run: |
|
||||
echo "${{ steps.next_version.outputs.new_version }}" > VERSION
|
||||
|
||||
- name: Commit VERSION and create tag
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
git add VERSION
|
||||
if ! git diff --cached --quiet; then
|
||||
git commit -m "chore: bump version to ${{ steps.next_version.outputs.new_tag }} [skip ci]"
|
||||
fi
|
||||
|
||||
NEW_TAG="${{ steps.next_version.outputs.new_tag }}"
|
||||
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
|
||||
git push origin HEAD:main "$NEW_TAG"
|
||||
|
||||
# Docker 构建并推送到阿里云
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Aliyun Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.ALIYUN_REGISTRY }}
|
||||
username: ${{ secrets.ALIYUN_REGISTRY_USER }}
|
||||
password: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.ALIYUN_REGISTRY }}/${{ secrets.ALIYUN_REGISTRY_NAMESPACE }}/ds2api:${{ steps.next_version.outputs.new_tag }}
|
||||
${{ secrets.ALIYUN_REGISTRY }}/${{ secrets.ALIYUN_REGISTRY_NAMESPACE }}/ds2api:${{ steps.next_version.outputs.new_version }}
|
||||
${{ secrets.ALIYUN_REGISTRY }}/${{ secrets.ALIYUN_REGISTRY_NAMESPACE }}/ds2api:latest
|
||||
labels: |
|
||||
org.opencontainers.image.version=${{ steps.next_version.outputs.new_version }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
build-args: |
|
||||
BUILD_VERSION=${{ steps.next_version.outputs.new_tag }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
@@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('../internal/js/chat-stream/index.js');
|
||||
@@ -1,567 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* DS2API 启动脚本 - 交互式菜单
|
||||
*
|
||||
* 使用方法:
|
||||
* node start.mjs # 显示交互式菜单
|
||||
* node start.mjs dev # 开发模式(后端 + 前端热重载)
|
||||
* node start.mjs prod # 生产模式(编译后运行)
|
||||
* node start.mjs build # 编译后端二进制
|
||||
* node start.mjs webui # 构建前端静态文件
|
||||
* node start.mjs install # 安装前端依赖
|
||||
* node start.mjs stop # 停止所有服务
|
||||
* node start.mjs status # 查看服务状态
|
||||
*/
|
||||
|
||||
import { spawn, execSync } from 'child_process';
|
||||
import { createInterface } from 'readline';
|
||||
import { existsSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// 判断是否为 Windows
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
// 编译产物路径
|
||||
const BINARY = join(__dirname, isWindows ? 'ds2api.exe' : 'ds2api');
|
||||
|
||||
// 配置(从环境变量读取,与 Go 主程序保持一致)
|
||||
const CONFIG = {
|
||||
port: process.env.PORT || '5001',
|
||||
frontendPort: 5173,
|
||||
logLevel: process.env.LOG_LEVEL || 'INFO',
|
||||
adminKey: process.env.DS2API_ADMIN_KEY || 'admin',
|
||||
webuiDir: join(__dirname, 'webui'),
|
||||
staticAdminDir: process.env.DS2API_STATIC_ADMIN_DIR || join(__dirname, 'static', 'admin'),
|
||||
};
|
||||
|
||||
// 国内镜像配置
|
||||
const MIRRORS = {
|
||||
goproxy: process.env.GOPROXY || 'https://goproxy.cn,direct',
|
||||
npm: process.env.NPM_REGISTRY || 'https://registry.npmmirror.com',
|
||||
};
|
||||
|
||||
// 存储子进程
|
||||
const processes = [];
|
||||
|
||||
// 颜色输出
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
bright: '\x1b[1m',
|
||||
dim: '\x1b[2m',
|
||||
red: '\x1b[31m',
|
||||
green: '\x1b[32m',
|
||||
yellow: '\x1b[33m',
|
||||
blue: '\x1b[34m',
|
||||
magenta: '\x1b[35m',
|
||||
cyan: '\x1b[36m',
|
||||
};
|
||||
|
||||
const log = {
|
||||
info: (msg) => console.log(`${colors.cyan}[INFO]${colors.reset} ${msg}`),
|
||||
success: (msg) => console.log(`${colors.green}[OK]${colors.reset} ${msg}`),
|
||||
warn: (msg) => console.log(`${colors.yellow}[WARN]${colors.reset} ${msg}`),
|
||||
error: (msg) => console.log(`${colors.red}[ERROR]${colors.reset} ${msg}`),
|
||||
title: (msg) => console.log(`\n${colors.bright}${colors.magenta}${msg}${colors.reset}`),
|
||||
};
|
||||
|
||||
// 清理并退出
|
||||
function cleanup() {
|
||||
console.log('\n');
|
||||
log.info('正在关闭所有服务...');
|
||||
processes.forEach(proc => {
|
||||
if (proc && !proc.killed) {
|
||||
proc.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
log.success('已退出');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
process.on('SIGINT', cleanup);
|
||||
process.on('SIGTERM', cleanup);
|
||||
|
||||
// 检查命令是否存在
|
||||
function commandExists(cmd) {
|
||||
try {
|
||||
execSync(`${isWindows ? 'where' : 'which'} ${cmd}`, { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查 Go 是否安装
|
||||
function checkGo() {
|
||||
return commandExists('go');
|
||||
}
|
||||
|
||||
// 获取 Go 版本
|
||||
function getGoVersion() {
|
||||
try {
|
||||
return execSync('go version', { encoding: 'utf-8' }).trim();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查前端依赖是否已安装
|
||||
function checkFrontendDeps() {
|
||||
if (!existsSync(CONFIG.webuiDir)) return null;
|
||||
return existsSync(join(CONFIG.webuiDir, 'node_modules'));
|
||||
}
|
||||
|
||||
// 检查前端是否已构建
|
||||
function checkWebuiBuilt() {
|
||||
return existsSync(join(CONFIG.staticAdminDir, 'index.html'));
|
||||
}
|
||||
|
||||
// 检查后端二进制是否存在
|
||||
function binaryExists() {
|
||||
return existsSync(BINARY);
|
||||
}
|
||||
|
||||
// 查找占用端口的进程 PID
|
||||
function findPidByPort(port) {
|
||||
try {
|
||||
if (isWindows) {
|
||||
const output = execSync(`netstat -ano | findstr :${port} | findstr LISTENING`, {
|
||||
encoding: 'utf-8',
|
||||
shell: true,
|
||||
stdio: ['pipe', 'pipe', 'ignore'],
|
||||
});
|
||||
const pids = new Set();
|
||||
for (const line of output.trim().split('\n')) {
|
||||
const parts = line.trim().split(/\s+/);
|
||||
const pid = parts[parts.length - 1];
|
||||
if (pid && pid !== '0') pids.add(pid);
|
||||
}
|
||||
return [...pids];
|
||||
} else {
|
||||
const output = execSync(`lsof -ti :${port}`, {
|
||||
encoding: 'utf-8',
|
||||
stdio: ['pipe', 'pipe', 'ignore'],
|
||||
});
|
||||
return output.trim().split('\n').filter(Boolean);
|
||||
}
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取运行中的服务状态
|
||||
function getRunningStatus() {
|
||||
const backendPids = findPidByPort(CONFIG.port);
|
||||
const frontendPids = findPidByPort(CONFIG.frontendPort);
|
||||
return {
|
||||
backend: backendPids,
|
||||
frontend: frontendPids,
|
||||
isRunning: backendPids.length > 0 || frontendPids.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 停止服务
|
||||
async function stopServices() {
|
||||
const running = getRunningStatus();
|
||||
|
||||
if (!running.isRunning) {
|
||||
log.warn('没有检测到正在运行的服务');
|
||||
return;
|
||||
}
|
||||
|
||||
log.title('========== 停止服务 ==========');
|
||||
|
||||
const killProcess = async (pid) => {
|
||||
try {
|
||||
if (isWindows) {
|
||||
try {
|
||||
execSync(`taskkill /PID ${pid}`, { stdio: 'ignore', shell: true });
|
||||
} catch {
|
||||
execSync(`taskkill /F /T /PID ${pid}`, { stdio: 'ignore', shell: true });
|
||||
}
|
||||
} else {
|
||||
execSync(`kill -15 ${pid}`, { stdio: 'ignore' });
|
||||
await new Promise(r => setTimeout(r, 500));
|
||||
try {
|
||||
execSync(`kill -0 ${pid}`, { stdio: 'ignore' });
|
||||
execSync(`kill -9 ${pid}`, { stdio: 'ignore' });
|
||||
} catch { /* 进程已退出 */ }
|
||||
}
|
||||
} catch { /* 进程可能已退出 */ }
|
||||
};
|
||||
|
||||
if (running.backend.length > 0) {
|
||||
log.info(`停止后端服务 (端口 ${CONFIG.port}, PID: ${running.backend.join(', ')})...`);
|
||||
for (const pid of running.backend) await killProcess(pid);
|
||||
log.success('后端服务已停止');
|
||||
}
|
||||
|
||||
if (running.frontend.length > 0) {
|
||||
log.info(`停止前端服务 (端口 ${CONFIG.frontendPort}, PID: ${running.frontend.join(', ')})...`);
|
||||
for (const pid of running.frontend) await killProcess(pid);
|
||||
log.success('前端服务已停止');
|
||||
}
|
||||
}
|
||||
|
||||
// 安装前端依赖
|
||||
async function installFrontendDeps() {
|
||||
if (!existsSync(CONFIG.webuiDir)) {
|
||||
log.warn('webui 目录不存在,跳过前端依赖安装');
|
||||
return;
|
||||
}
|
||||
log.info(`安装前端依赖 (npm ci, registry: ${MIRRORS.npm})...`);
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = spawn('npm', ['ci', '--registry', MIRRORS.npm], {
|
||||
cwd: CONFIG.webuiDir,
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
});
|
||||
proc.on('close', code => code === 0 ? resolve() : reject(new Error('前端依赖安装失败')));
|
||||
});
|
||||
}
|
||||
|
||||
// 确保前端依赖已安装
|
||||
async function ensureFrontendDeps() {
|
||||
if (checkFrontendDeps() === false) {
|
||||
log.warn('检测到前端依赖未安装,正在安装...');
|
||||
await installFrontendDeps();
|
||||
}
|
||||
}
|
||||
|
||||
// 编译后端二进制
|
||||
async function buildBackend() {
|
||||
if (!checkGo()) throw new Error('未找到 Go,请先安装 Go (https://go.dev/dl/)');
|
||||
log.info(`编译后端二进制 (GOPROXY: ${MIRRORS.goproxy})...`);
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = spawn('go', ['build', '-o', BINARY, './cmd/ds2api'], {
|
||||
cwd: __dirname,
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: { ...process.env, GOPROXY: MIRRORS.goproxy },
|
||||
});
|
||||
proc.on('close', code => code === 0 ? resolve() : reject(new Error('后端编译失败')));
|
||||
});
|
||||
}
|
||||
|
||||
// 构建前端静态文件
|
||||
async function buildWebui() {
|
||||
if (!existsSync(CONFIG.webuiDir)) {
|
||||
log.warn('webui 目录不存在');
|
||||
return;
|
||||
}
|
||||
await ensureFrontendDeps();
|
||||
log.info('构建前端静态文件...');
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = spawn(
|
||||
'npm', ['run', 'build', '--', '--outDir', CONFIG.staticAdminDir, '--emptyOutDir'],
|
||||
{ cwd: CONFIG.webuiDir, stdio: 'inherit', shell: true }
|
||||
);
|
||||
proc.on('close', code => code === 0 ? resolve() : reject(new Error('前端构建失败')));
|
||||
});
|
||||
}
|
||||
|
||||
// 启动后端(开发模式:go run,无需预编译)
|
||||
async function startBackendDev() {
|
||||
if (!checkGo()) throw new Error('未找到 Go,请先安装 Go (https://go.dev/dl/)');
|
||||
log.info(`启动后端(go run)... 本地 http://127.0.0.1:${CONFIG.port} 绑定 0.0.0.0:${CONFIG.port}`);
|
||||
const proc = spawn('go', ['run', './cmd/ds2api'], {
|
||||
cwd: __dirname,
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: {
|
||||
...process.env,
|
||||
PORT: CONFIG.port,
|
||||
LOG_LEVEL: CONFIG.logLevel,
|
||||
DS2API_ADMIN_KEY: CONFIG.adminKey,
|
||||
GOPROXY: MIRRORS.goproxy,
|
||||
},
|
||||
});
|
||||
processes.push(proc);
|
||||
return proc;
|
||||
}
|
||||
|
||||
// 启动后端(生产模式:运行编译好的二进制)
|
||||
async function startBackendProd() {
|
||||
if (!binaryExists()) {
|
||||
log.warn('未找到编译产物,正在编译...');
|
||||
await buildBackend();
|
||||
}
|
||||
log.info(`启动后端(二进制)... 本地 http://127.0.0.1:${CONFIG.port} 绑定 0.0.0.0:${CONFIG.port}`);
|
||||
const proc = spawn(BINARY, [], {
|
||||
cwd: __dirname,
|
||||
stdio: 'inherit',
|
||||
shell: false,
|
||||
env: {
|
||||
...process.env,
|
||||
PORT: CONFIG.port,
|
||||
LOG_LEVEL: CONFIG.logLevel,
|
||||
DS2API_ADMIN_KEY: CONFIG.adminKey,
|
||||
},
|
||||
});
|
||||
processes.push(proc);
|
||||
return proc;
|
||||
}
|
||||
|
||||
// 启动前端开发服务器
|
||||
async function startFrontend() {
|
||||
if (!existsSync(CONFIG.webuiDir)) {
|
||||
log.warn('webui 目录不存在,跳过前端启动');
|
||||
return null;
|
||||
}
|
||||
await ensureFrontendDeps();
|
||||
log.info(`启动前端开发服务器... http://localhost:${CONFIG.frontendPort}`);
|
||||
const proc = spawn('npm', ['run', 'dev'], {
|
||||
cwd: CONFIG.webuiDir,
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
});
|
||||
processes.push(proc);
|
||||
return proc;
|
||||
}
|
||||
|
||||
// 显示状态信息
|
||||
function showStatus() {
|
||||
console.log('\n' + '─'.repeat(50));
|
||||
log.success(`后端 API: http://127.0.0.1:${CONFIG.port}`);
|
||||
log.success(`管理界面: http://127.0.0.1:${CONFIG.port}/admin`);
|
||||
log.info(`后端绑定: 0.0.0.0:${CONFIG.port} (可通过局域网 IP 访问)`);
|
||||
if (existsSync(CONFIG.webuiDir)) {
|
||||
log.success(`前端 Dev: http://localhost:${CONFIG.frontendPort}`);
|
||||
}
|
||||
console.log('─'.repeat(50));
|
||||
log.info('按 Ctrl+C 停止所有服务\n');
|
||||
}
|
||||
|
||||
// 等待进程退出
|
||||
function waitForProcesses() {
|
||||
return new Promise(resolve => {
|
||||
const check = setInterval(() => {
|
||||
const activeCount = processes.filter(proc => proc.exitCode === null && proc.signalCode === null).length;
|
||||
if (activeCount === 0) {
|
||||
clearInterval(check);
|
||||
resolve();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
// 交互式菜单
|
||||
async function showMenu() {
|
||||
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
||||
const question = (prompt) => new Promise(resolve => rl.question(prompt, resolve));
|
||||
|
||||
console.clear();
|
||||
log.title('╔══════════════════════════════════════════╗');
|
||||
log.title('║ DS2API 启动脚本 (Go) ║');
|
||||
log.title('╚══════════════════════════════════════════╝');
|
||||
|
||||
// 环境状态
|
||||
const goVersion = getGoVersion();
|
||||
const frontendDeps = checkFrontendDeps();
|
||||
const webuiBuilt = checkWebuiBuilt();
|
||||
const hasBinary = binaryExists();
|
||||
const running = getRunningStatus();
|
||||
|
||||
const ok = (v) => v ? `${colors.green}✓${colors.reset}` : `${colors.yellow}✗${colors.reset}`;
|
||||
|
||||
console.log(`\n${colors.bright}环境状态:${colors.reset}`);
|
||||
console.log(` Go: ${goVersion ? `${colors.green}${goVersion}${colors.reset}` : `${colors.red}未安装${colors.reset}`}`);
|
||||
console.log(` 前端依赖: ${frontendDeps === null ? `${colors.dim}N/A${colors.reset}` : frontendDeps ? `${colors.green}已安装${colors.reset}` : `${colors.yellow}未安装${colors.reset}`}`);
|
||||
console.log(` 前端构建: ${ok(webuiBuilt)} ${webuiBuilt ? `(${CONFIG.staticAdminDir})` : '未构建'}`);
|
||||
console.log(` 后端二进制: ${ok(hasBinary)} ${hasBinary ? BINARY : '未编译'}`);
|
||||
|
||||
console.log(`\n${colors.bright}服务状态:${colors.reset}`);
|
||||
console.log(` 后端 (:${CONFIG.port}): ${running.backend.length > 0 ? `${colors.green}运行中${colors.reset} (PID: ${running.backend.join(', ')})` : `${colors.dim}未运行${colors.reset}`}`);
|
||||
console.log(` 前端 (:${CONFIG.frontendPort}): ${running.frontend.length > 0 ? `${colors.green}运行中${colors.reset} (PID: ${running.frontend.join(', ')})` : `${colors.dim}未运行${colors.reset}`}`);
|
||||
|
||||
console.log(`\n${colors.bright}环境变量:${colors.reset}`);
|
||||
console.log(` PORT: ${colors.cyan}${CONFIG.port}${colors.reset}`);
|
||||
console.log(` LOG_LEVEL: ${colors.cyan}${CONFIG.logLevel}${colors.reset}`);
|
||||
console.log(` DS2API_ADMIN_KEY: ${colors.cyan}${CONFIG.adminKey}${colors.reset}`);
|
||||
console.log(` GOPROXY: ${colors.cyan}${MIRRORS.goproxy}${colors.reset}`);
|
||||
console.log(` NPM_REGISTRY: ${colors.cyan}${MIRRORS.npm}${colors.reset}`);
|
||||
console.log(`${colors.dim} 自定义: DS2API_ADMIN_KEY=密钥 PORT=5001 node start.mjs${colors.reset}`);
|
||||
|
||||
console.log(`
|
||||
${colors.bright}请选择操作:${colors.reset}
|
||||
|
||||
${colors.cyan}1.${colors.reset} 开发模式 (go run + 前端热重载)
|
||||
${colors.cyan}2.${colors.reset} 仅后端 (go run,无需编译)
|
||||
${colors.cyan}3.${colors.reset} 仅前端 (npm dev)
|
||||
${colors.cyan}4.${colors.reset} 生产模式 (编译后运行,前端已嵌入)
|
||||
${colors.cyan}5.${colors.reset} 编译后端 (go build)
|
||||
${colors.cyan}6.${colors.reset} 构建前端 (npm build → static/admin)
|
||||
${colors.cyan}7.${colors.reset} 安装前端依赖 (npm ci)
|
||||
${colors.red}8.${colors.reset} 停止所有服务
|
||||
${colors.cyan}0.${colors.reset} 退出
|
||||
`);
|
||||
|
||||
const choice = await question(`${colors.yellow}请输入选项 [1]: ${colors.reset}`);
|
||||
rl.close();
|
||||
|
||||
switch (choice.trim() || '1') {
|
||||
case '1':
|
||||
log.title('========== 开发模式 ==========');
|
||||
await startBackendDev();
|
||||
await new Promise(r => setTimeout(r, 1500));
|
||||
await startFrontend();
|
||||
showStatus();
|
||||
await waitForProcesses();
|
||||
break;
|
||||
|
||||
case '2':
|
||||
log.title('========== 仅后端 (go run) ==========');
|
||||
await startBackendDev();
|
||||
showStatus();
|
||||
await waitForProcesses();
|
||||
break;
|
||||
|
||||
case '3':
|
||||
log.title('========== 仅前端 ==========');
|
||||
await startFrontend();
|
||||
showStatus();
|
||||
await waitForProcesses();
|
||||
break;
|
||||
|
||||
case '4':
|
||||
log.title('========== 生产模式 ==========');
|
||||
await startBackendProd();
|
||||
showStatus();
|
||||
await waitForProcesses();
|
||||
break;
|
||||
|
||||
case '5':
|
||||
log.title('========== 编译后端 ==========');
|
||||
await buildBackend();
|
||||
log.success(`编译完成:${BINARY}`);
|
||||
break;
|
||||
|
||||
case '6':
|
||||
log.title('========== 构建前端 ==========');
|
||||
await buildWebui();
|
||||
log.success('前端构建完成!');
|
||||
break;
|
||||
|
||||
case '7':
|
||||
log.title('========== 安装前端依赖 ==========');
|
||||
await installFrontendDeps();
|
||||
log.success('前端依赖安装完成!');
|
||||
break;
|
||||
|
||||
case '8':
|
||||
await stopServices();
|
||||
break;
|
||||
|
||||
case '0':
|
||||
log.info('再见!');
|
||||
process.exit(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
log.warn('无效选项');
|
||||
await showMenu();
|
||||
}
|
||||
}
|
||||
|
||||
// 命令行参数处理
|
||||
async function main() {
|
||||
const cmd = process.argv[2];
|
||||
|
||||
if (!checkGo() && !['install', 'webui', 'stop', 'status', 'help', '-h', '--help'].includes(cmd)) {
|
||||
log.error('未找到 Go,请先安装 Go: https://go.dev/dl/');
|
||||
if (!cmd) {
|
||||
// 无 Go 时仍允许进入菜单(可以只操作前端)
|
||||
} else {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case 'dev':
|
||||
log.title('========== 开发模式 ==========');
|
||||
await startBackendDev();
|
||||
await new Promise(r => setTimeout(r, 1500));
|
||||
await startFrontend();
|
||||
showStatus();
|
||||
await waitForProcesses();
|
||||
break;
|
||||
|
||||
case 'prod':
|
||||
log.title('========== 生产模式 ==========');
|
||||
await startBackendProd();
|
||||
showStatus();
|
||||
await waitForProcesses();
|
||||
break;
|
||||
|
||||
case 'build':
|
||||
await buildBackend();
|
||||
log.success(`编译完成:${BINARY}`);
|
||||
break;
|
||||
|
||||
case 'webui':
|
||||
await buildWebui();
|
||||
log.success('前端构建完成!');
|
||||
break;
|
||||
|
||||
case 'install':
|
||||
await installFrontendDeps();
|
||||
log.success('前端依赖安装完成!');
|
||||
break;
|
||||
|
||||
case 'stop':
|
||||
await stopServices();
|
||||
break;
|
||||
|
||||
case 'status': {
|
||||
const status = getRunningStatus();
|
||||
const goVer = getGoVersion();
|
||||
console.log(`\n${colors.bright}环境:${colors.reset}`);
|
||||
console.log(` Go: ${goVer || `${colors.red}未安装${colors.reset}`}`);
|
||||
console.log(`\n${colors.bright}服务状态:${colors.reset}`);
|
||||
console.log(` 后端 (:${CONFIG.port}): ${status.backend.length > 0 ? `${colors.green}运行中${colors.reset} (PID: ${status.backend.join(', ')})` : `${colors.dim}未运行${colors.reset}`}`);
|
||||
console.log(` 前端 (:${CONFIG.frontendPort}): ${status.frontend.length > 0 ? `${colors.green}运行中${colors.reset} (PID: ${status.frontend.join(', ')})` : `${colors.dim}未运行${colors.reset}`}\n`);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'help':
|
||||
case '-h':
|
||||
case '--help':
|
||||
console.log(`
|
||||
${colors.bright}DS2API 启动脚本 (Go)${colors.reset}
|
||||
|
||||
${colors.cyan}使用方法:${colors.reset}
|
||||
node start.mjs 显示交互式菜单
|
||||
node start.mjs dev 开发模式 (go run + 前端热重载)
|
||||
node start.mjs prod 生产模式 (编译产物,前端已嵌入)
|
||||
node start.mjs build 编译后端二进制 (go build)
|
||||
node start.mjs webui 构建前端静态文件
|
||||
node start.mjs install 安装前端依赖 (npm ci)
|
||||
node start.mjs stop 停止所有服务
|
||||
node start.mjs status 查看服务状态
|
||||
|
||||
${colors.cyan}常用环境变量:${colors.reset}
|
||||
PORT 后端端口 (默认: 5001)
|
||||
LOG_LEVEL 日志级别: DEBUG|INFO|WARN|ERROR (默认: INFO)
|
||||
DS2API_ADMIN_KEY 管理员密钥 (默认: admin)
|
||||
DS2API_CONFIG_PATH 配置文件路径 (默认: config.json)
|
||||
GOPROXY Go 模块代理 (默认: https://goproxy.cn,direct)
|
||||
NPM_REGISTRY npm 镜像源 (默认: https://registry.npmmirror.com)
|
||||
|
||||
${colors.cyan}示例:${colors.reset}
|
||||
DS2API_ADMIN_KEY=mykey PORT=8080 node start.mjs dev
|
||||
GOPROXY=off NPM_REGISTRY=https://registry.npmjs.org node start.mjs dev
|
||||
`);
|
||||
break;
|
||||
|
||||
default:
|
||||
await showMenu();
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(e => {
|
||||
log.error(e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
{
|
||||
"version": 2,
|
||||
"buildCommand": "npm ci --prefix webui && npm run build --prefix webui",
|
||||
"outputDirectory": "static",
|
||||
"functions": {
|
||||
"api/chat-stream.js": {
|
||||
"maxDuration": 300
|
||||
},
|
||||
"api/index.go": {
|
||||
"maxDuration": 300
|
||||
}
|
||||
},
|
||||
"rewrites": [
|
||||
{
|
||||
"source": "/v1/chat/completions",
|
||||
"has": [
|
||||
{
|
||||
"type": "query",
|
||||
"key": "__go"
|
||||
}
|
||||
],
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/v1/chat/completions",
|
||||
"destination": "/api/chat-stream"
|
||||
},
|
||||
{
|
||||
"source": "/admin/login",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/verify",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/config",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/config/(.*)",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/settings",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/settings/(.*)",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/keys(.*)",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/accounts(.*)",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/queue/status",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/import",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/test",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/vercel/(.*)",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/export",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin/version",
|
||||
"destination": "/api/index"
|
||||
},
|
||||
{
|
||||
"source": "/admin",
|
||||
"destination": "/admin/index.html"
|
||||
},
|
||||
{
|
||||
"source": "/admin/assets/(.*)",
|
||||
"destination": "/admin/assets/$1"
|
||||
},
|
||||
{
|
||||
"source": "/admin/(.*)",
|
||||
"destination": "/admin/index.html"
|
||||
},
|
||||
{
|
||||
"source": "/(.*)",
|
||||
"destination": "/api/index"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"source": "/admin/assets/(.*)",
|
||||
"headers": [
|
||||
{
|
||||
"key": "Cache-Control",
|
||||
"value": "public, max-age=31536000, immutable"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": "/admin/(.*)",
|
||||
"headers": [
|
||||
{
|
||||
"key": "Cache-Control",
|
||||
"value": "no-store, must-revalidate"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
# yaml-language-server: $schema=https://schema.zeabur.app/template.json
|
||||
apiVersion: zeabur.com/v1
|
||||
kind: Template
|
||||
metadata:
|
||||
name: DS2API
|
||||
spec:
|
||||
description: DeepSeek Web 对话转 OpenAI/Claude/Gemini 兼容 API(Go 实现,含 WebUI)
|
||||
tags:
|
||||
- DeepSeek
|
||||
- API
|
||||
- Go
|
||||
readme: |-
|
||||
# DS2API (Zeabur)
|
||||
|
||||
## Runtime baseline
|
||||
- Go: 1.26
|
||||
|
||||
## After deployment
|
||||
- Admin panel: `/admin`
|
||||
- Health check: `/healthz`
|
||||
- Config is persisted at `/data/config.json` (mounted volume)
|
||||
- `BUILD_VERSION` is optional; when omitted, Docker build falls back to the repo `VERSION` file automatically
|
||||
|
||||
## First-time setup
|
||||
1. Open your service URL, then visit `/admin`
|
||||
2. Login with `DS2API_ADMIN_KEY` (shown in Zeabur env/instructions)
|
||||
3. Import / edit config in Admin UI (saved to `/data/config.json`)
|
||||
|
||||
services:
|
||||
- name: ds2api
|
||||
template: GIT
|
||||
spec:
|
||||
source:
|
||||
source: GITHUB
|
||||
repo: 1139136822
|
||||
branch: main
|
||||
rootDirectory: /
|
||||
ports:
|
||||
- id: web
|
||||
port: 5001
|
||||
type: HTTP
|
||||
volumes:
|
||||
- id: data
|
||||
dir: /data
|
||||
env:
|
||||
PORT:
|
||||
default: "5001"
|
||||
LOG_LEVEL:
|
||||
default: "INFO"
|
||||
DS2API_ADMIN_KEY:
|
||||
default: ${PASSWORD}
|
||||
expose: true
|
||||
DS2API_CONFIG_PATH:
|
||||
default: /data/config.json
|
||||
instructions:
|
||||
- title: Admin panel
|
||||
content: Visit `/admin` on your service URL.
|
||||
- title: DS2API admin key
|
||||
content: ${DS2API_ADMIN_KEY}
|
||||
healthCheck:
|
||||
type: HTTP
|
||||
port: web
|
||||
http:
|
||||
path: /healthz
|
||||
Reference in New Issue
Block a user