Skip to content

Commit 08b16c8

Browse files
authored
Merge pull request #9 from zy84338719/feature/login-gates
feat(admin): add transfer log tab and polish storage ui
2 parents def22f9 + 68407df commit 08b16c8

69 files changed

Lines changed: 4531 additions & 2212 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
# Copilot / AI Agent Instructions for FileCodeBox
2+
3+
Short, actionable guidance so an AI agent can be productive immediately in this repo.
4+
5+
1) Big picture
6+
- Layered architecture: `routes -> handlers -> services -> repository -> database/storage`.
7+
- Key directories: `internal/routes/`, `internal/handlers/`, `internal/services/`, `internal/repository/`, `internal/storage/`, `internal/config/`, `internal/mcp/`, `docs/`.
8+
- Main entry: `main.go` initializes `ConfigManager`, `StorageManager`, and starts the HTTP server via `routes.CreateAndStartServer()`; DB initialization is deferred and can be triggered via `/setup/initialize`.
9+
10+
2) Typical data & control flow
11+
- HTTP requests handled by `routes` -> call `handlers` -> call `services` -> use `repository` -> talk to DB/storage.
12+
- Storage is abstracted by `storage.NewStorageManager(manager)` and concrete implementations under `internal/storage/` (local, s3, webdav, onedrive).
13+
- MCP subsystem lives under `internal/mcp/` and is conditionally started when `manager.MCP.EnableMCPServer == 1`.
14+
15+
3) Configuration & runtime
16+
- Config is centralized in `internal/config/manager.go` (use `config.InitManager()` to obtain `ConfigManager`).
17+
- Environment variables override config; `manager.SetDB(db)` is used to inject DB connection after initialization.
18+
- Common env vars: `PORT`, `DATA_PATH`, `ENABLE_MCP_SERVER`.
19+
20+
4) Versioning & release patterns
21+
- Project version stored in the top-level `VERSION` file and echoed in `internal/models/service/system.go` (`Version` variable) and swagger docs under `docs/`.
22+
- Releases are created by updating those files and tagging the commit (e.g., `v1.8.2`). Avoid editing `go.sum` manually.
23+
24+
5) Build, test, and release commands
25+
- Build: `make build` or `go build ./...`.
26+
- Tests: `make test` or `go test ./...` (many packages have no tests; run targeted packages if needed).
27+
- Docker: `./scripts/build-docker.sh` and `docker-compose.yml` present.
28+
29+
6) Project-specific conventions
30+
- Handler constructors follow: `NewXxxHandler(service *services.XxxService, config *config.ConfigManager) *XxxHandler`.
31+
- Services are created with dependency injection in `routes` during server start: e.g., `services.NewUserService(daoManager, manager)`.
32+
- Repositories live under `internal/repository/` and expose `RepositoryManager` for DAOs (use `dmgr *repository.RepositoryManager`).
33+
- Error responses use helper functions in `internal/common/` (`common.SuccessResponse`, `common.ErrorResponse`, `common.BadRequestResponse`).
34+
35+
7) Integration points to inspect when editing code
36+
- `internal/config/manager.go` — config lifecycle, hot reload hooks.
37+
- `internal/routes/setup.go` — server and route wiring, DI order.
38+
- `internal/mcp/manager.go` — MCP lifecycle and tools registration.
39+
- `internal/storage/*` — adding new storage backends: implement `storage.StorageInterface` and register in `storage.NewStorageManager`.
40+
41+
8) Useful file examples to copy patterns from
42+
- `internal/services/*` shows DI, error wrapping and transaction handling (e.g., `internal/services/admin/*`).
43+
- `internal/routes/*` shows route grouping and middleware usage, look at `internal/routes/admin.go` for admin auth patterns.
44+
45+
9) CSS / Frontend notes
46+
- Frontend themes under `themes/2025/`. Admin UI assets are served via protected routes — modifying admin CSS may require rebuilding or restarting server to pick static changes when not using hot reload.
47+
48+
10) Safety & version control
49+
- Do not alter `go.sum` manually.
50+
- When creating tags, prefer not to overwrite remote tags; create a new semver or `-local.<sha>` tag if necessary.
51+
52+
If any section is unclear or you want examples added (e.g., sample PR description, changelog generation command), tell me which part to expand. After your feedback I'll iterate.
153
# FileCodeBox AI Coding Agent Instructions
254

