feat: 添加同步进度显示和中文界面支持
refactor: 重构同步引擎以支持进度跟踪 style: 更新前端界面为中文 docs: 更新README为中文文档
This commit is contained in:
181
README.md
181
README.md
@@ -1,60 +1,161 @@
|
||||
# GitM - Gitea Repository Sync Tool
|
||||
# GitM - Gitea 仓库镜像同步工具
|
||||
|
||||
Cross-platform tool to synchronize all repositories from multiple Gitea servers to local storage.
|
||||
将多个 Gitea 服务器的仓库自动镜像同步到本地存储,支持定时同步和手动同步。
|
||||
|
||||
## Features
|
||||
## 功能特性
|
||||
|
||||
- Single binary deployment (frontend embedded)
|
||||
- Web UI for management (Vue 3 + Element Plus)
|
||||
- SQLite database
|
||||
- JWT authentication
|
||||
- Scheduled and manual sync
|
||||
- Cross-platform (Windows, Linux)
|
||||
- **单文件部署** - 前端内嵌到 Go 二进制,无需额外依赖
|
||||
- **Web 管理界面** - Vue 3 + Element Plus,中文界面
|
||||
- **多服务器管理** - 同时管理多个 Gitea 服务器
|
||||
- **仓库自动发现** - 一键发现服务器上的所有仓库
|
||||
- **镜像同步** - 使用 `git clone --mirror` 完整镜像,支持 Token 认证
|
||||
- **实时进度** - 同步过程实时展示当前克隆/同步的仓库及进度
|
||||
- **定时同步** - 可配置每个服务器的自动同步间隔
|
||||
- **SQLite 存储** - 轻量级数据库,无需额外安装
|
||||
|
||||
## Build
|
||||
## 快速开始
|
||||
|
||||
### 前置要求
|
||||
|
||||
- Go 1.21+(需要 CGO 支持 SQLite)
|
||||
- GCC(Windows 下需安装 MinGW-w64)
|
||||
- Node.js 18+(仅开发时需要)
|
||||
|
||||
### 安装与运行
|
||||
|
||||
```bash
|
||||
# Build binary with embedded frontend
|
||||
go build -o bin/gitm .
|
||||
# 1. 初始化(设置管理员密码)
|
||||
$env:CGO_ENABLED="1"; go run main.go --init
|
||||
|
||||
# Or with CGO for SQLite support
|
||||
CGO_ENABLED=1 go build -o bin/gitm .
|
||||
# 2. 启动服务(默认监听 :9000)
|
||||
$env:CGO_ENABLED="1"; go run main.go
|
||||
```
|
||||
|
||||
## Run
|
||||
启动后浏览器访问 `http://localhost:9000`
|
||||
|
||||
### 使用流程
|
||||
|
||||
1. **登录** - 使用初始化时设置的密码登录
|
||||
2. **添加服务器** - 填写 Gitea 服务器地址和 API Token
|
||||
3. **测试连接** - 验证服务器和 Token 是否可用
|
||||
4. **发现仓库** - 扫描服务器上的所有仓库
|
||||
5. **同步** - 将仓库镜像克隆到本地,支持手动和定时同步
|
||||
|
||||
## 打包部署
|
||||
|
||||
```bash
|
||||
# First-time initialization (set admin password)
|
||||
./bin/gitm --init
|
||||
# 构建前端
|
||||
cd web
|
||||
npm install
|
||||
npm run build
|
||||
cd ..
|
||||
|
||||
# Start server (default :9000)
|
||||
./bin/gitm
|
||||
|
||||
# Custom address
|
||||
./bin/gitm --addr :9090
|
||||
|
||||
# Custom data directory
|
||||
./bin/gitm --data /path/to/data
|
||||
# 打包为单文件 exe
|
||||
$env:CGO_ENABLED="1"; go build -o gitm.exe
|
||||
```
|
||||
|
||||
## Usage
|
||||
打包后的 `gitm.exe` 包含前后端,直接运行即可。
|
||||
|
||||
1. Initialize: `./bin/gitm --init` -- sets admin password
|
||||
2. Start: `./bin/gitm` -- starts web server
|
||||
3. Open browser to `http://localhost:9000`
|
||||
4. Login and add Gitea servers
|
||||
5. Discover repos and sync
|
||||
|
||||
## Development
|
||||
### 运行
|
||||
|
||||
```bash
|
||||
# Frontend dev server
|
||||
cd web && npm install && npm run dev
|
||||
# 首次初始化
|
||||
.\gitm.exe --init
|
||||
|
||||
# Backend
|
||||
go run main.go
|
||||
# 启动服务
|
||||
.\gitm.exe
|
||||
|
||||
# Run tests
|
||||
go test ./internal/gitea/... -v
|
||||
CGO_ENABLED=1 go test ./internal/database/... -v
|
||||
# 指定监听地址
|
||||
.\gitm.exe --addr :8080
|
||||
|
||||
# 指定数据目录
|
||||
.\gitm.exe --data /path/to/data
|
||||
```
|
||||
|
||||
## 开发模式
|
||||
|
||||
前后端分别启动,支持热更新:
|
||||
|
||||
```bash
|
||||
# 终端 1:启动后端(默认 :9000)
|
||||
$env:CGO_ENABLED="1"; go run main.go
|
||||
|
||||
# 终端 2:启动前端开发服务器(:5173,自动代理 API 到 :9000)
|
||||
cd web
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
开发时访问 `http://localhost:5173`
|
||||
|
||||
## 命令行参数
|
||||
|
||||
| 参数 | 说明 | 默认值 |
|
||||
|------|------|--------|
|
||||
| `--init` | 初始化数据库并设置管理员密码 | - |
|
||||
| `--addr` | 监听地址 | `:9000` |
|
||||
| `--data` | 数据存储目录 | `./data` |
|
||||
|
||||
## 系统设置
|
||||
|
||||
通过 Web 界面可配置:
|
||||
|
||||
- **管理员密码** - 修改登录密码
|
||||
- **监听地址** - 修改服务端口(需重启)
|
||||
- **仓库目录** - 仓库镜像存储路径
|
||||
- **最大并发数** - 同步时的并发数量(1-10)
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
├── main.go # 程序入口
|
||||
├── internal/
|
||||
│ ├── config/ # 配置管理
|
||||
│ ├── database/ # SQLite 数据库操作
|
||||
│ ├── gitea/ # Gitea API 客户端
|
||||
│ ├── handler/ # HTTP 请求处理
|
||||
│ ├── middleware/ # JWT 认证中间件
|
||||
│ ├── models/ # 数据模型
|
||||
│ └── sync/ # 同步引擎与调度器
|
||||
├── web/ # Vue 3 前端
|
||||
│ ├── src/
|
||||
│ │ ├── api/ # API 请求封装
|
||||
│ │ ├── views/ # 页面组件
|
||||
│ │ ├── stores/ # Pinia 状态管理
|
||||
│ │ └── router/ # 路由配置
|
||||
│ └── vite.config.ts
|
||||
└── data/ # 运行时数据(自动创建)
|
||||
├── gitm.db # SQLite 数据库
|
||||
└── repos/ # 镜像仓库存储
|
||||
```
|
||||
|
||||
## API 接口
|
||||
|
||||
| 方法 | 路径 | 说明 |
|
||||
|------|------|------|
|
||||
| POST | `/api/login` | 登录 |
|
||||
| POST | `/api/init` | 初始化密码 |
|
||||
| GET | `/api/settings` | 获取系统设置 |
|
||||
| PUT | `/api/settings` | 更新系统设置 |
|
||||
| GET | `/api/servers` | 服务器列表 |
|
||||
| POST | `/api/servers` | 添加服务器 |
|
||||
| PUT | `/api/servers/:id` | 更新服务器 |
|
||||
| DELETE | `/api/servers/:id` | 删除服务器 |
|
||||
| POST | `/api/servers/test` | 测试连接 |
|
||||
| GET | `/api/servers/:id/repos` | 仓库列表 |
|
||||
| POST | `/api/servers/:id/discover` | 发现仓库 |
|
||||
| POST | `/api/servers/:id/sync` | 同步服务器 |
|
||||
| GET | `/api/servers/:id/sync/status` | 同步进度 |
|
||||
| POST | `/api/sync/all` | 同步全部服务器 |
|
||||
| GET | `/api/sync/logs` | 同步日志 |
|
||||
| GET | `/api/sync/stats` | 同步统计 |
|
||||
|
||||
## 技术栈
|
||||
|
||||
**后端:** Go / Gin / SQLite / JWT
|
||||
|
||||
**前端:** Vue 3 / TypeScript / Element Plus / Vite / Pinia
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
Reference in New Issue
Block a user