增加基础设置页面
This commit is contained in:
+3
-6
@@ -226,12 +226,9 @@ func GetOptionsByUser(db *gorm.DB, userID uint) (map[string]string, error) {
|
||||
func BatchSetOptions(db *gorm.DB, userID uint, options map[string]string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
for name, value := range options {
|
||||
opt := Option{
|
||||
Name: name,
|
||||
UserID: userID,
|
||||
Value: value,
|
||||
}
|
||||
if err := tx.Save(&opt).Error; err != nil {
|
||||
// 复合主键在 SQLite 旧表上可能缺失唯一约束,Save 会重复插入,
|
||||
// 改用查找-更新-不存在才插入的方式保证幂等
|
||||
if err := SetOptionValue(tx, name, userID, value); err != nil {
|
||||
slog.Error("保存配置失败", "name", name, "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user