355
## Project Overview

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Build and Release
22

33
on:
44
push:
5+
# Only trigger the heavy multi-platform build on version tag pushes (e.g. v1.9.1)
56
tags:
67
- 'v*'
7-
branches: [ main ]
8-
pull_request:
9-
branches: [ main ]
8+
# Allow manual dispatch for ad-hoc builds from the UI
9+
workflow_dispatch:
1010

1111
permissions:
1212
contents: read

.github/workflows/ci.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches: [ main, develop ]
66
pull_request:
77
branches: [ main, develop ]
8+
# Allow manual runs
9+
workflow_dispatch:
810

911
jobs:
1012
test:
@@ -102,7 +104,14 @@ jobs:
102104
name: Docker Test
103105
runs-on: ubuntu-latest
104106
needs: test
105-
if: github.event_name == 'push'
107+
# Run Docker Test only when explicitly requested via commit message flag
108+
# (e.g., include [docker-test] in the commit message) or when running on tags/branches on CI
109+
# Run when explicitly requested by commit message, PR label, tag push, or manual dispatch
110+
if: |
111+
contains(github.event.head_commit.message, '[docker-test]') ||
112+
startsWith(github.ref, 'refs/tags/') ||
113+
github.event_name == 'workflow_dispatch' ||
114+
(github.event_name == 'pull_request' && contains(join(github.event.pull_request.labels.*.name, ','), 'run-full-ci'))
106115
107116
steps:
108117
- name: Checkout code
@@ -148,7 +157,13 @@ jobs:
148157
security:
149158
name: Security Scan
150159
runs-on: ubuntu-latest
151-
if: github.event_name == 'push'
160+
# Run Security Scan only when explicitly requested via commit message flag
161+
# (e.g., include [security-scan] in the commit message) or when running manually
162+
# Run when explicitly requested by commit message, PR label, or manual dispatch
163+
if: |
164+
contains(github.event.head_commit.message, '[security-scan]') ||
165+
github.event_name == 'workflow_dispatch' ||
166+
(github.event_name == 'pull_request' && contains(join(github.event.pull_request.labels.*.name, ','), 'run-security'))
152167
153168
steps:
154169
- name: Checkout code

CONTRIBUTING.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
## Contributing and CI guidelines
2+
3+
This document explains how our GitHub Actions are gated and how to trigger heavier CI jobs (cross-platform builds, Docker tests, security scans) intentionally.
4+
5+
### CI design principles
6+
- Lightweight checks (unit tests, linters) run on `push` / `pull_request` for `main` and `develop` branches.
7+
- Heavy tasks (cross-platform builds, Docker image builds & push, release packaging) only run on tag pushes (e.g. `v1.9.1`) or when explicitly requested.
8+
9+
This reduces wasted CI minutes and avoids building/publishing artifacts for every code merge.
10+
11+
### How to trigger heavy CI jobs
12+
There are multiple intentional ways to trigger full/heavy workflows:
13+
14+
- Push a semantic version tag (recommended for releases):
15+
```bash
16+
git tag v1.9.1
17+
git push origin v1.9.1
18+
```
19+
Tag pushes trigger the `build.yml` / `release.yml` flows which do cross-platform builds and create the Release.
20+
21+
- Use commit message flags for ad-hoc full CI when pushing branches:
22+
- `[docker-test]` — triggers Docker Test job
23+
- `[security-scan]` — triggers Security Scan job
24+
Example:
25+
```bash
26+
git commit -m "feat: add X [docker-test]"
27+
git push origin feature/xxx
28+
```
29+
30+
- Use PR labels to request full CI for a pull request (team members with label permissions can add labels):
31+
- `run-full-ci` — triggers Docker Test
32+
- `run-security` — triggers Security Scan
33+
34+
- Manual dispatch from GitHub Actions UI (`workflow_dispatch`) — allowed for `build.yml` and can be used to run ad-hoc full builds.
35+
36+
### Release flow (recommended)
37+
1. Finish work on a branch, open PR and get reviews.
38+
2. Merge to `main` when ready (this runs lightweight CI only).
39+
3. Create a version tag on the merge commit and push the tag:
40+
```bash
41+
git tag vX.Y.Z
42+
git push origin vX.Y.Z
43+
```
44+
4. The tag push will run the release pipeline (build artifacts, create release, push Docker images).
45+
46+
### Generated files and embeds
47+
- Some files under `uploads/` or other `generated/` directories may be produced by code generation tools. Do not commit generated artifacts unless they are intentionally tracked.
48+
- If a file uses `//go:embed` to include generated assets, ensure the assets exist in the repository or exclude the embed file from normal builds (recommended: keep generated assets out of VCS and generate them in CI when needed).
49+
50+
Recommended `.gitignore` additions for generated assets (add if appropriate):
51+
```
52+
# generated embed or build artifacts
53+
uploads/
54+
dist/
55+
build/
56+
```
57+
58+
### Debugging CI triggers
59+
- To see why a job ran, open the Actions page, find the workflow run and view the `Event` and `Jobs` details. The `Event` will indicate whether it was a `push`, `pull_request`, `workflow_dispatch`, or `tag` event.
60+
- If you expected a heavy job but it didn't run, verify:
61+
- You pushed a tag (tags trigger build/release flows).
62+
- The commit message includes the required token (e.g., `[docker-test]`).
63+
- A PR contains the appropriate label (`run-full-ci` or `run-security`).
64+
65+
### Contact / ownership
66+
- CI workflow files are located under `.github/workflows/`. If you want to change gating logic, please open a PR and tag the maintainers.
67+
68+
---
69+
Thank you for contributing — keeping heavy CI runs intentional saves time and cost for the whole team.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.2
1+
1.9.1

