feat: add thumbnail to list resp

pull/1604/head
Noah Hsu 2022-08-03 13:03:45 +08:00
parent 71a6ebaf43
commit 2a68c3cc7b
1 changed files with 17 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package handles
import ( import (
"fmt" "fmt"
"github.com/alist-org/alist/v3/internal/sign"
stdpath "path" stdpath "path"
"strings" "strings"
"time" "time"
@ -11,6 +10,7 @@ import (
"github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/errs"
"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/sign"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common" "github.com/alist-org/alist/v3/server/common"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -34,6 +34,7 @@ type ObjResp struct {
IsDir bool `json:"is_dir"` IsDir bool `json:"is_dir"`
Modified time.Time `json:"modified"` Modified time.Time `json:"modified"`
Sign string `json:"sign"` Sign string `json:"sign"`
Thumbnail string `json:"thumbnail"`
} }
type FsListResp struct { type FsListResp struct {
@ -166,12 +167,17 @@ func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
func toObjResp(objs []model.Obj) []ObjResp { func toObjResp(objs []model.Obj) []ObjResp {
var resp []ObjResp var resp []ObjResp
for _, obj := range objs { for _, obj := range objs {
thumbnail := ""
if t, ok := obj.(model.Thumbnail); ok {
thumbnail = t.Thumbnail()
}
resp = append(resp, ObjResp{ resp = append(resp, ObjResp{
Name: obj.GetName(), Name: obj.GetName(),
Size: obj.GetSize(), Size: obj.GetSize(),
IsDir: obj.IsDir(), IsDir: obj.IsDir(),
Modified: obj.ModTime(), Modified: obj.ModTime(),
Sign: common.Sign(obj), Sign: common.Sign(obj),
Thumbnail: thumbnail,
}) })
} }
return resp return resp