mirror of https://github.com/Xhofe/alist
🎇 support add another alist
parent
74d8fa3919
commit
985b81826f
|
@ -41,8 +41,9 @@ var (
|
||||||
RawIndexHtml string
|
RawIndexHtml string
|
||||||
IndexHtml string
|
IndexHtml string
|
||||||
CheckParent bool
|
CheckParent bool
|
||||||
CheckDown bool
|
CheckDown bool
|
||||||
|
|
||||||
|
Token string
|
||||||
DavUsername string
|
DavUsername string
|
||||||
DavPassword string
|
DavPassword string
|
||||||
)
|
)
|
||||||
|
|
|
@ -431,7 +431,7 @@ func (driver AliDrive) Upload(file *model.FileStream, account *model.Account) er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
res, err := base.BaseHttpClient.Do(req)
|
res, err := base.HttpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
_ "github.com/Xhofe/alist/drivers/123"
|
_ "github.com/Xhofe/alist/drivers/123"
|
||||||
_ "github.com/Xhofe/alist/drivers/189"
|
_ "github.com/Xhofe/alist/drivers/189"
|
||||||
_ "github.com/Xhofe/alist/drivers/alidrive"
|
_ "github.com/Xhofe/alist/drivers/alidrive"
|
||||||
|
_ "github.com/Xhofe/alist/drivers/alist"
|
||||||
_ "github.com/Xhofe/alist/drivers/google"
|
_ "github.com/Xhofe/alist/drivers/google"
|
||||||
_ "github.com/Xhofe/alist/drivers/lanzou"
|
_ "github.com/Xhofe/alist/drivers/lanzou"
|
||||||
_ "github.com/Xhofe/alist/drivers/native"
|
_ "github.com/Xhofe/alist/drivers/native"
|
||||||
|
|
|
@ -81,8 +81,8 @@ func GetDrivers() map[string][]Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
var NoRedirectClient *resty.Client
|
var NoRedirectClient *resty.Client
|
||||||
//var BaseClient = resty.New()
|
var RestyClient = resty.New()
|
||||||
var BaseHttpClient = &http.Client{}
|
var HttpClient = &http.Client{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
NoRedirectClient = resty.New().SetRedirectPolicy(
|
NoRedirectClient = resty.New().SetRedirectPolicy(
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -83,6 +85,11 @@ func LoadSettings() {
|
||||||
conf.IndexHtml = strings.Replace(conf.IndexHtml, "<!-- customize body -->", customizeBody.Value, 1)
|
conf.IndexHtml = strings.Replace(conf.IndexHtml, "<!-- customize body -->", customizeBody.Value, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adminPassword, err := GetSettingByKey("password")
|
||||||
|
if err == nil {
|
||||||
|
conf.Token = utils.GetMD5Encode(fmt.Sprintf("https://github.com/Xhofe/alist-%s",adminPassword.Value))
|
||||||
|
}
|
||||||
|
|
||||||
davUsername, err := GetSettingByKey("WebDAV username")
|
davUsername, err := GetSettingByKey("WebDAV username")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
conf.DavUsername = davUsername.Value
|
conf.DavUsername = davUsername.Value
|
||||||
|
|
|
@ -2,25 +2,24 @@ package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Xhofe/alist/model"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/server/common"
|
"github.com/Xhofe/alist/server/common"
|
||||||
"github.com/Xhofe/alist/utils"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Auth(c *gin.Context) {
|
func Auth(c *gin.Context) {
|
||||||
token := c.GetHeader("Authorization")
|
token := c.GetHeader("Authorization")
|
||||||
password, err := model.GetSettingByKey("password")
|
//password, err := model.GetSettingByKey("password")
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
if err == gorm.ErrRecordNotFound {
|
// if err == gorm.ErrRecordNotFound {
|
||||||
common.ErrorResp(c, fmt.Errorf("password not set"), 400)
|
// common.ErrorResp(c, fmt.Errorf("password not set"), 400)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
common.ErrorResp(c, err, 500)
|
// common.ErrorResp(c, err, 500)
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
if token != utils.GetMD5Encode(password.Value) {
|
//if token != utils.GetMD5Encode(password.Value) {
|
||||||
|
if token != conf.Token {
|
||||||
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,21 @@ package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/server/common"
|
"github.com/Xhofe/alist/server/common"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DownCheck(c *gin.Context) {
|
func DownCheck(c *gin.Context) {
|
||||||
|
sign := c.Query("sign")
|
||||||
rawPath := c.Param("path")
|
rawPath := c.Param("path")
|
||||||
rawPath = utils.ParsePath(rawPath)
|
rawPath = utils.ParsePath(rawPath)
|
||||||
|
name := utils.Base(rawPath)
|
||||||
|
if sign == utils.Get16MD5Encode(fmt.Sprintf("%s-%s", conf.Token, name)) {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
pw := c.Query("pw")
|
pw := c.Query("pw")
|
||||||
if !common.CheckDownLink(utils.Dir(rawPath), pw, utils.Base(rawPath)) {
|
if !common.CheckDownLink(utils.Dir(rawPath), pw, utils.Base(rawPath)) {
|
||||||
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
common.ErrorResp(c, fmt.Errorf("wrong password"), 401)
|
||||||
|
|
|
@ -17,6 +17,11 @@ func PathCheck(c *gin.Context) {
|
||||||
}
|
}
|
||||||
req.Path = utils.ParsePath(req.Path)
|
req.Path = utils.ParsePath(req.Path)
|
||||||
c.Set("req",req)
|
c.Set("req",req)
|
||||||
|
token := c.GetHeader("Authorization")
|
||||||
|
if token == conf.Token {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
meta, err := model.GetMetaByPath(req.Path)
|
meta, err := model.GetMetaByPath(req.Path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if meta.Password != "" && meta.Password != req.Password {
|
if meta.Password != "" && meta.Password != req.Password {
|
||||||
|
|
Loading…
Reference in New Issue