config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
base:
2-
name: FileCodeBox
2+
name: 站点
33
description: 开箱即用的文件快传系统
44
keywords: FileCodeBox, 文件快递柜, 口令传送箱, 匿名口令分享文本, 文件
55
port: 12345
@@ -18,13 +18,15 @@ transfer:
1818
upload:
1919
openupload: 1
2020
uploadsize: 10485760
21-
enablechunk: 0
21+
enablechunk: 1
2222
chunksize: 2097152
2323
maxsaveseconds: 0
24+
requirelogin: 1
2425
download:
2526
enableconcurrentdownload: 1
2627
maxconcurrentdownloads: 10
2728
downloadtimeout: 300
29+
requirelogin: 0
2830
storage:
2931
type: ""
3032
storagepath: ""

docs/config.new.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ transfer:
1717
enable_chunk: 1
1818
chunk_size: 2097152
1919
max_save_seconds: 0
20+
require_login: 0
2021
download:
2122
enable_concurrent_download: 1
2223
max_concurrent_downloads: 10
2324
download_timeout: 300
25+
require_login: 0
2426

2527
user:
2628
allow_user_registration: 1

docs/swagger-enhanced.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ swagger: "2.0"
22
info:
33
title: "FileCodeBox API"
44
description: "FileCodeBox 是一个用于文件分享和代码片段管理的 Web 应用程序"
5-
version: "1.8.2"
5+
version: "1.9.1"
66
termsOfService: "http://swagger.io/terms/"
77
contact:
88
name: "API Support"
@@ -69,7 +69,7 @@ paths:
6969
example: "2025-09-11T10:00:00Z"
7070
version:
7171
type: "string"
72-
example: "1.8.2"
72+
example: "1.9.1"
7373
uptime:
7474
type: "string"
7575
example: "2h30m15s"

docs/swagger.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"name": "MIT",
1414
"url": "https://github.com/zy84338719/filecodebox/blob/main/LICENSE"
1515
},
16-
"version": "1.8.2"
16+
"version": "1.9.1"
1717
},
1818
"host": "localhost:12345",
1919
"basePath": "/",
@@ -553,7 +553,7 @@
553553
},
554554
"version": {
555555
"type": "string",
556-
"example": "1.8.2"
556+
"example": "1.9.1"
557557
}
558558
}
559559
},

docs/swagger.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ definitions:
1212
example: 2h30m15s
1313
type: string
1414
version:
15-
example: 1.8.2
15+
example: 1.9.1
1616
type: string
1717
type: object
1818
handlers.SystemConfig:
@@ -57,7 +57,7 @@ info:
5757
url: https://github.com/zy84338719/filecodebox/blob/main/LICENSE
5858
termsOfService: http://swagger.io/terms/
5959
title: FileCodeBox API
60-
version: "1.8.2"
60+
version: "1.9.1"
6161
paths:
6262
/api/config:
6363
get:

0 commit comments

Comments
 (0)