feat: frontend group folder configure page
This commit is contained in:
parent
2165c03c9d
commit
5132d2139b
1 changed files with 68 additions and 13 deletions
|
@ -24,19 +24,21 @@ type Group struct {
|
|||
|
||||
// GroupOption 用户组其他配置
|
||||
type GroupOption struct {
|
||||
ArchiveDownload bool `json:"archive_download,omitempty"` // 打包下载
|
||||
ArchiveTask bool `json:"archive_task,omitempty"` // 在线压缩
|
||||
CompressSize uint64 `json:"compress_size,omitempty"` // 可压缩大小
|
||||
DecompressSize uint64 `json:"decompress_size,omitempty"`
|
||||
OneTimeDownload bool `json:"one_time_download,omitempty"`
|
||||
ShareDownload bool `json:"share_download,omitempty"`
|
||||
Aria2 bool `json:"aria2,omitempty"` // 离线下载
|
||||
Aria2Options map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
|
||||
SourceBatchSize int `json:"source_batch,omitempty"`
|
||||
RedirectedSource bool `json:"redirected_source,omitempty"`
|
||||
Aria2BatchSize int `json:"aria2_batch,omitempty"`
|
||||
AdvanceDelete bool `json:"advance_delete,omitempty"`
|
||||
WebDAVProxy bool `json:"webdav_proxy,omitempty"`
|
||||
ArchiveDownload bool `json:"archive_download,omitempty"` // 打包下载
|
||||
ArchiveTask bool `json:"archive_task,omitempty"` // 在线压缩
|
||||
CompressSize uint64 `json:"compress_size,omitempty"` // 可压缩大小
|
||||
DecompressSize uint64 `json:"decompress_size,omitempty"`
|
||||
OneTimeDownload bool `json:"one_time_download,omitempty"`
|
||||
ShareDownload bool `json:"share_download,omitempty"`
|
||||
Aria2 bool `json:"aria2,omitempty"` // 离线下载
|
||||
Aria2Options map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
|
||||
SourceBatchSize int `json:"source_batch,omitempty"`
|
||||
RedirectedSource bool `json:"redirected_source,omitempty"`
|
||||
Aria2BatchSize int `json:"aria2_batch,omitempty"`
|
||||
AdvanceDelete bool `json:"advance_delete,omitempty"`
|
||||
WebDAVProxy bool `json:"webdav_proxy,omitempty"`
|
||||
GroupFolderEnabled bool `json:"group_folder_enabled,omitempty"`
|
||||
GroupFolder string `json:"group_folder,omitempty"`
|
||||
}
|
||||
|
||||
// GetGroupByID 用ID获取用户组
|
||||
|
@ -70,6 +72,21 @@ func (group *Group) BeforeSave() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func (group *Group) AfterSave() (err error) {
|
||||
err = json.Unmarshal([]byte(group.Options), &group.OptionsSerialized)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if group.OptionsSerialized.GroupFolderEnabled {
|
||||
err = group.createGroupFolder(group.OptionsSerialized.GroupFolder)
|
||||
} else {
|
||||
err = group.deleteGroupFolder()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SerializePolicyList 将序列后的可选策略列表、配置写入数据库字段
|
||||
// TODO 完善测试
|
||||
func (group *Group) SerializePolicyList() (err error) {
|
||||
|
@ -89,3 +106,41 @@ func (group *Group) getGroupFolder() (*Folder, bool) {
|
|||
result := DB.Where("owner_id = ?", -int(group.ID)).First(&folder)
|
||||
return &folder, !result.RecordNotFound()
|
||||
}
|
||||
|
||||
// createGroupFolder 创建用户组文件夹,如果已存在则更新
|
||||
func (group *Group) createGroupFolder(name string) error {
|
||||
tx := DB.Begin()
|
||||
folder, ok := group.getGroupFolder()
|
||||
if !ok {
|
||||
folder = &Folder{
|
||||
OwnerID: -int(group.ID),
|
||||
Name: name,
|
||||
}
|
||||
if err := tx.Create(folder).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
folder.Name = name
|
||||
if err := tx.Save(folder).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
group.GroupFolder = folder
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
// deleteGroupFolder 删除用户组文件夹
|
||||
func (group *Group) deleteGroupFolder() error {
|
||||
tx := DB.Begin()
|
||||
var folder Folder
|
||||
if err := tx.Where("owner_id = ?", -int(group.ID)).First(&folder).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tx.Delete(&folder).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue