🎨 Improve the code structure

This commit is contained in:
微凉
2021-12-06 15:55:05 +08:00
parent 7dfe48339c
commit 1779617cb9
24 changed files with 212 additions and 181 deletions

View File

@ -2,7 +2,7 @@ package server
import (
"fmt"
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
@ -25,7 +25,7 @@ func CreateAccount(c *gin.Context) {
ErrorResp(c, err, 400)
return
}
driver, ok := drivers.GetDriver(req.Type)
driver, ok := base.GetDriver(req.Type)
if !ok {
ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400)
return
@ -51,7 +51,7 @@ func SaveAccount(c *gin.Context) {
ErrorResp(c, err, 400)
return
}
driver, ok := drivers.GetDriver(req.Type)
driver, ok := base.GetDriver(req.Type)
if !ok {
ErrorResp(c, fmt.Errorf("no [%s] driver", req.Type), 400)
return

View File

@ -2,7 +2,7 @@ package server
import (
"fmt"
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
@ -15,7 +15,7 @@ type Resp struct {
Data interface{} `json:"data"`
}
func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
var path, name string
switch model.AccountsCount() {
case 0:
@ -32,7 +32,7 @@ func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
if !ok {
return nil, "", nil, fmt.Errorf("no [%s] account", name)
}
driver, ok := drivers.GetDriver(account.Type)
driver, ok := base.GetDriver(account.Type)
if !ok {
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
}

View File

@ -1,10 +1,10 @@
package server
import (
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/drivers/base"
"github.com/gin-gonic/gin"
)
func GetDrivers(c *gin.Context) {
SuccessResp(c, drivers.GetDrivers())
SuccessResp(c, base.GetDrivers())
}

View File

@ -8,7 +8,7 @@ import (
"context"
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
log "github.com/sirupsen/logrus"
@ -22,7 +22,7 @@ import (
type FileSystem struct{}
func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
func ParsePath(rawPath string) (*model.Account, string, base.Driver, error) {
var path, name string
switch model.AccountsCount() {
case 0:
@ -39,7 +39,7 @@ func ParsePath(rawPath string) (*model.Account, string, drivers.Driver, error) {
if !ok {
return nil, "", nil, fmt.Errorf("no [%s] account", name)
}
driver, ok := drivers.GetDriver(account.Type)
driver, ok := base.GetDriver(account.Type)
if !ok {
return nil, "", nil, fmt.Errorf("no [%s] driver", account.Type)
}