16 Commits

Author SHA1 Message Date
loveuer 6e5bf040dc fix: v0.1.2
/ build and run u-api (push) Failing after 2s
/ clean (push) Successful in 0s
2025-05-09 23:06:21 +08:00
loveuer 1a8827a67a fix: v0.1.2
/ build and run u-api (push) Failing after 2s
/ clean (push) Successful in 0s
2025-05-09 23:03:46 +08:00
loveuer 761b1d3b27 fix: v0.1.2
/ build and run u-api (push) Failing after 3s
/ clean (push) Successful in 0s
2025-05-09 22:52:32 +08:00
loveuer fb66b2c359 fix: v0.1.2
/ build and run u-api (push) Failing after 3s
/ clean (push) Successful in 0s
2025-05-09 22:45:32 +08:00
loveuer ad1b096a3b fix: v0.1.2
/ build and run u-api (push) Failing after 3s
/ clean (push) Successful in 0s
2025-05-09 22:44:31 +08:00
loveuer 2d992e36ec fix: v0.1.2
/ build and run u-api (push) Failing after 2s
/ clean (push) Successful in 0s
2025-05-09 22:11:54 +08:00
loveuer 91f3da635d fix: v0.1.2
/ build and run u-api (push) Failing after 2s
/ clean (push) Successful in 0s
2025-05-09 22:10:18 +08:00
loveuer 93c4339039 init: 0.1.2
/ build and run u-api (push) Failing after 8s
/ clean (push) Successful in 0s
feat: login page && auth required
todo: file dir cleanup
2025-05-09 17:49:12 +08:00
loveuer e5cf2c1367 cache 2025-05-09 11:22:27 +08:00
loveuer 0e984c46b4 init: 0.1.1
feat: login page && auth required
todo: 断点上传
2025-05-08 18:02:49 +08:00
loveuer 440aa96ad6 init: 0.1.0
feat: 基本功能有了
  1. 分片上传
  2. code 回显
  3. 下载
todo: 断点上传
2025-05-06 18:04:20 +08:00
loveuer cfd4e8cb6d init: 0.0.8
feat: 实现了分片上传
todo:
  1. 上传完成后 code 回显
  2. 清理不用的临时 code file
  3. 断点续传
  4. 多 chunk 并发上传
