-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af9c6af
commit 1896e44
Showing
16 changed files
with
197 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package data | ||
|
||
import ( | ||
"github.com/alist-org/alist/v3/internal/db" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
) | ||
|
||
var initialTaskItems []model.TaskItem | ||
|
||
func initTasks() { | ||
InitialTasks() | ||
|
||
for i := range initialTaskItems { | ||
item := &initialTaskItems[i] | ||
taskitem, _ := db.GetTaskDataByType(item.Key) | ||
if taskitem == nil { | ||
db.CreateTaskData(item) | ||
} | ||
} | ||
} | ||
|
||
func InitialTasks() []model.TaskItem { | ||
initialTaskItems = []model.TaskItem{ | ||
{Key: "copy", PersistData: "[]"}, | ||
{Key: "download", PersistData: "[]"}, | ||
{Key: "transfer", PersistData: "[]"}, | ||
} | ||
return initialTaskItems | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package db | ||
|
||
import ( | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func GetTaskDataByType(type_s string) (*model.TaskItem, error) { | ||
task := model.TaskItem{Key: type_s} | ||
if err := db.Where(task).First(&task).Error; err != nil { | ||
return nil, errors.Wrapf(err, "failed find task") | ||
} | ||
return &task, nil | ||
} | ||
|
||
func UpdateTaskData(t *model.TaskItem) error { | ||
return errors.WithStack(db.Model(&model.TaskItem{}).Where("key = ?", t.Key).Update("persist_data", t.PersistData).Error) | ||
} | ||
|
||
func CreateTaskData(t *model.TaskItem) error { | ||
return errors.WithStack(db.Create(t).Error) | ||
} | ||
|
||
func GetTaskDataFunc(type_s string, enabled bool) func() ([]byte, error) { | ||
if !enabled { | ||
return func() ([]byte, error) { | ||
return []byte("[]"), nil | ||
} | ||
} | ||
task, err := GetTaskDataByType(type_s) | ||
if err != nil { | ||
return nil | ||
} | ||
return func() ([]byte, error) { | ||
return []byte(task.PersistData), nil | ||
} | ||
} | ||
|
||
func UpdateTaskDataFunc(type_s string, enabled bool) func([]byte) error { | ||
if !enabled { | ||
return func([]byte) error { | ||
return nil | ||
} | ||
} | ||
return func(data []byte) error { | ||
s := string(data) | ||
if s == "null" || s == "" { | ||
s = "[]" | ||
} | ||
return UpdateTaskData(&model.TaskItem{Key: type_s, PersistData: s}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package model | ||
|
||
type TaskItem struct { | ||
Key string `json:"key"` | ||
PersistData string `gorm:"type:text" json:"persist_data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.