fix: Update API base URL to include versioning

- Modify the base URL in the ApiClient constructor to append '/api/v1', ensuring compatibility with versioned API endpoints.
This commit is contained in:
2026-02-26 22:27:25 +08:00
parent 0aa51cc932
commit 3f313283df
3 changed files with 198 additions and 1 deletions

View File

@@ -5,7 +5,7 @@ export class ApiClient {
constructor(baseUrl: string) {
this.http = axios.create({
baseURL: baseUrl.replace(/\/$/, '') + '/api',
baseURL: baseUrl.replace(/\/$/, '') + '/api/v1',
timeout: 10000,
});
}

136
docs/BUILD-CLIENT.md Normal file
View File

@@ -0,0 +1,136 @@
# 各平台客户端构建并放入下载目录
下载页提供的文件名由服务端配置 `CLIENT_VERSION` 决定(默认 `0.1.0`),格式为:
- `FunMC-<版本>-windows-x64.exe`
- `FunMC-<版本>-macos-arm64.dmg` / `FunMC-<版本>-macos-x64.dmg`
- `FunMC-<版本>-linux-x64.AppImage`
- `FunMC-<版本>-android.apk`
构建产物需**复制到服务器的下载目录**并**按上述文件名命名**,下载页才会显示「下载」按钮。
服务器下载目录:`/opt/funmc/downloads`(或环境变量 `DOWNLOADS_DIR`)。
---
## 1. 版本号一致
构建前请确认与服务器一致:
- 查看服务器:`grep CLIENT_VERSION /etc/funmc/server.env`(例如 `0.1.0`
- 下文中的 `VERSION` 请替换为该版本号。
---
## 2. Linux可在服务器本机执行
**在服务器或任意 Linux 机器上:**
```bash
cd /opt/funmc/src/client # 或你的项目 client 目录
npm install --registry https://registry.npmjs.org/
npm run dist:linux
```
产物在 `client/release/` 下,例如:
- `FunConnect-1.1.0-Linux-x64.AppImage`
复制并重命名为下载页期望的文件名后放入下载目录:
```bash
VERSION=0.1.0 # 与 CLIENT_VERSION 一致
cp release/FunConnect-*-Linux-x64.AppImage /opt/funmc/downloads/FunMC-${VERSION}-linux-x64.AppImage
```
---
## 3. Windows
**在 Windows 本机:**
```cmd
cd client
npm install
npm run dist:win
```
产物在 `client\release\`,例如:
- `FunConnect-1.1.0-Win-x64.exe`(或带 nsis 的安装包)
上传到服务器后重命名并放入下载目录(在服务器上执行,或本机重命名后上传):
```bash
# 在服务器上(假设已上传为 FunConnect-1.1.0-Win-x64.exe
VERSION=0.1.0
mv /path/to/FunConnect-1.1.0-Win-x64.exe /opt/funmc/downloads/FunMC-${VERSION}-windows-x64.exe
```
或用 SCP 从本机直接放到服务器并命名PowerShell 示例):
```powershell
scp client\release\FunConnect-1.1.0-Win-x64.exe root@你的服务器IP:/opt/funmc/downloads/FunMC-0.1.0-windows-x64.exe
```
---
## 4. macOS
**在 Mac 本机:**
```bash
cd client
npm install
npm run dist:mac
```
产物在 `client/release/`,例如:
- Apple Silicon: `FunConnect-1.1.0-Mac-arm64.dmg`
- Intel: `FunConnect-1.1.0-Mac-x64.dmg`
上传到服务器并重命名(在服务器上):
```bash
VERSION=0.1.0
mv /path/to/FunConnect-1.1.0-Mac-arm64.dmg /opt/funmc/downloads/FunMC-${VERSION}-macos-arm64.dmg
mv /path/to/FunConnect-1.1.0-Mac-x64.dmg /opt/funmc/downloads/FunMC-${VERSION}-macos-x64.dmg
```
---
## 5. Android
若项目中有 Android 构建(如 `mobile/` 或 Android 子工程),构建出 `.apk` 后,上传到服务器并命名为:
```bash
VERSION=0.1.0
cp /path/to/your.apk /opt/funmc/downloads/FunMC-${VERSION}-android.apk
```
---
## 6. 一键复制脚本示例(在服务器上使用)
在服务器上,若已把各平台构建产物上传到某目录(或本机刚构建好 Linux 版),可统一复制并重命名:
```bash
# 请先确认版本号与 /etc/funmc/server.env 中 CLIENT_VERSION 一致
VERSION=0.1.0
DOWNLOADS=/opt/funmc/downloads
# Linux本机刚构建时
cp -v /opt/funmc/src/client/release/FunConnect-*-Linux-x64.AppImage "$DOWNLOADS/FunMC-${VERSION}-linux-x64.AppImage" 2>/dev/null || true
# 若 Windows/macOS 已上传到 /opt/funmc/uploads/ 等目录,可类似:
# cp -v /opt/funmc/uploads/FunConnect-*-Win-x64.exe "$DOWNLOADS/FunMC-${VERSION}-windows-x64.exe" 2>/dev/null || true
# cp -v /opt/funmc/uploads/FunConnect-*-Mac-arm64.dmg "$DOWNLOADS/FunMC-${VERSION}-macos-arm64.dmg" 2>/dev/null || true
# cp -v /opt/funmc/uploads/FunConnect-*-Mac-x64.dmg "$DOWNLOADS/FunMC-${VERSION}-macos-x64.dmg" 2>/dev/null || true
```
---
## 7. 验证
- 在服务器上:`ls -la /opt/funmc/downloads`
- 浏览器打开:`http://你的服务器:3000/download`,有文件的平台会显示「下载」按钮,没有的显示「暂无」。

View File

@@ -0,0 +1,61 @@
#!/bin/bash
# 将 client/release 下的构建产物复制到服务器下载目录并命名为 FunMC-<版本>-<平台>.<后缀>
# 用法:
# bash scripts/copy-client-to-downloads.sh [版本号]
# bash scripts/copy-client-to-downloads.sh # 版本号从 /etc/funmc/server.env 的 CLIENT_VERSION 读取
# 需在项目根目录或指定 CLIENT_DIR、DOWNLOADS_DIR 运行。
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
CLIENT_DIR="${CLIENT_DIR:-$REPO_ROOT/client}"
DOWNLOADS_DIR="${DOWNLOADS_DIR:-/opt/funmc/downloads}"
if [ -n "$1" ]; then
VERSION="$1"
elif [ -f /etc/funmc/server.env ]; then
VERSION=$(grep -E '^CLIENT_VERSION=' /etc/funmc/server.env | cut -d= -f2)
fi
if [ -z "$VERSION" ]; then
echo "用法: $0 <版本号> 或确保 /etc/funmc/server.env 中有 CLIENT_VERSION"
echo "示例: $0 0.1.0"
exit 1
fi
RELEASE="$CLIENT_DIR/release"
if [ ! -d "$RELEASE" ]; then
echo "未找到 $RELEASE,请先在 client 目录执行 npm run dist:linux 等构建"
exit 1
fi
mkdir -p "$DOWNLOADS_DIR"
# 复制并重命名Electron 产物: FunConnect-<package.json版本>-<平台>-<arch>.<ext>
copied=0
for f in "$RELEASE"/FunConnect-*-Linux-x64.AppImage; do
[ -f "$f" ] || continue
cp -v "$f" "$DOWNLOADS_DIR/FunMC-${VERSION}-linux-x64.AppImage"
copied=$((copied+1))
done
for f in "$RELEASE"/FunConnect-*-Win-x64.exe; do
[ -f "$f" ] || continue
cp -v "$f" "$DOWNLOADS_DIR/FunMC-${VERSION}-windows-x64.exe"
copied=$((copied+1))
done
for f in "$RELEASE"/FunConnect-*-Mac-arm64.dmg; do
[ -f "$f" ] || continue
cp -v "$f" "$DOWNLOADS_DIR/FunMC-${VERSION}-macos-arm64.dmg"
copied=$((copied+1))
done
for f in "$RELEASE"/FunConnect-*-Mac-x64.dmg; do
[ -f "$f" ] || continue
cp -v "$f" "$DOWNLOADS_DIR/FunMC-${VERSION}-macos-x64.dmg"
copied=$((copied+1))
done
if [ $copied -eq 0 ]; then
echo "未在 $RELEASE 中找到可复制的 FunConnect-* 文件,请先构建客户端"
exit 1
fi
echo "已复制 $copied 个文件到 $DOWNLOADS_DIR(版本 $VERSION"