Skip to content

Commit

Permalink
fix(crypt): add sign to thumbnail (#6611)
Browse files Browse the repository at this point in the history
  • Loading branch information
j2rong4cn authored Dec 25, 2024
1 parent 221cdf3 commit db5c601
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion drivers/crypt/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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/op"
"github.com/alist-org/alist/v3/internal/sign"
"github.com/alist-org/alist/v3/internal/stream"
"github.com/alist-org/alist/v3/pkg/http_range"
"github.com/alist-org/alist/v3/pkg/utils"
Expand Down Expand Up @@ -160,7 +161,11 @@ func (d *Crypt) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
// discarding hash as it's encrypted
}
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 {
result = append(result, &objRes)
Expand Down
8 changes: 4 additions & 4 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
if !d.ShowHidden && strings.HasPrefix(f.Name(), ".") {
continue
}
file := d.FileInfoToObj(f, args.ReqPath, fullPath)
file := d.FileInfoToObj(ctx, f, args.ReqPath, fullPath)
files = append(files, file)
}
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 := ""
if d.Thumbnail {
typeName := utils.GetFileType(f.Name())
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 += "?type=thumb&sign=" + sign.Sign(stdpath.Join(reqPath, f.Name()))
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func (d *Local) GetMeta(ctx context.Context, path string) (model.Obj, error) {
if err != nil {
return nil, err
}
file := d.FileInfoToObj(f, path, path)
file := d.FileInfoToObj(ctx, f, path, path)
//h := "123123"
//if s, ok := f.(model.SetHash); ok && file.GetHash() == ("","") {
// s.SetHash(h,"SHA1")
Expand Down
9 changes: 9 additions & 0 deletions server/common/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

import (
"context"
"net/http"
"strings"

"github.com/alist-org/alist/v3/cmd/flags"
Expand Down Expand Up @@ -80,3 +82,10 @@ func SuccessResp(c *gin.Context, data ...interface{}) {
Data: data[0],
})
}

func GetHttpReq(ctx context.Context) *http.Request {
if c, ok := ctx.(*gin.Context); ok {
return c.Request
}
return nil
}

0 comments on commit db5c601

Please sign in to comment.