feat: complete Vue UI parity (full backend + frontend)

== New domain models (7) ==
- UserPermission: per-user feature toggles (13 booleans)
- StorageConfig: encrypted Alist/S3/WebDAV adapters
- LicenseKey + LicenseActivation: offline license issuance
- DownloadClient: multi-client downloader configs
- AssistantSession + AssistantMessage: multi-turn AI chat persistence

== New services (5) ==
- PermissionService: admin grants always-true; user defaults seeded
- StorageConfigService: AES-GCM encryption + per-type connection probe
- LicenseService: 24-char hyphenated key generation, activation/heartbeat
- DownloadClientService: qB/Aria2/Transmission CRUD + WebUI test
- AssistantService: chat history + execute/undo stubs (op_id tracking)

== Extended AIService.Chat ==
- Multi-turn LLM call with chat history; offline fallback reply

== New endpoints (60+) ==
Auth:
  POST /auth/refresh, /auth/logout, /auth/change-password
  PATCH /auth/profile
  GET /auth/permissions, /auth/me

Permissions admin:
  GET/PUT /admin/users/:id/permissions
  POST /admin/users/:id/permissions/reset

Search:
  GET /search, /search/advanced, /search/tmdb, /search/sites

System:
  GET /system/config, /settings/schema, /system/events/ticket
  POST /admin/system/scheduler/:name/trigger

Stats:
  GET /stats/user/:id, /stats/top-users
  POST /stats/play

Sites:
  GET /sites/:id/resource, /sites/:id/userdata

Subscriptions:
  PUT /subscriptions/:id, POST /subscriptions/:id/search

Playlists:
  POST /playlists/:id/reorder
  DELETE /playlists/:id/items/by-id/:item_id

DLNA per-renderer:
  POST /dlna/:uuid/{play,pause,stop}, GET /dlna/:uuid/status

Media:
  POST/DELETE /media/:id/favorite, GET /media/:id/favorite/status
  POST /media/:id/ai-scrape, /media/scrape/test, /media/organize
  GET /favorites (alias)

Playback:
  GET /playback/:id/info, /playback/:id/external-players, /playback/:id/external-url
  POST /playback/:id/progress
  GET /playback/transcode/:job_id/status

Downloads:
  POST /download/:id/{pause,resume,organize}
  POST /download/{organize,sync,start-auto-sync}
  GET /download/tasks
  Admin: full CRUD on /admin/download/clients + /admin/download/aria2/stats

License:
  POST /license/{activate,heartbeat}
  GET /license/{status,heartbeat-status}
  Admin: /admin/license/{generate,list,:id/activations,:id/revoke,activation/:id/unbind}

Storage:
  GET /admin/storage/{status,:type}
  PUT /admin/storage/:type, POST /admin/storage/:type/test

Assistant (multi-turn AI):
  GET/POST /admin/assistant/sessions
  GET/DELETE /admin/assistant/session/:id
  POST /admin/assistant/{chat,execute}
  POST /admin/assistant/undo/:op_id
  GET /admin/assistant/history

== New React pages (4) ==
- AssistantChatPage (/assistant): full multi-turn chat UI with sessions
  sidebar, optimistic user-turn append, live AI response.
- DownloadClientsPage (/download-clients): typed CRUD form for
  qBittorrent / Aria2 / Transmission + per-row Test action.
- LicensePage (/license): generate keys, list activations, revoke,
  unbind individual devices.
- StorageConfigPage (/storage-config): tabbed Alist/WebDAV/S3 form
  with secret-aware redaction + connection probe.

== New API helpers (5) ==
- assistant, download_clients, license, permissions, storage_config

