mirror of
https://github.com/MatrixSeven/file-transfer-go.git
synced 2026-02-04 03:25:03 +08:00
feat: 删除不再使用的构建脚本和模型文件
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =============================================================================
|
||||
# 简化版 SSG 构建脚本
|
||||
# 专注于 API 路由的处理和静态导出
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# 颜色定义
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 配置
|
||||
PROJECT_ROOT="$(pwd)"
|
||||
API_DIR="$PROJECT_ROOT/src/app/api"
|
||||
TEMP_API_DIR="/tmp/nextjs-api-$(date +%s)"
|
||||
|
||||
echo -e "${GREEN}🚀 开始 SSG 静态导出构建...${NC}"
|
||||
|
||||
# 错误处理函数
|
||||
cleanup_on_error() {
|
||||
echo -e "${RED}❌ 构建失败,正在恢复文件...${NC}"
|
||||
if [ -d "$TEMP_API_DIR" ]; then
|
||||
if [ -d "$TEMP_API_DIR/api" ]; then
|
||||
mv "$TEMP_API_DIR/api" "$API_DIR" 2>/dev/null || true
|
||||
echo -e "${YELLOW}📂 已恢复 API 目录${NC}"
|
||||
fi
|
||||
rm -rf "$TEMP_API_DIR"
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 设置错误处理
|
||||
trap cleanup_on_error ERR INT TERM
|
||||
|
||||
# 步骤 1: 备份 API 路由
|
||||
if [ -d "$API_DIR" ]; then
|
||||
echo -e "${YELLOW}📦 备份 API 路由...${NC}"
|
||||
mkdir -p "$TEMP_API_DIR"
|
||||
mv "$API_DIR" "$TEMP_API_DIR/"
|
||||
echo "✅ API 路由已备份到临时目录"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ API 目录不存在,跳过备份${NC}"
|
||||
fi
|
||||
|
||||
# 步骤 2: 清理构建文件
|
||||
echo -e "${YELLOW}🧹 清理之前的构建...${NC}"
|
||||
rm -rf .next out
|
||||
|
||||
# 步骤 3: 执行静态构建
|
||||
echo -e "${YELLOW}🔨 执行静态导出构建...${NC}"
|
||||
NEXT_EXPORT=true yarn build
|
||||
|
||||
# 步骤 4: 验证构建结果
|
||||
if [ -d "out" ] && [ -f "out/index.html" ]; then
|
||||
echo -e "${GREEN}✅ 静态导出构建成功!${NC}"
|
||||
|
||||
# 显示构建统计
|
||||
file_count=$(find out -type f | wc -l)
|
||||
dir_size=$(du -sh out | cut -f1)
|
||||
echo "📊 构建统计:"
|
||||
echo " - 文件数量: $file_count"
|
||||
echo " - 总大小: $dir_size"
|
||||
else
|
||||
echo -e "${RED}❌ 构建验证失败${NC}"
|
||||
cleanup_on_error
|
||||
fi
|
||||
|
||||
# 步骤 5: 恢复 API 路由
|
||||
if [ -d "$TEMP_API_DIR/api" ]; then
|
||||
echo -e "${YELLOW}🔄 恢复 API 路由...${NC}"
|
||||
mv "$TEMP_API_DIR/api" "$API_DIR"
|
||||
echo "✅ API 路由已恢复"
|
||||
fi
|
||||
|
||||
# 步骤 6: 清理临时文件
|
||||
rm -rf "$TEMP_API_DIR"
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}🎉 SSG 构建完成!${NC}"
|
||||
echo -e "${GREEN}📁 静态文件位于: ./out/${NC}"
|
||||
echo -e "${GREEN}🚀 部署命令: npx serve out${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}💡 提示: 静态版本会直接连接到 Go 后端 (localhost:8080)${NC}"
|
||||
1
go.mod
1
go.mod
@@ -5,6 +5,5 @@ go 1.21
|
||||
require (
|
||||
github.com/go-chi/chi/v5 v5.0.10
|
||||
github.com/go-chi/cors v1.2.1
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
)
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// WebRTCOffer WebRTC offer 结构
|
||||
type WebRTCOffer struct {
|
||||
SDP string `json:"sdp"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// WebRTCAnswer WebRTC answer 结构
|
||||
type WebRTCAnswer struct {
|
||||
SDP string `json:"sdp"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// WebRTCICECandidate ICE candidate 结构
|
||||
type WebRTCICECandidate struct {
|
||||
Candidate string `json:"candidate"`
|
||||
SDPMLineIndex int `json:"sdpMLineIndex"`
|
||||
SDPMid string `json:"sdpMid"`
|
||||
}
|
||||
|
||||
// VideoMessage 视频消息结构
|
||||
type VideoMessage struct {
|
||||
Type string `json:"type"`
|
||||
Payload interface{} `json:"payload"`
|
||||
}
|
||||
|
||||
// ClientInfo 客户端连接信息
|
||||
type ClientInfo struct {
|
||||
ID string `json:"id"` // 客户端唯一标识
|
||||
Role string `json:"role"` // sender 或 receiver
|
||||
Connection *websocket.Conn `json:"-"` // WebSocket连接(不序列化)
|
||||
JoinedAt time.Time `json:"joined_at"` // 加入时间
|
||||
UserAgent string `json:"user_agent"` // 用户代理
|
||||
}
|
||||
|
||||
// RoomStatus 房间状态信息
|
||||
type RoomStatus struct {
|
||||
Code string `json:"code"`
|
||||
SenderOnline bool `json:"sender_online"`
|
||||
ReceiverOnline bool `json:"receiver_online"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// ErrorResponse 错误响应结构
|
||||
type ErrorResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
Code string `json:"code,omitempty"`
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 嵌入静态文件
|
||||
//
|
||||
//go:embed all:static
|
||||
var StaticFiles embed.FS
|
||||
|
||||
// StaticFileServer 创建静态文件服务器
|
||||
func StaticFileServer() http.Handler {
|
||||
// 获取嵌入的文件系统
|
||||
staticFS, err := fs.Sub(StaticFiles, "static")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return http.FileServer(http.FS(staticFS))
|
||||
}
|
||||
|
||||
// FrontendFileServer 创建前端文件服务器
|
||||
func FrontendFileServer() http.Handler {
|
||||
return &frontendHandler{}
|
||||
}
|
||||
|
||||
// frontendHandler 处理前端文件请求,支持 SPA 路由
|
||||
type frontendHandler struct{}
|
||||
|
||||
func (h *frontendHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// 返回一个简单的占位页面
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>文件传输</title>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<h1>文件传输服务</h1>
|
||||
<p>前端文件未嵌入,请先构建前端项目。</p>
|
||||
<p>运行以下命令构建前端:</p>
|
||||
<pre>cd chuan-next && yarn build:ssg</pre>
|
||||
</body>
|
||||
</html>
|
||||
`))
|
||||
}
|
||||
Reference in New Issue
Block a user