2025-04-30 18:00:29 +08:00
loveuer b8fda4322f init: 0.0.7
next: upload
2025-04-28 17:59:07 +08:00
loveuer 0cfd617922 init: 0.0.6
next: upload
2025-04-28 14:59:22 +08:00
loveuer 4801b3de08 wip: v0.0.5 2025-04-27 22:14:21 +08:00
loveuer 25c76aebf2 init: 0.0.4 2025-04-27 18:01:58 +08:00
7 changed files with 23 additions and 96 deletions
+1 -2
View File
@@ -1,3 +1,2 @@
frontend/node_modules node_modules
dist dist
frontend/dist
+12 -24
View File
@@ -5,7 +5,7 @@ on:
- 'v*' - 'v*'
jobs: jobs:
build ushare: build and run u-api:
runs-on: tencent-sg runs-on: tencent-sg
steps: steps:
- name: prepare enviroment - name: prepare enviroment
@@ -17,6 +17,9 @@ jobs:
- name: print operator - name: print operator
run: whoami run: whoami
- name: print work dir and files
run: pwd & ls -alsh .
- name: print tag name - name: print tag name
run: echo "Tag name = ${{ gitea.ref_name }}" run: echo "Tag name = ${{ gitea.ref_name }}"
@@ -26,29 +29,14 @@ jobs:
${{ secrets.DOCKER_CONFIG }} ${{ secrets.DOCKER_CONFIG }}
EOF EOF
- name: print work dir and files - name: build by kaniko in docker
run: pwd & ls -alsh . run: |
docker run --rm -v $(pwd):/workspace \
- name: build image by docker build -v $(pwd)/.docker.config.json:/kaniko/.docker/config.json:ro \
run: docker build -t gitea.loveuer.com/loveuer/build/ushare:${{ gitea.ref_name }} . gcr.io/kaniko-project/executor:latest \
'-f /workspace/Dockerfile' \
- name: login repository '-d "gitea.loveuer.com/loveuer/build/ushare:${{ gitea.ref_name }}"' \
run: echo ${{ secrets.DOCKER_REPOSITORY_PASSWORD }} | docker login --username loveuer --password-stdin gitea.loveuer.com/loveuer '--single-snapshot'
- name: push image to repository
run: docker push gitea.loveuer.com/loveuer/build/ushare:${{ gitea.ref_name }}
# - name: build by kaniko in docker
# run: |
# docker run --rm -v $(pwd):/workspace \
# -v $(pwd)/.docker.config.json:/kaniko/.docker/config.json:ro \
# alpine:latest \
# ls -alsh /workspace
# gcr.io/kaniko-project/executor:latest \
# --dockerfile=/workspace/Dockerfile \
# --context=/workspace \
# --destination=gitea.loveuer.com/loveuer/build/u-api:${{ gitea.ref_name }} \
# --single-snapshot
clean: clean:
if: always() if: always()
+1 -4
View File
@@ -27,12 +27,9 @@ COPY --from=backend-builder /app/ushare /usr/local/bin/ushare
# 配置 Nginx # 配置 Nginx
RUN rm /etc/nginx/conf.d/default.conf RUN rm /etc/nginx/conf.d/default.conf
COPY deployment/nginx.conf /etc/nginx/conf.d COPY deployment/nginx.conf /etc/nginx/conf.d
COPY deployment/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# 开放端口 # 开放端口
EXPOSE 80 EXPOSE 80
# 启动服务 # 启动服务
ENTRYPOINT ["entrypoint.sh"] CMD sh -c "ushare & nginx -g 'daemon off;'"
-35
View File
@@ -1,35 +0,0 @@
#!/bin/sh
set -e
# 启动后端服务(带参数后台运行)
echo "启动后端服务,参数: $@"
ushare "$@" &
BACKEND_PID=$!
# 定义优雅关闭函数
graceful_shutdown() {
echo "接收到终止信号,开始优雅关闭..."
# 先关闭 Nginx
echo "关闭 Nginx..."
nginx -s quit 2>/dev/null || kill -TERM $NGINX_PID 2>/dev/null
# 关闭后端服务
echo "关闭后端服务 PID $BACKEND_PID..."
kill -TERM $BACKEND_PID 2>/dev/null
# 等待进程终止
wait $BACKEND_PID $NGINX_PID 2>/dev/null
exit 0
}
# 捕获系统信号
trap 'graceful_shutdown' SIGTERM SIGINT
# 启动 Nginx(前台运行)
echo "启动 Nginx..."
nginx -g "daemon off;" &
NGINX_PID=$!
# 等待所有后台进程
wait $BACKEND_PID $NGINX_PID
+3 -22
View File
@@ -104,10 +104,6 @@ func (m *meta) Start(ctx context.Context) {
ticker := time.NewTicker(time.Minute) ticker := time.NewTicker(time.Minute)
m.ctx = ctx m.ctx = ctx
if err := os.MkdirAll(opt.Cfg.DataPath, 0644); err != nil {
log.Fatal("controller.MetaManager.Start: mkdir datapath failed, path = %s, err = %s", opt.Cfg.DataPath, err.Error())
}
// 清理 2 分钟内没有继续上传的 part // 清理 2 分钟内没有继续上传的 part
go func() { go func() {
for { for {
@@ -135,25 +131,14 @@ func (m *meta) Start(ctx context.Context) {
// 清理一天前的文件 // 清理一天前的文件
go func() { go func() {
if opt.Cfg.CleanInterval <= 0 {
log.Warn("meta.Clean: no clean interval set, plz clean manual!!!")
return
}
ticker := time.NewTicker(5 * time.Minute) ticker := time.NewTicker(5 * time.Minute)
duration := time.Duration(opt.Cfg.CleanInterval) * time.Hour
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case now := <-ticker.C: case now := <-ticker.C:
//log.Debug("meta.Clean: 开始清理过期文件 = %v", duration)
_ = filepath.Walk(opt.Cfg.DataPath, func(path string, info os.FileInfo, err error) error { _ = filepath.Walk(opt.Cfg.DataPath, func(path string, info os.FileInfo, err error) error {
if info == nil {
return nil
}
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
@@ -179,16 +164,12 @@ func (m *meta) Start(ctx context.Context) {
code := strings.TrimPrefix(name, ".meta.") code := strings.TrimPrefix(name, ".meta.")
if now.Sub(time.UnixMilli(mi.CreatedAt)) > duration { if now.Sub(time.UnixMilli(mi.CreatedAt)) > 24*time.Hour {
log.Debug("controller.meta: file out of date, code = %s, user_key = %s", code, mi.Uploader) log.Debug("controller.meta: file out of date, code = %s, user_key = %s", code, mi.Uploader)
if err = os.RemoveAll(opt.FilePath(code)); err != nil { os.RemoveAll(opt.FilePath(code))
log.Warn("meta.Clean: remove file failed, file = %s, err = %s", opt.FilePath(code), err.Error()) os.RemoveAll(path)
}
if err = os.RemoveAll(path); err != nil {
log.Warn("meta.Clean: remove file failed, file = %s, err = %s", path, err.Error())
}
m.Lock() m.Lock()
delete(m.m, code) delete(m.m, code)
-1
View File
@@ -11,7 +11,6 @@ type config struct {
Address string Address string
DataPath string DataPath string
Auth string Auth string
CleanInterval int
} }
var ( var (
+1 -3
View File
@@ -7,7 +7,6 @@ import (
"github.com/loveuer/ushare/internal/api" "github.com/loveuer/ushare/internal/api"
"github.com/loveuer/ushare/internal/controller" "github.com/loveuer/ushare/internal/controller"
"github.com/loveuer/ushare/internal/opt" "github.com/loveuer/ushare/internal/opt"
"github.com/loveuer/ushare/internal/pkg/tool"
"os/signal" "os/signal"
"syscall" "syscall"
) )
@@ -17,12 +16,11 @@ func init() {
flag.StringVar(&opt.Cfg.Address, "address", "0.0.0.0:9119", "") flag.StringVar(&opt.Cfg.Address, "address", "0.0.0.0:9119", "")
flag.StringVar(&opt.Cfg.DataPath, "data", "/data", "") flag.StringVar(&opt.Cfg.DataPath, "data", "/data", "")
flag.StringVar(&opt.Cfg.Auth, "auth", "", "auth required(admin, password)") flag.StringVar(&opt.Cfg.Auth, "auth", "", "auth required(admin, password)")
flag.IntVar(&opt.Cfg.CleanInterval, "clean", 24, "清理文件的周期, 单位: 小时, 0 则表示不自动清理")
flag.Parse() flag.Parse()
if opt.Cfg.Debug { if opt.Cfg.Debug {
log.SetLogLevel(log.LogLevelDebug) log.SetLogLevel(log.LogLevelDebug)
tool.TablePrinter(opt.Cfg) log.Debug("start server with debug mode")
} }
} }