diff --git a/bootstrap/account.go b/bootstrap/account.go new file mode 100644 index 00000000..d799b733 --- /dev/null +++ b/bootstrap/account.go @@ -0,0 +1,30 @@ +package bootstrap + +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/drivers" + "github.com/Xhofe/alist/model" + log "github.com/sirupsen/logrus" +) + +func InitAccounts() { + log.Infof("init accounts...") + var accounts []model.Account + if err := conf.DB.Find(&accounts).Error; err != nil { + log.Fatalf("failed sync init accounts") + } + for i, account := range accounts { + model.RegisterAccount(account) + driver, ok := drivers.GetDriver(account.Type) + if !ok { + log.Errorf("no [%s] driver", driver) + } else { + err := driver.Save(&accounts[i], nil) + if err != nil { + log.Errorf("init account [%s] error:[%s]", account.Name, err.Error()) + } else { + log.Infof("success init account: %s, type: %s", account.Name, account.Type) + } + } + } +} \ No newline at end of file diff --git a/bootstrap/model.go b/bootstrap/model.go index 65c44879..d7687ea0 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -3,7 +3,6 @@ package bootstrap import ( "fmt" "github.com/Xhofe/alist/conf" - "github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/model" log "github.com/sirupsen/logrus" "gorm.io/driver/mysql" @@ -79,152 +78,3 @@ func InitModel() { } } -func InitAccounts() { - log.Infof("init accounts...") - var accounts []model.Account - if err := conf.DB.Find(&accounts).Error; err != nil { - log.Fatalf("failed sync init accounts") - } - for i, account := range accounts { - model.RegisterAccount(account) - driver, ok := drivers.GetDriver(account.Type) - if !ok { - log.Errorf("no [%s] driver", driver) - } else { - err := driver.Save(&accounts[i], nil) - if err != nil { - log.Errorf("init account [%s] error:[%s]", account.Name, err.Error()) - } else { - log.Infof("success init account: %s, type: %s", account.Name, account.Type) - } - } - } -} - -func InitSettings() { - log.Infof("init settings...") - version := model.SettingItem{ - Key: "version", - Value: conf.GitTag, - Description: "version", - Type: "string", - Group: model.CONST, - } - - _ = model.SaveSetting(version) - - settings := []model.SettingItem{ - { - Key: "title", - Value: "Alist", - Description: "title", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "password", - Value: "alist", - Description: "password", - Type: "string", - Group: model.PRIVATE, - }, - { - Key: "logo", - Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", - Description: "logo", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "favicon", - Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", - Description: "favicon", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "icon color", - Value: "teal.300", - Description: "icon's color", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "text types", - Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp", - Type: "string", - Description: "text type extensions", - }, - { - Key: "hide readme file", - Value: "true", - Type: "bool", - Description: "hide readme file? ", - }, - { - Key: "music cover", - Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", - Description: "music cover image", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "site beian", - Description: "chinese beian info", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "home readme url", - Description: "when have multiple, the readme file to show", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "markdown theme", - Value: "vuepress", - Description: "default | github | vuepress", - Group: model.PUBLIC, - Type: "select", - Values: "default,github,vuepress", - }, - { - Key: "autoplay video", - Value: "false", - Type: "bool", - }, - { - Key: "autoplay audio", - Value: "false", - Type: "bool", - }, - { - Key: "check parent folder", - Value: "false", - Type: "bool", - Description: "check parent folder password", - }, - { - Key: "customize style", - Value: "", - Type: "text", - Description: "customize style, don't need add ", - }, - { - Key: "customize script", - Value: "", - Type: "text", - Description: "customize script, don't need add ", - }, - } - for _, v := range settings { - _, err := model.GetSettingByKey(v.Key) - if err == gorm.ErrRecordNotFound { - err = model.SaveSetting(v) - if err != nil { - log.Fatalf("failed write setting: %s", err.Error()) - } - } - } - model.LoadSettings() -} diff --git a/bootstrap/setting.go b/bootstrap/setting.go new file mode 100644 index 00000000..567b0e21 --- /dev/null +++ b/bootstrap/setting.go @@ -0,0 +1,142 @@ +package bootstrap + +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/model" + log "github.com/sirupsen/logrus" + "gorm.io/gorm" +) + +func InitSettings() { + log.Infof("init settings...") + version := model.SettingItem{ + Key: "version", + Value: conf.GitTag, + Description: "version", + Type: "string", + Group: model.CONST, + } + + _ = model.SaveSetting(version) + + settings := []model.SettingItem{ + { + Key: "title", + Value: "Alist", + Description: "title", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "password", + Value: "alist", + Description: "password", + Type: "string", + Group: model.PRIVATE, + }, + { + Key: "logo", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Description: "logo", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "favicon", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Description: "favicon", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "icon color", + Value: "teal.300", + Description: "icon's color", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "text types", + Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp", + Type: "string", + Description: "text type extensions", + }, + { + Key: "hide readme file", + Value: "true", + Type: "bool", + Description: "hide readme file? ", + }, + { + Key: "music cover", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Description: "music cover image", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "site beian", + Description: "chinese beian info", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "home readme url", + Description: "when have multiple, the readme file to show", + Type: "string", + Group: model.PUBLIC, + }, + { + Key: "markdown theme", + Value: "vuepress", + Description: "default | github | vuepress", + Group: model.PUBLIC, + Type: "select", + Values: "default,github,vuepress", + }, + { + Key: "autoplay video", + Value: "false", + Type: "bool", + }, + { + Key: "autoplay audio", + Value: "false", + Type: "bool", + }, + { + Key: "check parent folder", + Value: "false", + Type: "bool", + Description: "check parent folder password", + }, + { + Key: "customize style", + Value: "", + Type: "text", + Description: "customize style, don't need add ", + }, + { + Key: "customize script", + Value: "", + Type: "text", + Description: "customize script, don't need add ", + }, + { + Key: "animation", + Value: "true", + Type: "bool", + Description: "when there are a lot of files, the animation will freeze when opening", + }, + } + for _, v := range settings { + _, err := model.GetSettingByKey(v.Key) + if err == gorm.ErrRecordNotFound { + err = model.SaveSetting(v) + if err != nil { + log.Fatalf("failed write setting: %s", err.Error()) + } + } + } + model.LoadSettings() +} \ No newline at end of file diff --git a/drivers/189.go b/drivers/189.go index 8cbf3e8b..45090715 100644 --- a/drivers/189.go +++ b/drivers/189.go @@ -29,6 +29,13 @@ var client189Map map[string]*resty.Client func (c Cloud189) Items() []Item { return []Item{ + { + Name: "proxy", + Label: "proxy", + Type: "bool", + Required: true, + Description: "allow proxy", + }, { Name: "username", Label: "username", @@ -224,6 +231,9 @@ func (c Cloud189) Link(path string, account *model.Account) (string, error) { return "", fmt.Errorf(resp.ResMessage) } res, err := noRedirectClient.R().Get(resp.FileDownloadUrl) + if err != nil { + return "", err + } if res.StatusCode() == 302 { return res.Header().Get("location"), nil } diff --git a/drivers/alidrive.go b/drivers/alidrive.go index c9a7db79..72aba422 100644 --- a/drivers/alidrive.go +++ b/drivers/alidrive.go @@ -67,6 +67,13 @@ func (a AliDrive) Preview(path string, account *model.Account) (interface{}, err func (a AliDrive) Items() []Item { return []Item{ + { + Name: "proxy", + Label: "proxy", + Type: "bool", + Required: true, + Description: "allow proxy", + }, { Name: "order_by", Label: "order_by", diff --git a/drivers/native.go b/drivers/native.go index 5f0a272a..797b0458 100644 --- a/drivers/native.go +++ b/drivers/native.go @@ -43,6 +43,7 @@ func (n Native) Save(account *model.Account, old *model.Account) error { return fmt.Errorf("[%s] not exist", account.RootFolder) } account.Status = "work" + account.Proxy = true err := model.SaveAccount(account) if err != nil { return err diff --git a/drivers/onedrive.go b/drivers/onedrive.go index 54f3c620..9f8c708e 100644 --- a/drivers/onedrive.go +++ b/drivers/onedrive.go @@ -77,6 +77,13 @@ func (o Onedrive) GetMetaUrl(account *model.Account, auth bool, path string) str func (o Onedrive) Items() []Item { return []Item{ + { + Name: "proxy", + Label: "proxy", + Type: "bool", + Required: true, + Description: "allow proxy", + }, { Name: "zone", Label: "zone", diff --git a/server/down.go b/server/down.go index 9ece4f6f..3b6d028b 100644 --- a/server/down.go +++ b/server/down.go @@ -26,6 +26,10 @@ func Down(c *gin.Context) { ErrorResp(c, err, 500) return } + if account.Type == "GoogleDrive" { + Proxy(c) + return + } link, err := driver.Link(path, account) if err != nil { ErrorResp(c, err, 500) @@ -70,7 +74,7 @@ func Proxy(c *gin.Context) { Text(c, link) return } - driver.Proxy(c) + driver.Proxy(c,account) r := c.Request w := c.Writer target, err := url.Parse(link)