Some checks are pending
Release Binaries / Build and Release (.exe, amd64, windows, windows-amd64) (push) Waiting to run
Release Binaries / Build and Release (amd64, darwin, darwin-amd64) (push) Waiting to run
Release Binaries / Build and Release (amd64, linux, linux-amd64) (push) Waiting to run
Release Binaries / Build and Release (arm64, darwin, darwin-arm64) (push) Waiting to run
Release Binaries / Build and Release (arm64, linux, linux-arm64) (push) Waiting to run
- Add Token GORM model with UserID/Name/Token/LastUsedAt/ExpiresAt fields
- Add TokenManager controller: List/Create/Delete/Verify operations
- Add token HTTP handlers: list, create, revoke
- Update AuthVerify to support Bearer token auth; API tokens use "ust_" prefix to distinguish from session tokens
- Add one-step file upload endpoint: PUT /api/v1/upload/:filename (returns {"status":200,"data":{"code":"..."}})
- Add token management routes: GET/POST/DELETE /api/token
- Add /self page: personal center with account info, token management table, and curl usage guide
- Add "个人中心 / API Token" nav link for users with token_manage permission
🤖 Generated with [Qoder][https://qoder.com]
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/loveuer/nf/nft/log"
|
|
"github.com/loveuer/ushare/internal/api"
|
|
"github.com/loveuer/ushare/internal/controller"
|
|
"github.com/loveuer/ushare/internal/model"
|
|
"github.com/loveuer/ushare/internal/opt"
|
|
"github.com/loveuer/ushare/internal/pkg/db"
|
|
"github.com/loveuer/ushare/internal/pkg/tool"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func init() {
|
|
flag.BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode")
|
|
flag.StringVar(&opt.Cfg.Address, "address", "0.0.0.0:9119", "")
|
|
flag.StringVar(&opt.Cfg.DataPath, "data", "/data", "")
|
|
flag.IntVar(&opt.Cfg.CleanInterval, "clean", 24, "清理文件的周期, 单位: 小时, 0 则表示不自动清理")
|
|
flag.Parse()
|
|
|
|
opt.LoadFromEnv()
|
|
|
|
if opt.Cfg.Debug {
|
|
log.SetLogLevel(log.LogLevelDebug)
|
|
tool.TablePrinter(opt.Cfg)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer cancel()
|
|
|
|
opt.Init(ctx)
|
|
|
|
if err := os.MkdirAll(opt.Cfg.DataPath, 0755); err != nil {
|
|
log.Fatal("main: create data path failed: %s", err.Error())
|
|
}
|
|
|
|
dbPath := filepath.Join(opt.Cfg.DataPath, ".ushare.db")
|
|
if err := db.Init(ctx, "sqlite::"+dbPath); err != nil {
|
|
log.Fatal("main: init db failed: %s", err.Error())
|
|
}
|
|
log.Debug("main: db initialized at %s", dbPath)
|
|
|
|
if err := db.Default.Migrate(&model.Role{}, &model.User{}, &model.Token{}); err != nil {
|
|
log.Fatal("main: db migrate failed: %s", err.Error())
|
|
}
|
|
|
|
controller.UserManager.Start(ctx)
|
|
controller.MetaManager.Start(ctx)
|
|
controller.RoomController.Start(ctx)
|
|
api.Start(ctx)
|
|
|
|
<-ctx.Done()
|
|
}
|