mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-27 18:11:57 +08:00
Feat: creat uri aria2 download task
This commit is contained in:
@@ -10,9 +10,10 @@ type Download struct {
|
||||
gorm.Model
|
||||
Status int // 任务状态
|
||||
Type int // 任务类型
|
||||
Source string // 文件下载地址
|
||||
Name string // 任务文件名
|
||||
Size uint64 // 文件大小
|
||||
PID string // 任务ID
|
||||
GID string // 任务ID
|
||||
Path string `gorm:"type:text"` // 存储路径
|
||||
Attrs string `gorm:"type:text"` // 任务状态属性
|
||||
FolderID uint // 存储父目录ID
|
||||
|
||||
@@ -25,13 +25,14 @@ 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"`
|
||||
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"`
|
||||
ShareFree bool `json:"share_free,omitempty"`
|
||||
Aria2 bool `json:"aria2,omitempty"` // 离线下载
|
||||
}
|
||||
|
||||
// GetAria2Option 获取用户离线下载设备
|
||||
|
||||
@@ -29,7 +29,8 @@ func migration() {
|
||||
if conf.DatabaseConfig.Type == "mysql" {
|
||||
DB = DB.Set("gorm:table_options", "ENGINE=InnoDB")
|
||||
}
|
||||
DB.AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{}, &StoragePack{}, &Share{}, &Task{})
|
||||
DB.AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{}, &StoragePack{}, &Share{},
|
||||
&Task{}, &Download{})
|
||||
|
||||
// 创建初始存储策略
|
||||
addDefaultPolicy()
|
||||
@@ -110,6 +111,7 @@ solid #e9e9e9;"bgcolor="#fff"><tbody><tr style="font-family: 'Helvetica Neue',He
|
||||
{Name: "onedrive_monitor_timeout", Value: `600`, Type: "timeout"},
|
||||
{Name: "share_download_session_timeout", Value: `2073600`, Type: "timeout"},
|
||||
{Name: "onedrive_callback_check", Value: `20`, Type: "timeout"},
|
||||
{Name: "aria2_call_timeout", Value: `5`, Type: "timeout"},
|
||||
{Name: "onedrive_chunk_retries", Value: `1`, Type: "retry"},
|
||||
{Name: "allowdVisitorDownload", Value: `false`, Type: "share"},
|
||||
{Name: "login_captcha", Value: `0`, Type: "login"},
|
||||
@@ -155,9 +157,9 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti
|
||||
{Name: "themes", Value: `{"#3f51b5":{"palette":{"primary":{"light":"#7986cb","main":"#3f51b5","dark":"#303f9f","contrastText":"#fff"},"secondary":{"light":"#ff4081","main":"#f50057","dark":"#c51162","contrastText":"#fff"},"error":{"light":"#e57373","main":"#f44336","dark":"#d32f2f","contrastText":"#fff"},"explorer":{"filename":"#474849","icon":"#8f8f8f","bgSelected":"#D5DAF0","emptyIcon":"#e8e8e8"}}}}`, Type: "basic"},
|
||||
{Name: "refererCheck", Value: `true`, Type: "share"},
|
||||
{Name: "header", Value: `X-Sendfile`, Type: "download"},
|
||||
{Name: "aria2_tmppath", Value: `/path/to/public/download`, Type: "aria2"},
|
||||
{Name: "aria2_token", Value: `your token`, Type: "aria2"},
|
||||
{Name: "aria2_rpcurl", Value: `http://127.0.0.1:6800/`, Type: "aria2"},
|
||||
{Name: "aria2_token", Value: `your token`, Type: "aria2"},
|
||||
{Name: "aria2_temp_path", Value: `F:\aria2-1.33.1-win-64bit-build1\temp`, Type: "aria2"},
|
||||
{Name: "aria2_options", Value: `{"max-tries":5}`, Type: "aria2"},
|
||||
{Name: "max_worker_num", Value: `10`, Type: "task"},
|
||||
{Name: "max_parallel_transfer", Value: `4`, Type: "task"},
|
||||
|
||||
@@ -39,7 +39,7 @@ func GetSettingByName(name string) string {
|
||||
}
|
||||
|
||||
// GetSettingByNames 用多个 Name 获取设置值
|
||||
func GetSettingByNames(names []string) map[string]string {
|
||||
func GetSettingByNames(names ...string) map[string]string {
|
||||
var queryRes []Setting
|
||||
res, miss := cache.GetSettings(names, "setting_")
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestGetSettingByNames(t *testing.T) {
|
||||
AddRow("siteName", "Cloudreve", "basic").
|
||||
AddRow("siteDes", "Something wonderful", "basic")
|
||||
mock.ExpectQuery("^SELECT \\* FROM `(.+)` WHERE `(.+)`\\.`deleted_at` IS NULL AND(.+)$").WillReturnRows(rows)
|
||||
settings := GetSettingByNames([]string{"siteName", "siteDes"})
|
||||
settings := GetSettingByNames("siteName", "siteDes")
|
||||
asserts.Equal(map[string]string{
|
||||
"siteName": "Cloudreve",
|
||||
"siteDes": "Something wonderful",
|
||||
@@ -78,7 +78,7 @@ func TestGetSettingByNames(t *testing.T) {
|
||||
rows = sqlmock.NewRows([]string{"name", "value", "type"}).
|
||||
AddRow("siteName2", "Cloudreve", "basic")
|
||||
mock.ExpectQuery("^SELECT \\* FROM `(.+)` WHERE `(.+)`\\.`deleted_at` IS NULL AND(.+)$").WillReturnRows(rows)
|
||||
settings = GetSettingByNames([]string{"siteName2", "siteDes2333"})
|
||||
settings = GetSettingByNames("siteName2", "siteDes2333")
|
||||
asserts.Equal(map[string]string{
|
||||
"siteName2": "Cloudreve",
|
||||
}, settings)
|
||||
@@ -87,14 +87,14 @@ func TestGetSettingByNames(t *testing.T) {
|
||||
//找不到设置时
|
||||
rows = sqlmock.NewRows([]string{"name", "value", "type"})
|
||||
mock.ExpectQuery("^SELECT \\* FROM `(.+)` WHERE `(.+)`\\.`deleted_at` IS NULL AND(.+)$").WillReturnRows(rows)
|
||||
settings = GetSettingByNames([]string{"siteName2333", "siteDes2333"})
|
||||
settings = GetSettingByNames("siteName2333", "siteDes2333")
|
||||
asserts.Equal(map[string]string{}, settings)
|
||||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
|
||||
// 一个设置命中缓存
|
||||
mock.ExpectQuery("^SELECT \\* FROM `(.+)` WHERE `(.+)`\\.`deleted_at` IS NULL AND(.+)$").WithArgs("siteDes2").WillReturnRows(sqlmock.NewRows([]string{"name", "value", "type"}).
|
||||
AddRow("siteDes2", "Cloudreve2", "basic"))
|
||||
settings = GetSettingByNames([]string{"siteName", "siteDes2"})
|
||||
settings = GetSettingByNames("siteName", "siteDes2")
|
||||
asserts.Equal(map[string]string{
|
||||
"siteName": "Cloudreve",
|
||||
"siteDes2": "Cloudreve2",
|
||||
|
||||
Reference in New Issue
Block a user