mirror of
https://github.com/AlistGo/alist.git
synced 2025-06-05 18:04:39 +08:00
chore: rename account to storage
This commit is contained in:
@ -11,58 +11,58 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func ListAccounts(c *gin.Context) {
|
||||
func ListStorages(c *gin.Context) {
|
||||
var req common.PageReq
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
log.Debugf("%+v", req)
|
||||
accounts, total, err := db.GetAccounts(req.PageIndex, req.PageSize)
|
||||
storages, total, err := db.GetStorages(req.PageIndex, req.PageSize)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, common.PageResp{
|
||||
Content: accounts,
|
||||
Content: storages,
|
||||
Total: total,
|
||||
})
|
||||
}
|
||||
|
||||
func CreateAccount(c *gin.Context) {
|
||||
var req model.Account
|
||||
func CreateStorage(c *gin.Context) {
|
||||
var req model.Storage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := operations.CreateAccount(c, req); err != nil {
|
||||
if err := operations.CreateStorage(c, req); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateAccount(c *gin.Context) {
|
||||
var req model.Account
|
||||
func UpdateStorage(c *gin.Context) {
|
||||
var req model.Storage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := operations.UpdateAccount(c, req); err != nil {
|
||||
if err := operations.UpdateStorage(c, req); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteAccount(c *gin.Context) {
|
||||
func DeleteStorage(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := operations.DeleteAccountById(c, uint(id)); err != nil {
|
||||
if err := operations.DeleteStorageById(c, uint(id)); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ import (
|
||||
func Down(c *gin.Context) {
|
||||
rawPath := c.MustGet("path").(string)
|
||||
filename := stdpath.Base(rawPath)
|
||||
account, err := fs.GetAccount(rawPath)
|
||||
storage, err := fs.GetStorage(rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if shouldProxy(account, filename) {
|
||||
if shouldProxy(storage, filename) {
|
||||
Proxy(c)
|
||||
return
|
||||
} else {
|
||||
@ -43,13 +43,13 @@ func Down(c *gin.Context) {
|
||||
func Proxy(c *gin.Context) {
|
||||
rawPath := c.MustGet("path").(string)
|
||||
filename := stdpath.Base(rawPath)
|
||||
account, err := fs.GetAccount(rawPath)
|
||||
storage, err := fs.GetStorage(rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if canProxy(account, filename) {
|
||||
downProxyUrl := account.GetAccount().DownProxyUrl
|
||||
if canProxy(storage, filename) {
|
||||
downProxyUrl := storage.GetStorage().DownProxyUrl
|
||||
if downProxyUrl != "" {
|
||||
_, ok := c.GetQuery("d")
|
||||
if ok {
|
||||
@ -79,10 +79,10 @@ func Proxy(c *gin.Context) {
|
||||
// TODO need optimize
|
||||
// when should be proxy?
|
||||
// 1. config.MustProxy()
|
||||
// 2. account.WebProxy
|
||||
// 2. storage.WebProxy
|
||||
// 3. proxy_types
|
||||
func shouldProxy(account driver.Driver, filename string) bool {
|
||||
if account.Config().MustProxy() || account.GetAccount().WebProxy {
|
||||
func shouldProxy(storage driver.Driver, filename string) bool {
|
||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
||||
return true
|
||||
}
|
||||
proxyTypes := setting.GetByKey(conf.ProxyTypes)
|
||||
@ -96,11 +96,11 @@ func shouldProxy(account driver.Driver, filename string) bool {
|
||||
// when can be proxy?
|
||||
// 1. text file
|
||||
// 2. config.MustProxy()
|
||||
// 3. account.WebProxy
|
||||
// 3. storage.WebProxy
|
||||
// 4. proxy_types
|
||||
// solution: text_file + shouldProxy()
|
||||
func canProxy(account driver.Driver, filename string) bool {
|
||||
if account.Config().MustProxy() || account.GetAccount().WebProxy {
|
||||
func canProxy(storage driver.Driver, filename string) bool {
|
||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
||||
return true
|
||||
}
|
||||
proxyTypes := setting.GetByKey(conf.ProxyTypes)
|
||||
|
@ -237,12 +237,12 @@ func Link(c *gin.Context) {
|
||||
}
|
||||
user := c.MustGet("user").(*model.User)
|
||||
rawPath := stdpath.Join(user.BasePath, req.Path)
|
||||
account, err := fs.GetAccount(rawPath)
|
||||
storage, err := fs.GetStorage(rawPath)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
if account.Config().OnlyLocal {
|
||||
if storage.Config().OnlyLocal {
|
||||
common.SuccessResp(c, model.Link{
|
||||
URL: fmt.Sprintf("%s/p%s?d&sign=%s", common.GetBaseUrl(c.Request), req.Path, sign.Sign(stdpath.Base(rawPath))),
|
||||
})
|
||||
|
@ -218,16 +218,16 @@ func FsGet(c *gin.Context) {
|
||||
if u, ok := obj.(model.URL); ok {
|
||||
rawURL = u.URL()
|
||||
} else {
|
||||
account, _ := fs.GetAccount(req.Path)
|
||||
if account.Config().MustProxy() || account.GetAccount().WebProxy {
|
||||
if account.GetAccount().DownProxyUrl != "" {
|
||||
rawURL = fmt.Sprintf("%s%s?sign=%s", strings.Split(account.GetAccount().DownProxyUrl, "\n")[0], req.Path, sign.Sign(obj.GetName()))
|
||||
storage, _ := fs.GetStorage(req.Path)
|
||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
||||
if storage.GetStorage().DownProxyUrl != "" {
|
||||
rawURL = fmt.Sprintf("%s%s?sign=%s", strings.Split(storage.GetStorage().DownProxyUrl, "\n")[0], req.Path, sign.Sign(obj.GetName()))
|
||||
} else {
|
||||
rawURL = fmt.Sprintf("%s/p%s?sign=%s", common.GetBaseUrl(c.Request), req.Path, sign.Sign(obj.GetName()))
|
||||
}
|
||||
} else {
|
||||
// if account is not proxy, use raw url by fs.Link
|
||||
link, _, err := fs.Link(c, req.Path, model.LinkArgs{})
|
||||
// if storage is not proxy, use raw url by fs.Link
|
||||
link, _, err := fs.Link(c, req.Path, model.LinkArgs{IP: c.ClientIP()})
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
|
@ -37,11 +37,11 @@ func Init(r *gin.Engine) {
|
||||
user.POST("/update", controllers.UpdateUser)
|
||||
user.POST("/delete", controllers.DeleteUser)
|
||||
|
||||
account := admin.Group("/account")
|
||||
account.GET("/list", controllers.ListAccounts)
|
||||
account.POST("/create", controllers.CreateAccount)
|
||||
account.POST("/update", controllers.UpdateAccount)
|
||||
account.POST("/delete", controllers.DeleteAccount)
|
||||
storage := admin.Group("/storage")
|
||||
storage.GET("/list", controllers.ListStorages)
|
||||
storage.POST("/create", controllers.CreateStorage)
|
||||
storage.POST("/update", controllers.UpdateStorage)
|
||||
storage.POST("/delete", controllers.DeleteStorage)
|
||||
|
||||
driver := admin.Group("/driver")
|
||||
driver.GET("/list", controllers.ListDriverItems)
|
||||
|
@ -216,8 +216,8 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
|
||||
}
|
||||
w.Header().Set("ETag", etag)
|
||||
// Let ServeContent determine the Content-Type header.
|
||||
account, _ := fs.GetAccount(reqPath)
|
||||
if account.GetAccount().WebdavNative() {
|
||||
storage, _ := fs.GetStorage(reqPath)
|
||||
if storage.GetStorage().WebdavNative() {
|
||||
link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{Header: r.Header})
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
@ -226,7 +226,7 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
} else if account.Config().MustProxy() || account.GetAccount().WebdavProxy() {
|
||||
} else if storage.Config().MustProxy() || storage.GetStorage().WebdavProxy() {
|
||||
u := fmt.Sprintf("%s/p%s?sign=%s", common.GetBaseUrl(r), reqPath, sign.Sign(path.Base(reqPath)))
|
||||
http.Redirect(w, r, u, 302)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user