feat: add `hash_info` field to `/fs/get` (close #5259)

pull/5284/head
Andy Hsu 2023-09-22 15:20:04 +08:00
parent 2a6ab77295
commit 882112ed1c
2 changed files with 34 additions and 27 deletions

View File

@ -218,3 +218,7 @@ func FromString(str string) HashInfo {
func (hi HashInfo) GetHash(ht *HashType) string { func (hi HashInfo) GetHash(ht *HashType) string {
return hi.h[ht] return hi.h[ht]
} }
func (hi HashInfo) Export() map[*HashType]string {
return hi.h
}

View File

@ -33,15 +33,16 @@ type DirReq struct {
} }
type ObjResp struct { type ObjResp struct {
Name string `json:"name"` Name string `json:"name"`
Size int64 `json:"size"` Size int64 `json:"size"`
IsDir bool `json:"is_dir"` IsDir bool `json:"is_dir"`
Modified time.Time `json:"modified"` Modified time.Time `json:"modified"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Sign string `json:"sign"` Sign string `json:"sign"`
Thumb string `json:"thumb"` Thumb string `json:"thumb"`
Type int `json:"type"` Type int `json:"type"`
HashInfo string `json:"hashinfo"` HashInfoStr string `json:"hashinfo"`
HashInfo map[*utils.HashType]string `json:"hash_info"`
} }
type FsListResp struct { type FsListResp struct {
@ -200,15 +201,16 @@ func toObjsResp(objs []model.Obj, parent string, encrypt bool) []ObjResp {
for _, obj := range objs { for _, obj := range objs {
thumb, _ := model.GetThumb(obj) thumb, _ := model.GetThumb(obj)
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(),
Created: obj.CreateTime(), Created: obj.CreateTime(),
HashInfo: obj.GetHash().String(), HashInfoStr: obj.GetHash().String(),
Sign: common.Sign(obj, parent, encrypt), HashInfo: obj.GetHash().Export(),
Thumb: thumb, Sign: common.Sign(obj, parent, encrypt),
Type: utils.GetObjType(obj.GetName(), obj.IsDir()), Thumb: thumb,
Type: utils.GetObjType(obj.GetName(), obj.IsDir()),
}) })
} }
return resp return resp
@ -313,15 +315,16 @@ func FsGet(c *gin.Context) {
thumb, _ := model.GetThumb(obj) thumb, _ := model.GetThumb(obj)
common.SuccessResp(c, FsGetResp{ common.SuccessResp(c, FsGetResp{
ObjResp: ObjResp{ ObjResp: 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(),
Created: obj.CreateTime(), Created: obj.CreateTime(),
HashInfo: obj.GetHash().String(), HashInfoStr: obj.GetHash().String(),
Sign: common.Sign(obj, parentPath, isEncrypt(meta, reqPath)), HashInfo: obj.GetHash().Export(),
Type: utils.GetFileType(obj.GetName()), Sign: common.Sign(obj, parentPath, isEncrypt(meta, reqPath)),
Thumb: thumb, Type: utils.GetFileType(obj.GetName()),
Thumb: thumb,
}, },
RawURL: rawURL, RawURL: rawURL,
Readme: getReadme(meta, reqPath), Readme: getReadme(meta, reqPath),