fix(crypt): add sign to thumbnail (#6611)

This commit is contained in:
j2rong4cn 2024-12-25 21:13:54 +08:00 committed by GitHub
parent 221cdf3611
commit db5c601cfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/alist-org/alist/v3/internal/fs" "github.com/alist-org/alist/v3/internal/fs"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/internal/op"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/internal/stream" "github.com/alist-org/alist/v3/internal/stream"
"github.com/alist-org/alist/v3/pkg/http_range" "github.com/alist-org/alist/v3/pkg/http_range"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
@ -160,7 +161,11 @@ func (d *Crypt) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
// discarding hash as it's encrypted // discarding hash as it's encrypted
} }
if d.Thumbnail && thumb == "" { if d.Thumbnail && thumb == "" {
thumb = utils.EncodePath(common.GetApiUrl(nil)+stdpath.Join("/d", args.ReqPath, ".thumbnails", name+".webp"), true) thumbPath := stdpath.Join(args.ReqPath, ".thumbnails", name+".webp")
thumb = fmt.Sprintf("%s/d%s?sign=%s",
common.GetApiUrl(common.GetHttpReq(ctx)),
utils.EncodePath(thumbPath, true),
sign.Sign(thumbPath))
} }
if !ok && !d.Thumbnail { if !ok && !d.Thumbnail {
result = append(result, &objRes) result = append(result, &objRes)

View File

@ -101,17 +101,17 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
if !d.ShowHidden && strings.HasPrefix(f.Name(), ".") { if !d.ShowHidden && strings.HasPrefix(f.Name(), ".") {
continue continue
} }
file := d.FileInfoToObj(f, args.ReqPath, fullPath) file := d.FileInfoToObj(ctx, f, args.ReqPath, fullPath)
files = append(files, file) files = append(files, file)
} }
return files, nil return files, nil
} }
func (d *Local) FileInfoToObj(f fs.FileInfo, reqPath string, fullPath string) model.Obj { func (d *Local) FileInfoToObj(ctx context.Context, f fs.FileInfo, reqPath string, fullPath string) model.Obj {
thumb := "" thumb := ""
if d.Thumbnail { if d.Thumbnail {
typeName := utils.GetFileType(f.Name()) typeName := utils.GetFileType(f.Name())
if typeName == conf.IMAGE || typeName == conf.VIDEO { if typeName == conf.IMAGE || typeName == conf.VIDEO {
thumb = common.GetApiUrl(nil) + stdpath.Join("/d", reqPath, f.Name()) thumb = common.GetApiUrl(common.GetHttpReq(ctx)) + stdpath.Join("/d", reqPath, f.Name())
thumb = utils.EncodePath(thumb, true) thumb = utils.EncodePath(thumb, true)
thumb += "?type=thumb&sign=" + sign.Sign(stdpath.Join(reqPath, f.Name())) thumb += "?type=thumb&sign=" + sign.Sign(stdpath.Join(reqPath, f.Name()))
} }
@ -149,7 +149,7 @@ func (d *Local) GetMeta(ctx context.Context, path string) (model.Obj, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
file := d.FileInfoToObj(f, path, path) file := d.FileInfoToObj(ctx, f, path, path)
//h := "123123" //h := "123123"
//if s, ok := f.(model.SetHash); ok && file.GetHash() == ("","") { //if s, ok := f.(model.SetHash); ok && file.GetHash() == ("","") {
// s.SetHash(h,"SHA1") // s.SetHash(h,"SHA1")

View File

@ -1,6 +1,8 @@
package common package common
import ( import (
"context"
"net/http"
"strings" "strings"
"github.com/alist-org/alist/v3/cmd/flags" "github.com/alist-org/alist/v3/cmd/flags"
@ -80,3 +82,10 @@ func SuccessResp(c *gin.Context, data ...interface{}) {
Data: data[0], Data: data[0],
}) })
} }
func GetHttpReq(ctx context.Context) *http.Request {
if c, ok := ctx.(*gin.Context); ok {
return c.Request
}
return nil
}