diff --git a/admin-panel/src/pages/Downloads.tsx b/admin-panel/src/pages/Downloads.tsx
index e8bdf78..35efe2a 100644
--- a/admin-panel/src/pages/Downloads.tsx
+++ b/admin-panel/src/pages/Downloads.tsx
@@ -152,6 +152,9 @@ export default function Downloads() {
{building ? '构建中...' : '构建选中平台'}
+
+ 当前需在本地或 CI 中构建客户端,将产物(如 FunMC-版本号-windows-x64.exe)放入服务器 downloads 目录(由环境变量 DOWNLOADS_DIR 指定,默认 /opt/funmc/downloads)后,下载页与下表才会提供下载。
+
{Object.entries(platformInfo).map(([key, info]) => (
diff --git a/install.sh b/install.sh
index 9c3a87e..ac353d8 100644
--- a/install.sh
+++ b/install.sh
@@ -99,19 +99,23 @@ install_nodejs() {
fi
}
-# 配置数据库
+# 配置数据库(固定密码 12345678,安装时覆盖旧数据)
setup_database() {
echo -e "${YELLOW}[4/7] 配置数据库...${NC}"
systemctl enable postgresql
systemctl start postgresql
- # 生成随机密码
- DB_PASSWORD=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 24)
+ # 固定数据库密码,安装时覆盖旧库与用户
+ DB_PASSWORD="12345678"
- # 创建数据库和用户
- sudo -u postgres psql -c "CREATE USER funmc WITH PASSWORD '$DB_PASSWORD';" 2>/dev/null || true
- sudo -u postgres psql -c "CREATE DATABASE funmc OWNER funmc;" 2>/dev/null || true
+ # 先删除旧数据库和用户(覆盖旧数据)
+ sudo -u postgres psql -c "DROP DATABASE IF EXISTS funmc;" 2>/dev/null || true
+ sudo -u postgres psql -c "DROP USER IF EXISTS funmc;" 2>/dev/null || true
+
+ # 创建用户和数据库
+ sudo -u postgres psql -c "CREATE USER funmc WITH PASSWORD '$DB_PASSWORD';"
+ sudo -u postgres psql -c "CREATE DATABASE funmc OWNER funmc;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE funmc TO funmc;"
# 配置 pg_hba.conf
@@ -122,7 +126,7 @@ setup_database() {
systemctl reload postgresql
fi
- echo -e "${GREEN}✓ 数据库配置完成${NC}"
+ echo -e "${GREEN}✓ 数据库配置完成(密码已设为 12345678,已覆盖旧数据)${NC}"
echo "$DB_PASSWORD" > /tmp/funmc_db_password
}
@@ -130,8 +134,8 @@ setup_database() {
build_funmc() {
echo -e "${YELLOW}[5/7] 编译 FunMC...${NC}"
- # 创建目录
- mkdir -p $INSTALL_DIR $CONFIG_DIR $DATA_DIR $LOG_DIR
+ # 创建目录(含客户端下载目录)
+ mkdir -p $INSTALL_DIR $INSTALL_DIR/downloads $CONFIG_DIR $DATA_DIR $LOG_DIR
# 克隆或更新代码
if [ -d "$INSTALL_DIR/src" ]; then
@@ -192,6 +196,7 @@ ADMIN_PASSWORD=${ADMIN_PASSWORD}
# 客户端下载
CLIENT_DOWNLOAD_ENABLED=true
CLIENT_VERSION=${FUNMC_VERSION}
+DOWNLOADS_DIR=$INSTALL_DIR/downloads
EOF
# 创建中继配置
diff --git a/server/src/api/download.rs b/server/src/api/download.rs
index 6c42497..b1ff959 100644
--- a/server/src/api/download.rs
+++ b/server/src/api/download.rs
@@ -256,11 +256,31 @@ pub async fn list_builds() -> Json
> {
Json(builds)
}
-pub async fn download_file(Path(filename): Path) -> Result {
+pub async fn download_file(Path(filename): Path) -> Result {
let downloads_dir = std::env::var("DOWNLOADS_DIR").unwrap_or_else(|_| "./downloads".to_string());
let file_path = std::path::Path::new(&downloads_dir).join(&filename);
- let file = File::open(&file_path).await.map_err(|_| StatusCode::NOT_FOUND)?;
+ let file = match File::open(&file_path).await {
+ Ok(f) => f,
+ Err(_) => {
+ let escaped = filename.replace('&', "&").replace('<', "<").replace('>', ">").replace('"', """);
+ let html = format!(r##"
+
+文件不存在
+
+文件不存在
+未找到 {}。
+可能原因:该版本尚未构建或未上传到服务器。请联系管理员,或将构建好的客户端放入服务器的 downloads 目录后重试。
+返回下载页
+
+"##, escaped);
+ return Err(Response::builder()
+ .status(StatusCode::NOT_FOUND)
+ .header(header::CONTENT_TYPE, "text/html; charset=utf-8")
+ .body(Body::from(html))
+ .unwrap());
+ }
+ };
let stream = ReaderStream::new(file);
let body = Body::from_stream(stream);