feat: 新增配置与提示词偏好页
后端新增 preferences 与 prompt_customizations 表及对应接口, 支持 BYOK 模型渠道密钥落库(仅回显掩码)与按任务类型定制 平台提示词模板;前端新增 /settings 页面及入口。
This commit is contained in:
1 parent
ae6cdf1551
commit
b9df2f84ab
27 files changed
+1515
-22
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/ttstd/infinite-canvas/backend/internal/model"
|
||||
)
|
||||
|
||||
type PreferenceRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewPreferenceRepository(db *gorm.DB) *PreferenceRepository {
|
||||
return &PreferenceRepository{db: db}
|
||||
}
|
||||
|
||||
// Get 读取全局偏好;尚未配置过时返回一个空骨架,不写入数据库。
|
||||
func (r *PreferenceRepository) Get() (*model.Preference, error) {
|
||||
var preference model.Preference
|
||||
if err := r.db.First(&preference, "id = ?", model.PreferenceID).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return &model.Preference{ID: model.PreferenceID}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &preference, nil
|
||||
}
|
||||
|
||||
// Save 整条覆盖写入,记录不存在时创建。
|
||||
// CreatedAt 由调用方从旧记录带入,避免更新时被零值覆盖。
|
||||
func (r *PreferenceRepository) Save(preference *model.Preference) error {
|
||||
return r.db.Save(preference).Error
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/ttstd/infinite-canvas/backend/internal/model"
|
||||
)
|
||||
|
||||
type PromptRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewPromptRepository(db *gorm.DB) *PromptRepository {
|
||||
return &PromptRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *PromptRepository) List() ([]model.PromptCustomization, error) {
|
||||
var rows []model.PromptCustomization
|
||||
err := r.db.Order("created_at asc").Find(&rows).Error
|
||||
return rows, err
|
||||
}
|
||||
|
||||
func (r *PromptRepository) Get(operation string) (*model.PromptCustomization, error) {
|
||||
var customization model.PromptCustomization
|
||||
if err := r.db.First(&customization, "operation = ?", operation).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &customization, nil
|
||||
}
|
||||
|
||||
// Save 覆盖写入一条定制。调用方需保证同 operation 复用已有 ID,否则会撞唯一索引。
|
||||
func (r *PromptRepository) Save(customization *model.PromptCustomization) error {
|
||||
return r.db.Save(customization).Error
|
||||
}
|
||||
|
||||
func (r *PromptRepository) Delete(operation string) error {
|
||||
result := r.db.Delete(&model.PromptCustomization{}, "operation = ?", operation)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user