From 6591af58ea20fc808b4514cc9d55acbf94b5a213 Mon Sep 17 00:00:00 2001 From: Xhofe Date: Fri, 8 Apr 2022 21:51:21 +0800 Subject: [PATCH 1/3] feat: store search file index --- bootstrap/model.go | 4 +- drivers/123/123.go | 56 +-------------------------- drivers/123/types.go | 72 +++++++++++++++++++++++++++++++++++ drivers/189/189.go | 5 +-- drivers/189/types.go | 24 ++++++++++++ drivers/alidrive/alidrive.go | 39 +------------------ drivers/alidrive/types.go | 53 ++++++++++++++++++++++++++ drivers/base/cache.go | 34 ++++++++++++++--- drivers/google/googledrive.go | 27 +------------ drivers/google/types.go | 38 ++++++++++++++++++ drivers/lanzou/lanzou.go | 16 +------- drivers/lanzou/types.go | 34 +++++++++++++++++ drivers/native/driver.go | 4 ++ go.mod | 2 +- model/file.go | 5 +++ model/search_file.go | 35 +++++++++++++++++ server/controllers/proxy.go | 1 + 17 files changed, 304 insertions(+), 145 deletions(-) create mode 100644 drivers/123/types.go create mode 100644 drivers/alidrive/types.go create mode 100644 drivers/google/types.go create mode 100644 model/search_file.go diff --git a/bootstrap/model.go b/bootstrap/model.go index 94453e10..e199f116 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -74,9 +74,9 @@ func InitModel() { log.Infof("auto migrate model...") if databaseConfig.Type == "mysql" { err = conf.DB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4"). - AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{}) + AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{}, &model.SearchFile{}) } else { - err = conf.DB.AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{}) + err = conf.DB.AutoMigrate(&model.SettingItem{}, &model.Account{}, &model.Meta{}, &model.SearchFile{}) } if err != nil { log.Fatalf("failed to auto migrate: %s", err.Error()) diff --git a/drivers/123/123.go b/drivers/123/123.go index 027d278e..5d8ae7dc 100644 --- a/drivers/123/123.go +++ b/drivers/123/123.go @@ -12,58 +12,8 @@ import ( log "github.com/sirupsen/logrus" "path/filepath" "strconv" - "time" ) -type BaseResp struct { - Code int `json:"code"` - Message string `json:"message"` -} - -type Pan123TokenResp struct { - BaseResp - Data struct { - Token string `json:"token"` - } `json:"data"` -} - -type Pan123File struct { - FileName string `json:"FileName"` - Size int64 `json:"Size"` - UpdateAt *time.Time `json:"UpdateAt"` - FileId int64 `json:"FileId"` - Type int `json:"Type"` - Etag string `json:"Etag"` - S3KeyFlag string `json:"S3KeyFlag"` -} - -type Pan123Files struct { - BaseResp - Data struct { - InfoList []Pan123File `json:"InfoList"` - Next string `json:"Next"` - } `json:"data"` -} - -type Pan123DownResp struct { - BaseResp - Data struct { - DownloadUrl string `json:"DownloadUrl"` - } `json:"data"` -} - -type UploadResp struct { - BaseResp - Data struct { - AccessKeyId string `json:"AccessKeyId"` - Bucket string `json:"Bucket"` - Key string `json:"Key"` - SecretAccessKey string `json:"SecretAccessKey"` - SessionToken string `json:"SessionToken"` - FileId int64 `json:"FileId"` - } `json:"data"` -} - func (driver Pan123) Login(account *model.Account) error { url := "https://www.123pan.com/api/user/sign_in" if account.APIProxyUrl != "" { @@ -98,11 +48,7 @@ func (driver Pan123) FormatFile(file *Pan123File) *model.File { Driver: driver.Config().Name, UpdatedAt: file.UpdateAt, } - if file.Type == 1 { - f.Type = conf.FOLDER - } else { - f.Type = utils.GetFileType(filepath.Ext(file.FileName)) - } + f.Type = file.GetType() return f } diff --git a/drivers/123/types.go b/drivers/123/types.go new file mode 100644 index 00000000..82d66223 --- /dev/null +++ b/drivers/123/types.go @@ -0,0 +1,72 @@ +package _23 + +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/utils" + "path" + "time" +) + +type Pan123File struct { + FileName string `json:"FileName"` + Size int64 `json:"Size"` + UpdateAt *time.Time `json:"UpdateAt"` + FileId int64 `json:"FileId"` + Type int `json:"Type"` + Etag string `json:"Etag"` + S3KeyFlag string `json:"S3KeyFlag"` +} + +func (f Pan123File) GetSize() uint64 { + return uint64(f.Size) +} + +func (f Pan123File) GetName() string { + return f.FileName +} + +func (f Pan123File) GetType() int { + if f.Type == 1 { + return conf.FOLDER + } + return utils.GetFileType(path.Ext(f.FileName)) +} + +type BaseResp struct { + Code int `json:"code"` + Message string `json:"message"` +} + +type Pan123TokenResp struct { + BaseResp + Data struct { + Token string `json:"token"` + } `json:"data"` +} + +type Pan123Files struct { + BaseResp + Data struct { + InfoList []Pan123File `json:"InfoList"` + Next string `json:"Next"` + } `json:"data"` +} + +type Pan123DownResp struct { + BaseResp + Data struct { + DownloadUrl string `json:"DownloadUrl"` + } `json:"data"` +} + +type UploadResp struct { + BaseResp + Data struct { + AccessKeyId string `json:"AccessKeyId"` + Bucket string `json:"Bucket"` + Key string `json:"Key"` + SecretAccessKey string `json:"SecretAccessKey"` + SessionToken string `json:"SessionToken"` + FileId int64 `json:"FileId"` + } `json:"data"` +} diff --git a/drivers/189/189.go b/drivers/189/189.go index 8d8fb2e4..126ec47f 100644 --- a/drivers/189/189.go +++ b/drivers/189/189.go @@ -18,7 +18,6 @@ import ( "math" "net/http" "net/http/cookiejar" - "path/filepath" "regexp" "strconv" "strings" @@ -60,11 +59,9 @@ func (driver Cloud189) FormatFile(file *Cloud189File) *model.File { f.UpdatedAt = &lastOpTime } if file.Size == -1 { - f.Type = conf.FOLDER f.Size = 0 - } else { - f.Type = utils.GetFileType(filepath.Ext(file.Name)) } + f.Type = file.GetType() return f } diff --git a/drivers/189/types.go b/drivers/189/types.go index 62403118..267fdef4 100644 --- a/drivers/189/types.go +++ b/drivers/189/types.go @@ -1,5 +1,11 @@ package _89 +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/utils" + "path" +) + type Cloud189Error struct { ErrorCode string `json:"errorCode"` ErrorMsg string `json:"errorMsg"` @@ -17,6 +23,24 @@ type Cloud189File struct { Url string `json:"url"` } +func (f Cloud189File) GetSize() uint64 { + if f.Size == -1 { + return 0 + } + return uint64(f.Size) +} + +func (f Cloud189File) GetName() string { + return f.Name +} + +func (f Cloud189File) GetType() int { + if f.Size == -1 { + return conf.FOLDER + } + return utils.GetFileType(path.Ext(f.Name)) +} + type Cloud189Folder struct { Id int64 `json:"id"` LastOpTime string `json:"lastOpTime"` diff --git a/drivers/alidrive/alidrive.go b/drivers/alidrive/alidrive.go index bac9dd7a..4bb2a0e7 100644 --- a/drivers/alidrive/alidrive.go +++ b/drivers/alidrive/alidrive.go @@ -3,7 +3,6 @@ package alidrive import ( "errors" "fmt" - "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" @@ -11,36 +10,10 @@ import ( jsoniter "github.com/json-iterator/go" log "github.com/sirupsen/logrus" "path/filepath" - "time" ) var aliClient = resty.New() -type AliRespError struct { - Code string `json:"code"` - Message string `json:"message"` -} - -type AliFiles struct { - Items []AliFile `json:"items"` - NextMarker string `json:"next_marker"` -} - -type AliFile struct { - DriveId string `json:"drive_id"` - CreatedAt *time.Time `json:"created_at"` - FileExtension string `json:"file_extension"` - FileId string `json:"file_id"` - Type string `json:"type"` - Name string `json:"name"` - Category string `json:"category"` - ParentFileId string `json:"parent_file_id"` - UpdatedAt *time.Time `json:"updated_at"` - Size int64 `json:"size"` - Thumbnail string `json:"thumbnail"` - Url string `json:"url"` -} - func (driver AliDrive) FormatFile(file *AliFile) *model.File { f := &model.File{ Id: file.FileId, @@ -51,17 +24,7 @@ func (driver AliDrive) FormatFile(file *AliFile) *model.File { Driver: driver.Config().Name, Url: file.Url, } - if file.Type == "folder" { - f.Type = conf.FOLDER - } else { - f.Type = utils.GetFileType(file.FileExtension) - } - if file.Category == "video" { - f.Type = conf.VIDEO - } - if file.Category == "image" { - f.Type = conf.IMAGE - } + f.Type = file.GetType() return f } diff --git a/drivers/alidrive/types.go b/drivers/alidrive/types.go new file mode 100644 index 00000000..93e3f286 --- /dev/null +++ b/drivers/alidrive/types.go @@ -0,0 +1,53 @@ +package alidrive + +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/utils" + "time" +) + +type AliRespError struct { + Code string `json:"code"` + Message string `json:"message"` +} + +type AliFiles struct { + Items []AliFile `json:"items"` + NextMarker string `json:"next_marker"` +} + +type AliFile struct { + DriveId string `json:"drive_id"` + CreatedAt *time.Time `json:"created_at"` + FileExtension string `json:"file_extension"` + FileId string `json:"file_id"` + Type string `json:"type"` + Name string `json:"name"` + Category string `json:"category"` + ParentFileId string `json:"parent_file_id"` + UpdatedAt *time.Time `json:"updated_at"` + Size int64 `json:"size"` + Thumbnail string `json:"thumbnail"` + Url string `json:"url"` +} + +func (f AliFile) GetSize() uint64 { + return uint64(f.Size) +} + +func (f AliFile) GetName() string { + return f.Name +} + +func (f AliFile) GetType() int { + if f.Type == "folder" { + return conf.FOLDER + } + if f.Category == "video" { + return conf.VIDEO + } + if f.Category == "image" { + return conf.IMAGE + } + return utils.GetFileType(f.FileExtension) +} diff --git a/drivers/base/cache.go b/drivers/base/cache.go index e702cf20..38141828 100644 --- a/drivers/base/cache.go +++ b/drivers/base/cache.go @@ -1,7 +1,6 @@ package base import ( - "fmt" "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/model" "github.com/Xhofe/alist/utils" @@ -9,12 +8,37 @@ import ( ) func KeyCache(path string, account *model.Account) string { - path = utils.ParsePath(path) - return fmt.Sprintf("%s%s", account.Name, path) + //path = utils.ParsePath(path) + key := utils.ParsePath(utils.Join(account.Name, path)) + log.Debugln("cache key: ", key) + return key } -func SetCache(path string, obj interface{}, account *model.Account) error { - return conf.Cache.Set(conf.Ctx, KeyCache(path, account), obj, nil) +func SaveSearchFiles[T model.ISearchFile](key string, obj []T) { + err := model.DeleteSearchFilesByPath(key) + if err != nil { + log.Errorln("failed create search files", err) + return + } + files := make([]model.SearchFile, len(obj)) + for i := 0; i < len(obj); i++ { + files[i] = model.SearchFile{ + Path: key, + Name: obj[i].GetName(), + Size: obj[i].GetSize(), + Type: obj[i].GetType(), + } + } + err = model.CreateSearchFiles(files) + if err != nil { + log.Errorln("failed create search files", err) + } +} + +func SetCache[T model.ISearchFile](path string, obj []T, account *model.Account) error { + key := KeyCache(path, account) + go SaveSearchFiles(key, obj) + return conf.Cache.Set(conf.Ctx, key, obj, nil) } func GetCache(path string, account *model.Account) (interface{}, error) { diff --git a/drivers/google/googledrive.go b/drivers/google/googledrive.go index 34b2f419..c3c47b49 100644 --- a/drivers/google/googledrive.go +++ b/drivers/google/googledrive.go @@ -2,15 +2,10 @@ package google import ( "fmt" - "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" - "github.com/Xhofe/alist/utils" "github.com/go-resty/resty/v2" log "github.com/sirupsen/logrus" - "path/filepath" - "strconv" - "time" ) type TokenError struct { @@ -44,19 +39,6 @@ func (driver GoogleDrive) RefreshToken(account *model.Account) error { return nil } -type File struct { - Id string `json:"id"` - Name string `json:"name"` - MimeType string `json:"mimeType"` - ModifiedTime *time.Time `json:"modifiedTime"` - Size string `json:"size"` - ThumbnailLink string `json:"thumbnailLink"` -} - -func (driver GoogleDrive) IsDir(mimeType string) bool { - return mimeType == "application/vnd.google-apps.folder" || mimeType == "application/vnd.google-apps.shortcut" -} - func (driver GoogleDrive) FormatFile(file *File, account *model.Account) *model.File { f := &model.File{ Id: file.Id, @@ -65,13 +47,8 @@ func (driver GoogleDrive) FormatFile(file *File, account *model.Account) *model. UpdatedAt: file.ModifiedTime, Url: "", } - if driver.IsDir(file.MimeType) { - f.Type = conf.FOLDER - } else { - size, _ := strconv.ParseInt(file.Size, 10, 64) - f.Size = size - f.Type = utils.GetFileType(filepath.Ext(file.Name)) - } + f.Size = int64(file.GetSize()) + f.Type = file.GetType() if file.ThumbnailLink != "" { if account.APIProxyUrl != "" { f.Thumbnail = fmt.Sprintf("%s/%s", account.APIProxyUrl, file.ThumbnailLink) diff --git a/drivers/google/types.go b/drivers/google/types.go new file mode 100644 index 00000000..67752a2b --- /dev/null +++ b/drivers/google/types.go @@ -0,0 +1,38 @@ +package google + +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/utils" + "path" + "strconv" + "time" +) + +type File struct { + Id string `json:"id"` + Name string `json:"name"` + MimeType string `json:"mimeType"` + ModifiedTime *time.Time `json:"modifiedTime"` + Size string `json:"size"` + ThumbnailLink string `json:"thumbnailLink"` +} + +func (f File) GetSize() uint64 { + if f.GetType() == conf.FOLDER { + return 0 + } + size, _ := strconv.ParseUint(f.Size, 10, 64) + return size +} + +func (f File) GetName() string { + return f.Name +} + +func (f File) GetType() int { + mimeType := f.MimeType + if mimeType == "application/vnd.google-apps.folder" || mimeType == "application/vnd.google-apps.shortcut" { + return conf.FOLDER + } + return utils.GetFileType(path.Ext(f.Name)) +} diff --git a/drivers/lanzou/lanzou.go b/drivers/lanzou/lanzou.go index 252918bd..9e43b676 100644 --- a/drivers/lanzou/lanzou.go +++ b/drivers/lanzou/lanzou.go @@ -2,28 +2,15 @@ package lanzou import ( "fmt" - "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/drivers/base" "github.com/Xhofe/alist/model" - "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" "net/url" - "path/filepath" "regexp" "strconv" "time" ) -type LanZouFile struct { - Name string `json:"name"` - NameAll string `json:"name_all"` - Id string `json:"id"` - FolId string `json:"fol_id"` - Size string `json:"size"` - Time string `json:"time"` - Folder bool -} - func (driver *Lanzou) FormatFile(file *LanZouFile) *model.File { now := time.Now() f := &model.File{ @@ -35,12 +22,11 @@ func (driver *Lanzou) FormatFile(file *LanZouFile) *model.File { UpdatedAt: &now, } if file.Folder { - f.Type = conf.FOLDER f.Id = file.FolId } else { f.Name = file.NameAll - f.Type = utils.GetFileType(filepath.Ext(file.NameAll)) } + f.Type = file.GetType() return f } diff --git a/drivers/lanzou/types.go b/drivers/lanzou/types.go index f17a1ea2..0b8f0e89 100644 --- a/drivers/lanzou/types.go +++ b/drivers/lanzou/types.go @@ -1,5 +1,39 @@ package lanzou +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/utils" + "path" +) + +type LanZouFile struct { + Name string `json:"name"` + NameAll string `json:"name_all"` + Id string `json:"id"` + FolId string `json:"fol_id"` + Size string `json:"size"` + Time string `json:"time"` + Folder bool +} + +func (f LanZouFile) GetSize() uint64 { + return 0 +} + +func (f LanZouFile) GetName() string { + if f.Folder { + return f.Name + } + return f.NameAll +} + +func (f LanZouFile) GetType() int { + if f.Folder { + return conf.FOLDER + } + return utils.GetFileType(path.Ext(f.NameAll)) +} + type DownPageResp struct { Zt int `json:"zt"` Info struct { diff --git a/drivers/native/driver.go b/drivers/native/driver.go index 580d9453..9afaff84 100644 --- a/drivers/native/driver.go +++ b/drivers/native/driver.go @@ -115,6 +115,10 @@ func (driver Native) Files(path string, account *model.Account) ([]model.File, e } files = append(files, file) } + _, err = base.GetCache(path, account) + if len(files) != 0 && err != nil { + _ = base.SetCache(path, files, account) + } return files, nil } diff --git a/go.mod b/go.mod index 1f4df15a..b71d9b89 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Xhofe/alist -go 1.17 +go 1.18 require ( github.com/aws/aws-sdk-go v1.27.0 diff --git a/model/file.go b/model/file.go index eb0cb0b8..961e7b14 100644 --- a/model/file.go +++ b/model/file.go @@ -2,6 +2,7 @@ package model import ( "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/utils" "sort" "strings" "time" @@ -84,3 +85,7 @@ func (f File) ModTime() time.Time { func (f File) IsDir() bool { return f.Type == conf.FOLDER } + +func (f File) GetType() int { + return utils.GetFileType(utils.Ext(f.GetName())) +} diff --git a/model/search_file.go b/model/search_file.go new file mode 100644 index 00000000..0858f2d6 --- /dev/null +++ b/model/search_file.go @@ -0,0 +1,35 @@ +package model + +import ( + "fmt" + "github.com/Xhofe/alist/conf" +) + +type ISearchFile interface { + GetName() string + GetSize() uint64 + GetType() int +} + +type SearchFile struct { + Path string `json:"path" gorm:"index"` + Name string `json:"name"` + Size uint64 `json:"size"` + Type int `json:"type"` +} + +func CreateSearchFiles(files []SearchFile) error { + return conf.DB.Create(files).Error +} + +func DeleteSearchFilesByPath(path string) error { + return conf.DB.Where(fmt.Sprintf("%s = ?", columnName("path")), path).Delete(&SearchFile{}).Error +} + +func SearchByNameAndPath(path, keyword string) ([]SearchFile, error) { + var files []SearchFile + if err := conf.DB.Where(fmt.Sprintf("%s LIKE ? AND %s LIKE ?", columnName("path"), columnName("name")), fmt.Sprintf("%s%%", path), fmt.Sprintf("%%%s%%", keyword)).Find(&files).Error; err != nil { + return nil, err + } + return files, nil +} diff --git a/server/controllers/proxy.go b/server/controllers/proxy.go index 8c47727a..5597903e 100644 --- a/server/controllers/proxy.go +++ b/server/controllers/proxy.go @@ -61,6 +61,7 @@ func Proxy(c *gin.Context) { return } err = common.Proxy(c.Writer, c.Request, link, file) + log.Debugln("web proxy error:", err) if err != nil { common.ErrorResp(c, err, 500) } From a73a40133d1979caeba54dcb227b91d2d70364f8 Mon Sep 17 00:00:00 2001 From: Xhofe Date: Fri, 8 Apr 2022 22:03:26 +0800 Subject: [PATCH 2/3] feat: search api --- bootstrap/setting.go | 7 +++++++ conf/var.go | 1 + drivers/base/cache.go | 4 +++- server/controllers/search.go | 31 +++++++++++++++++++++++++++++++ server/router.go | 2 ++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 server/controllers/search.go diff --git a/bootstrap/setting.go b/bootstrap/setting.go index 288498f2..a45245c5 100644 --- a/bootstrap/setting.go +++ b/bootstrap/setting.go @@ -258,6 +258,13 @@ func InitSettings() { Access: model.PRIVATE, Group: model.BACK, }, + { + Key: "enable search", + Value: "false", + Type: "bool", + Access: model.PUBLIC, + Group: model.BACK, + }, } for i, _ := range settings { v := settings[i] diff --git a/conf/var.go b/conf/var.go index 09429ab4..cf1e9227 100644 --- a/conf/var.go +++ b/conf/var.go @@ -85,6 +85,7 @@ var ( "Visitor WebDAV username", "Visitor WebDAV password", "default page size", "load type", "ocr api", "favicon", + "enable search", } ) diff --git a/drivers/base/cache.go b/drivers/base/cache.go index 38141828..bde23a17 100644 --- a/drivers/base/cache.go +++ b/drivers/base/cache.go @@ -37,7 +37,9 @@ func SaveSearchFiles[T model.ISearchFile](key string, obj []T) { func SetCache[T model.ISearchFile](path string, obj []T, account *model.Account) error { key := KeyCache(path, account) - go SaveSearchFiles(key, obj) + if conf.GetBool("enable search") { + go SaveSearchFiles(key, obj) + } return conf.Cache.Set(conf.Ctx, key, obj, nil) } diff --git a/server/controllers/search.go b/server/controllers/search.go new file mode 100644 index 00000000..1e754028 --- /dev/null +++ b/server/controllers/search.go @@ -0,0 +1,31 @@ +package controllers + +import ( + "github.com/Xhofe/alist/conf" + "github.com/Xhofe/alist/model" + "github.com/Xhofe/alist/server/common" + "github.com/gin-gonic/gin" +) + +type SearchReq struct { + Path string `json:"path"` + Keyword string `json:"keyword"` +} + +func Search(c *gin.Context) { + if conf.GetBool("enable search") { + common.ErrorStrResp(c, "Not allowed search", 403) + return + } + var req SearchReq + if err := c.ShouldBind(&req); err != nil { + common.ErrorResp(c, err, 400) + return + } + files, err := model.SearchByNameAndPath(req.Path, req.Keyword) + if err != nil { + common.ErrorResp(c, err, 500) + return + } + common.SuccessResp(c, files) +} diff --git a/server/router.go b/server/router.go index ae8fc262..174f29e2 100644 --- a/server/router.go +++ b/server/router.go @@ -25,6 +25,8 @@ func InitApiRouter(r *gin.Engine) { path.POST("/path", controllers.Path) path.POST("/preview", controllers.Preview) + public.POST("/search", controllers.Search) + //path.POST("/link",middlewares.Auth, controllers.Link) public.POST("/upload", file.UploadFiles) From 4c22f37d54d805398434a56f28f9f08885c1b0d7 Mon Sep 17 00:00:00 2001 From: Xhofe Date: Fri, 8 Apr 2022 22:47:04 +0800 Subject: [PATCH 3/3] fix(search): file type --- model/file.go | 3 +-- server/controllers/search.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/model/file.go b/model/file.go index 961e7b14..94497ff3 100644 --- a/model/file.go +++ b/model/file.go @@ -2,7 +2,6 @@ package model import ( "github.com/Xhofe/alist/conf" - "github.com/Xhofe/alist/utils" "sort" "strings" "time" @@ -87,5 +86,5 @@ func (f File) IsDir() bool { } func (f File) GetType() int { - return utils.GetFileType(utils.Ext(f.GetName())) + return f.Type } diff --git a/server/controllers/search.go b/server/controllers/search.go index 1e754028..061aeac1 100644 --- a/server/controllers/search.go +++ b/server/controllers/search.go @@ -13,7 +13,7 @@ type SearchReq struct { } func Search(c *gin.Context) { - if conf.GetBool("enable search") { + if !conf.GetBool("enable search") { common.ErrorStrResp(c, "Not allowed search", 403) return }