feat: local storage image thumbnail

This commit is contained in:
Noah Hsu
2022-08-11 20:32:17 +08:00
parent fda4db71bf
commit af884010d1
19 changed files with 178 additions and 61 deletions

View File

@ -30,6 +30,7 @@ func Down(c *gin.Context) {
link, _, err := fs.Link(c, rawPath, model.LinkArgs{
IP: c.ClientIP(),
Header: c.Request.Header,
Type: c.Query("type"),
})
if err != nil {
common.ErrorResp(c, err, 500)
@ -52,13 +53,17 @@ func Proxy(c *gin.Context) {
if downProxyUrl != "" {
_, ok := c.GetQuery("d")
if ok {
URL := fmt.Sprintf("%s%s?sign=%s", strings.Split(downProxyUrl, "\n")[0], rawPath, sign.Sign(filename))
URL := fmt.Sprintf("%s%s?sign=%s",
strings.Split(downProxyUrl, "\n")[0],
utils.EncodePath(rawPath),
sign.Sign(filename))
c.Redirect(302, URL)
return
}
}
link, file, err := fs.Link(c, rawPath, model.LinkArgs{
Header: c.Request.Header,
Type: c.Query("type"),
})
if err != nil {
common.ErrorResp(c, err, 500)

View File

@ -11,6 +11,7 @@ import (
"github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin"
)
@ -245,7 +246,10 @@ func Link(c *gin.Context) {
}
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))),
URL: fmt.Sprintf("%s/p%s?d&sign=%s",
common.GetApiUrl(c.Request),
utils.EncodePath(req.Path),
sign.Sign(stdpath.Base(rawPath))),
})
return
}

View File

@ -30,13 +30,13 @@ type DirReq struct {
}
type ObjResp struct {
Name string `json:"name"`
Size int64 `json:"size"`
IsDir bool `json:"is_dir"`
Modified time.Time `json:"modified"`
Sign string `json:"sign"`
Thumbnail string `json:"thumbnail"`
Type int `json:"type"`
Name string `json:"name"`
Size int64 `json:"size"`
IsDir bool `json:"is_dir"`
Modified time.Time `json:"modified"`
Sign string `json:"sign"`
Thumb string `json:"thumb"`
Type int `json:"type"`
}
type FsListResp struct {
@ -169,22 +169,22 @@ func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
func toObjResp(objs []model.Obj) []ObjResp {
var resp []ObjResp
for _, obj := range objs {
thumbnail := ""
if t, ok := obj.(model.Thumbnail); ok {
thumbnail = t.Thumbnail()
thumb := ""
if t, ok := obj.(model.Thumb); ok {
thumb = t.Thumb()
}
tp := conf.FOLDER
if !obj.IsDir() {
tp = utils.GetFileType(obj.GetName())
}
resp = append(resp, ObjResp{
Name: obj.GetName(),
Size: obj.GetSize(),
IsDir: obj.IsDir(),
Modified: obj.ModTime(),
Sign: common.Sign(obj),
Thumbnail: thumbnail,
Type: tp,
Name: obj.GetName(),
Size: obj.GetSize(),
IsDir: obj.IsDir(),
Modified: obj.ModTime(),
Sign: common.Sign(obj),
Thumb: thumb,
Type: tp,
})
}
return resp
@ -248,7 +248,10 @@ func FsGet(c *gin.Context) {
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()))
rawURL = fmt.Sprintf("%s/p%s?sign=%s",
common.GetApiUrl(c.Request),
utils.EncodePath(req.Path),
sign.Sign(obj.GetName()))
}
} else {
// if storage is not proxy, use raw url by fs.Link