== Layout ==
- Sidebar gains 4 new admin links (AI 对话, 下载器, 外部存储, 许可证).
This commit is contained in:
Kiro Agent
2026-05-16 09:49:35 +00:00
parent 7095d9ebec
commit 1dbd73b30b
38 changed files with 4496 additions and 14 deletions
+274 -14
View File
@@ -32,25 +32,35 @@ type Container struct {
Log *AccessLogRepository
NotifyChannel *NotifyChannelRepository
PlayProfile *PlayProfileRepository
Permission *PermissionRepository
StorageConfig *StorageConfigRepository
License *LicenseRepository
DownloadClient *DownloadClientRepository
Assistant *AssistantRepository
}
// New wires every repository to a single *gorm.DB.
func New(db *gorm.DB) *Container {
return &Container{
DB: db,
User: &UserRepository{db: db},
Library: &LibraryRepository{db: db},
Media: &MediaRepository{db: db},
Series: &SeriesRepository{db: db},
History: &HistoryRepository{db: db},
Favorite: &FavoriteRepository{db: db},
Playlist: &PlaylistRepository{db: db},
Download: &DownloadRepository{db: db},
Subscription: &SubscriptionRepository{db: db},
Setting: &SettingRepository{db: db},
Log: &AccessLogRepository{db: db},
NotifyChannel: &NotifyChannelRepository{db: db},
PlayProfile: &PlayProfileRepository{db: db},
DB: db,
User: &UserRepository{db: db},
Library: &LibraryRepository{db: db},
Media: &MediaRepository{db: db},
Series: &SeriesRepository{db: db},
History: &HistoryRepository{db: db},
Favorite: &FavoriteRepository{db: db},
Playlist: &PlaylistRepository{db: db},
Download: &DownloadRepository{db: db},
Subscription: &SubscriptionRepository{db: db},
Setting: &SettingRepository{db: db},
Log: &AccessLogRepository{db: db},
NotifyChannel: &NotifyChannelRepository{db: db},
PlayProfile: &PlayProfileRepository{db: db},
Permission: &PermissionRepository{db: db},
StorageConfig: &StorageConfigRepository{db: db},
License: &LicenseRepository{db: db},
DownloadClient: &DownloadClientRepository{db: db},
Assistant: &AssistantRepository{db: db},
}
}
@@ -501,3 +511,253 @@ func (r *PlayProfileRepository) Update(ctx context.Context, id string, patch map
func (r *PlayProfileRepository) Delete(ctx context.Context, id string) error {
return r.db.WithContext(ctx).Delete(&model.PlayProfile{}, "id = ?", id).Error
}
// ─── Permissions ─────────────────────────────────────────────────────────────
// PermissionRepository persists model.UserPermission.
type PermissionRepository struct{ db *gorm.DB }
// Get returns the row, or (nil, nil) when not yet seeded.
func (r *PermissionRepository) Get(ctx context.Context, userID string) (*model.UserPermission, error) {
var p model.UserPermission
err := r.db.WithContext(ctx).Where("user_id = ?", userID).First(&p).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &p, nil
}
// Save upserts the row keyed by UserID.
func (r *PermissionRepository) Save(ctx context.Context, p *model.UserPermission) error {
return r.db.WithContext(ctx).Save(p).Error
}
// Delete removes the row (used when a user is deleted).
func (r *PermissionRepository) Delete(ctx context.Context, userID string) error {
return r.db.WithContext(ctx).Where("user_id = ?", userID).Delete(&model.UserPermission{}).Error
}
// ─── Storage Config ──────────────────────────────────────────────────────────
// StorageConfigRepository persists model.StorageConfig records (Alist / S3 / WebDAV).
type StorageConfigRepository struct{ db *gorm.DB }
// Get returns the config for the given type, or (nil, nil).
func (r *StorageConfigRepository) Get(ctx context.Context, kind string) (*model.StorageConfig, error) {
var s model.StorageConfig
err := r.db.WithContext(ctx).Where("type = ?", kind).First(&s).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &s, nil
}
// Upsert inserts or updates the row keyed by Type.
func (r *StorageConfigRepository) Upsert(ctx context.Context, s *model.StorageConfig) error {
return r.db.WithContext(ctx).Where("type = ?", s.Type).
Assign(map[string]any{
"config": s.Config,
"enabled": s.Enabled,
"last_error": s.LastError,
}).
FirstOrCreate(s).Error
}
// List returns every storage config (admin overview).
func (r *StorageConfigRepository) List(ctx context.Context) ([]model.StorageConfig, error) {
var rows []model.StorageConfig
err := r.db.WithContext(ctx).Order("type asc").Find(&rows).Error
return rows, err
}
// ─── License ─────────────────────────────────────────────────────────────────
// LicenseRepository persists model.LicenseKey and model.LicenseActivation.
type LicenseRepository struct{ db *gorm.DB }
// Create inserts a new license key.
func (r *LicenseRepository) Create(ctx context.Context, k *model.LicenseKey) error {
return r.db.WithContext(ctx).Create(k).Error
}
// FindByKey returns the license key matching the value, or (nil, nil).
func (r *LicenseRepository) FindByKey(ctx context.Context, key string) (*model.LicenseKey, error) {
var k model.LicenseKey
err := r.db.WithContext(ctx).Where("key = ?", key).First(&k).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &k, nil
}
// FindByID returns the license key by primary key.
func (r *LicenseRepository) FindByID(ctx context.Context, id string) (*model.LicenseKey, error) {
var k model.LicenseKey
err := r.db.WithContext(ctx).Where("id = ?", id).First(&k).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &k, nil
}
// List returns every license key (admin view).
func (r *LicenseRepository) List(ctx context.Context) ([]model.LicenseKey, error) {
var rows []model.LicenseKey
err := r.db.WithContext(ctx).Order("issued_at desc").Find(&rows).Error
return rows, err
}
// Update applies a partial patch (revoke / extend expiry, etc.).
func (r *LicenseRepository) Update(ctx context.Context, id string, patch map[string]any) error {
return r.db.WithContext(ctx).Model(&model.LicenseKey{}).
Where("id = ?", id).Updates(patch).Error
}
// AddActivation creates an activation entry for a key.
func (r *LicenseRepository) AddActivation(ctx context.Context, a *model.LicenseActivation) error {
return r.db.WithContext(ctx).Create(a).Error
}
// CountActiveActivations counts non-unbound activations for a key.
func (r *LicenseRepository) CountActiveActivations(ctx context.Context, keyID string) (int64, error) {
var n int64
err := r.db.WithContext(ctx).Model(&model.LicenseActivation{}).
Where("key_id = ? AND unbound_at IS NULL", keyID).
Count(&n).Error
return n, err
}
// ListActivations returns all activations for a key.
func (r *LicenseRepository) ListActivations(ctx context.Context, keyID string) ([]model.LicenseActivation, error) {
var rows []model.LicenseActivation
err := r.db.WithContext(ctx).Where("key_id = ?", keyID).Find(&rows).Error
return rows, err
}
// UnbindActivation marks an activation as unbound (soft).
func (r *LicenseRepository) UnbindActivation(ctx context.Context, id string) error {
now := time.Now()
return r.db.WithContext(ctx).Model(&model.LicenseActivation{}).
Where("id = ?", id).Update("unbound_at", &now).Error
}
// TouchHeartbeat bumps the heartbeat_at column.
func (r *LicenseRepository) TouchHeartbeat(ctx context.Context, id string) error {
now := time.Now()
return r.db.WithContext(ctx).Model(&model.LicenseActivation{}).
Where("id = ?", id).Update("heartbeat_at", &now).Error
}
// ─── Download Clients ────────────────────────────────────────────────────────
// DownloadClientRepository persists model.DownloadClient records.
type DownloadClientRepository struct{ db *gorm.DB }
// Create inserts a new client config.
func (r *DownloadClientRepository) Create(ctx context.Context, c *model.DownloadClient) error {
return r.db.WithContext(ctx).Create(c).Error
}
// FindByID returns one client by ID.
func (r *DownloadClientRepository) FindByID(ctx context.Context, id string) (*model.DownloadClient, error) {
var c model.DownloadClient
err := r.db.WithContext(ctx).Where("id = ?", id).First(&c).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &c, nil
}
// List returns every configured client.
func (r *DownloadClientRepository) List(ctx context.Context) ([]model.DownloadClient, error) {
var rows []model.DownloadClient
err := r.db.WithContext(ctx).Order("created_at asc").Find(&rows).Error
return rows, err
}
// Update applies a partial patch.
func (r *DownloadClientRepository) Update(ctx context.Context, id string, patch map[string]any) error {
return r.db.WithContext(ctx).Model(&model.DownloadClient{}).
Where("id = ?", id).Updates(patch).Error
}
// Delete soft-deletes one client.
func (r *DownloadClientRepository) Delete(ctx context.Context, id string) error {
return r.db.WithContext(ctx).Delete(&model.DownloadClient{}, "id = ?", id).Error
}
// ─── Assistant ───────────────────────────────────────────────────────────────
// AssistantRepository persists AssistantSession + AssistantMessage rows.
type AssistantRepository struct{ db *gorm.DB }
// CreateSession inserts a new session.
func (r *AssistantRepository) CreateSession(ctx context.Context, s *model.AssistantSession) error {
return r.db.WithContext(ctx).Create(s).Error
}
// FindSession returns the session row + ownership.
func (r *AssistantRepository) FindSession(ctx context.Context, id string) (*model.AssistantSession, error) {
var s model.AssistantSession
err := r.db.WithContext(ctx).Where("id = ?", id).First(&s).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &s, nil
}
// ListSessions returns sessions for the user (or all for admins).
func (r *AssistantRepository) ListSessions(ctx context.Context, userID string) ([]model.AssistantSession, error) {
var rows []model.AssistantSession
q := r.db.WithContext(ctx).Order("updated_at desc")
if userID != "" {
q = q.Where("user_id = ?", userID)
}
err := q.Find(&rows).Error
return rows, err
}
// DeleteSession removes one session and cascades to its messages.
func (r *AssistantRepository) DeleteSession(ctx context.Context, id string) error {
if err := r.db.WithContext(ctx).Where("session_id = ?", id).Delete(&model.AssistantMessage{}).Error; err != nil {
return err
}
return r.db.WithContext(ctx).Delete(&model.AssistantSession{}, "id = ?", id).Error
}
// AppendMessage inserts a message in the given session.
func (r *AssistantRepository) AppendMessage(ctx context.Context, m *model.AssistantMessage) error {
if err := r.db.WithContext(ctx).Create(m).Error; err != nil {
return err
}
// Bump the parent session's updated_at so list ordering reflects activity.
return r.db.WithContext(ctx).Model(&model.AssistantSession{}).
Where("id = ?", m.SessionID).Update("updated_at", time.Now()).Error
}
// ListMessages returns the transcript ordered by creation time.
func (r *AssistantRepository) ListMessages(ctx context.Context, sessionID string) ([]model.AssistantMessage, error) {
var rows []model.AssistantMessage
err := r.db.WithContext(ctx).Where("session_id = ?", sessionID).
Order("created_at asc").Find(&rows).Error
return rows, err
}