feat: add type to fs read api

This commit is contained in:
Noah Hsu
2022-08-08 00:51:05 +08:00
parent ccce6a30bb
commit 61fa6f38a8
11 changed files with 81 additions and 18 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/setting"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
@ -85,8 +84,7 @@ func shouldProxy(storage driver.Driver, filename string) bool {
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
return true
}
proxyTypes := setting.GetByKey(conf.ProxyTypes)
if strings.Contains(proxyTypes, utils.Ext(filename)) {
if utils.SliceContains(conf.TypesMap[conf.ProxyTypes], utils.Ext(filename)) {
return true
}
return false
@ -103,12 +101,10 @@ func canProxy(storage driver.Driver, filename string) bool {
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
return true
}
proxyTypes := setting.GetByKey(conf.ProxyTypes)
if strings.Contains(proxyTypes, utils.Ext(filename)) {
if utils.SliceContains(conf.TypesMap[conf.ProxyTypes], utils.Ext(filename)) {
return true
}
textTypes := setting.GetByKey(conf.TextTypes)
if strings.Contains(textTypes, utils.Ext(filename)) {
if utils.SliceContains(conf.TypesMap[conf.TextTypes], utils.Ext(filename)) {
return true
}
return false

View File

@ -6,6 +6,7 @@ import (
"strings"
"time"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/internal/db"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/fs"
@ -35,6 +36,7 @@ type ObjResp struct {
Modified time.Time `json:"modified"`
Sign string `json:"sign"`
Thumbnail string `json:"thumbnail"`
Type int `json:"type"`
}
type FsListResp struct {
@ -171,6 +173,10 @@ func toObjResp(objs []model.Obj) []ObjResp {
if t, ok := obj.(model.Thumbnail); ok {
thumbnail = t.Thumbnail()
}
tp := conf.FOLDER
if !obj.IsDir() {
tp = utils.GetFileType(obj.GetName())
}
resp = append(resp, ObjResp{
Name: obj.GetName(),
Size: obj.GetSize(),
@ -178,6 +184,7 @@ func toObjResp(objs []model.Obj) []ObjResp {
Modified: obj.ModTime(),
Sign: common.Sign(obj),
Thumbnail: thumbnail,
Type: tp,
})
}
return resp
@ -256,6 +263,7 @@ func FsGet(c *gin.Context) {
IsDir: obj.IsDir(),
Modified: obj.ModTime(),
Sign: common.Sign(obj),
Type: utils.GetFileType(obj.GetName()),
},
RawURL: rawURL,
Readme: getReadme(meta, req.Path),