chore: remove license code, fix compilation, update README bilingual

- Remove all license-related code (handler/service/repository/model)
  License authorization is managed by separate server:
  https://github.com/ShukeBta/MediaStationLicenseServer
- Fix compilation errors: model field alignment, method name fixes,
  route conflicts, struct literal corrections (7 files)
- Add Chinese README.md as primary, English README_EN.md
- Update .gitignore: exclude .workbuddy/, editor backups
- Add new repository files: assistant, play_profile, storage_config
This commit is contained in:
ShukeBta
2026-05-17 00:02:41 +08:00
parent 37dd83c56d
commit 8e06b7e149
30 changed files with 756 additions and 1625 deletions
+64
View File
@@ -0,0 +1,64 @@
package repository
import (
"context"
"errors"
"gorm.io/gorm"
"github.com/ShukeBta/MediaStationGo/internal/model"
)
// AssistantRepository persists model.AssistantSession + AssistantMessage records.
type AssistantRepository struct{ db *gorm.DB }
// ─── Session ────────────────────────────────────────────────────────────
// CreateSession inserts a new chat session.
func (r *AssistantRepository) CreateSession(ctx context.Context, s *model.AssistantSession) error {
return r.db.WithContext(ctx).Create(s).Error
}
// FindSession returns a session by ID, or (nil, nil).
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 a user, or all when userID is empty.
func (r *AssistantRepository) ListSessions(ctx context.Context, userID string) ([]model.AssistantSession, error) {
q := r.db.WithContext(ctx).Model(&model.AssistantSession{})
if userID != "" {
q = q.Where("user_id = ?", userID)
}
var rows []model.AssistantSession
err := q.Order("created_at desc").Find(&rows).Error
return rows, err
}
// DeleteSession soft-deletes a session (cascade handled by GORM hooks if set).
func (r *AssistantRepository) DeleteSession(ctx context.Context, id string) error {
return r.db.WithContext(ctx).Delete(&model.AssistantSession{}, "id = ?", id).Error
}
// ─── Message ────────────────────────────────────────────────────────────
// AppendMessage inserts a new message into a session.
func (r *AssistantRepository) AppendMessage(ctx context.Context, m *model.AssistantMessage) error {
return r.db.WithContext(ctx).Create(m).Error
}
// ListMessages returns all messages for a session in chronological order.
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
}
+63
View File
@@ -0,0 +1,63 @@
package repository
import (
"context"
"errors"
"gorm.io/gorm"
"github.com/ShukeBta/MediaStationGo/internal/model"
)
// PlayProfileRepository persists model.PlayProfile records.
type PlayProfileRepository struct{ db *gorm.DB }
// Create inserts a new play profile.
func (r *PlayProfileRepository) Create(ctx context.Context, p *model.PlayProfile) error {
return r.db.WithContext(ctx).Create(p).Error
}
// FindByID returns the profile or (nil, nil).
func (r *PlayProfileRepository) FindByID(ctx context.Context, id string) (*model.PlayProfile, error) {
var p model.PlayProfile
err := r.db.WithContext(ctx).Where("id = ?", id).First(&p).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &p, nil
}
// List returns every profile (admin view).
func (r *PlayProfileRepository) List(ctx context.Context) ([]model.PlayProfile, error) {
var rows []model.PlayProfile
err := r.db.WithContext(ctx).Order("created_at desc").Find(&rows).Error
return rows, err
}
// ListByUser returns profiles owned by a user.
func (r *PlayProfileRepository) ListByUser(ctx context.Context, userID string) ([]model.PlayProfile, error) {
var rows []model.PlayProfile
err := r.db.WithContext(ctx).Where("user_id = ?", userID).
Order("created_at desc").Find(&rows).Error
return rows, err
}
// Update applies a partial update to a profile row.
func (r *PlayProfileRepository) Update(ctx context.Context, id string, patch map[string]any) error {
return r.db.WithContext(ctx).Model(&model.PlayProfile{}).
Where("id = ?", id).Updates(patch).Error
}
// Delete soft-deletes a profile.
func (r *PlayProfileRepository) Delete(ctx context.Context, id string) error {
return r.db.WithContext(ctx).Delete(&model.PlayProfile{}, "id = ?", id).Error
}
// ClearDefaultsFor resets is_default for all of a user's profiles.
func (r *PlayProfileRepository) ClearDefaultsFor(ctx context.Context, userID string) error {
return r.db.WithContext(ctx).Model(&model.PlayProfile{}).
Where("user_id = ?", userID).Update("is_default", false).Error
}
+6
View File
@@ -38,6 +38,9 @@ type Container struct {
NotifyChannel *NotifyChannelRepository
Site *SiteRepository
STRM *STRMRepository
PlayProfile *PlayProfileRepository
StorageConfig *StorageConfigRepository
Assistant *AssistantRepository
}
// New 将每个 repository 连接到单个 *gorm.DB。
@@ -62,6 +65,9 @@ func New(db *gorm.DB) *Container {
NotifyChannel: &NotifyChannelRepository{db: db},
Site: &SiteRepository{db: db},
STRM: &STRMRepository{db: db},
PlayProfile: &PlayProfileRepository{db: db},
StorageConfig: &StorageConfigRepository{db: db},
Assistant: &AssistantRepository{db: db},
}
}
@@ -0,0 +1,39 @@
package repository
import (
"context"
"errors"
"gorm.io/gorm"
"github.com/ShukeBta/MediaStationGo/internal/model"
)
// StorageConfigRepository persists model.StorageConfig records.
type StorageConfigRepository struct{ db *gorm.DB }
// Get returns the config row by type, or (nil, nil).
func (r *StorageConfigRepository) Get(ctx context.Context, kind string) (*model.StorageConfig, error) {
var c model.StorageConfig
err := r.db.WithContext(ctx).Where("type = ?", kind).First(&c).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
if err != nil {
return nil, err
}
return &c, nil
}
// List returns all storage configs.
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
}
// Upsert creates or replaces a storage config keyed by Type.
func (r *StorageConfigRepository) Upsert(ctx context.Context, c *model.StorageConfig) error {
return r.db.WithContext(ctx).Where("type = ?", c.Type).
Assign(*c).FirstOrCreate(c).Error
}