Skip to content

Commit 882112e

Browse files
committed
feat: add hash_info field to /fs/get (close #5259)
1 parent 2a6ab77 commit 882112e

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

pkg/utils/hash.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,7 @@ func FromString(str string) HashInfo {
218218
func (hi HashInfo) GetHash(ht *HashType) string {
219219
return hi.h[ht]
220220
}
221+
222+
func (hi HashInfo) Export() map[*HashType]string {
223+
return hi.h
224+
}

server/handles/fsread.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ type DirReq struct {
3333
}
3434

3535
type ObjResp struct {
36-
Name string `json:"name"`
37-
Size int64 `json:"size"`
38-
IsDir bool `json:"is_dir"`
39-
Modified time.Time `json:"modified"`
40-
Created time.Time `json:"created"`
41-
Sign string `json:"sign"`
42-
Thumb string `json:"thumb"`
43-
Type int `json:"type"`
44-
HashInfo string `json:"hashinfo"`
36+
Name string `json:"name"`
37+
Size int64 `json:"size"`
38+
IsDir bool `json:"is_dir"`
39+
Modified time.Time `json:"modified"`
40+
Created time.Time `json:"created"`
41+
Sign string `json:"sign"`
42+
Thumb string `json:"thumb"`
43+
Type int `json:"type"`
44+
HashInfoStr string `json:"hashinfo"`
45+
HashInfo map[*utils.HashType]string `json:"hash_info"`
4546
}
4647

4748
type FsListResp struct {
@@ -200,15 +201,16 @@ func toObjsResp(objs []model.Obj, parent string, encrypt bool) []ObjResp {
200201
for _, obj := range objs {
201202
thumb, _ := model.GetThumb(obj)
202203
resp = append(resp, ObjResp{
203-
Name: obj.GetName(),
204-
Size: obj.GetSize(),
205-
IsDir: obj.IsDir(),
206-
Modified: obj.ModTime(),
207-
Created: obj.CreateTime(),
208-
HashInfo: obj.GetHash().String(),
209-
Sign: common.Sign(obj, parent, encrypt),
210-
Thumb: thumb,
211-
Type: utils.GetObjType(obj.GetName(), obj.IsDir()),
204+
Name: obj.GetName(),
205+
Size: obj.GetSize(),
206+
IsDir: obj.IsDir(),
207+
Modified: obj.ModTime(),
208+
Created: obj.CreateTime(),
209+
HashInfoStr: obj.GetHash().String(),
210+
HashInfo: obj.GetHash().Export(),
211+
Sign: common.Sign(obj, parent, encrypt),
212+
Thumb: thumb,
213+
Type: utils.GetObjType(obj.GetName(), obj.IsDir()),
212214
})
213215
}
214216
return resp
@@ -313,15 +315,16 @@ func FsGet(c *gin.Context) {
313315
thumb, _ := model.GetThumb(obj)
314316
common.SuccessResp(c, FsGetResp{
315317
ObjResp: ObjResp{
316-
Name: obj.GetName(),
317-
Size: obj.GetSize(),
318-
IsDir: obj.IsDir(),
319-
Modified: obj.ModTime(),
320-
Created: obj.CreateTime(),
321-
HashInfo: obj.GetHash().String(),
322-
Sign: common.Sign(obj, parentPath, isEncrypt(meta, reqPath)),
323-
Type: utils.GetFileType(obj.GetName()),
324-
Thumb: thumb,
318+
Name: obj.GetName(),
319+
Size: obj.GetSize(),
320+
IsDir: obj.IsDir(),
321+
Modified: obj.ModTime(),
322+
Created: obj.CreateTime(),
323+
HashInfoStr: obj.GetHash().String(),
324+
HashInfo: obj.GetHash().Export(),
325+
Sign: common.Sign(obj, parentPath, isEncrypt(meta, reqPath)),
326+
Type: utils.GetFileType(obj.GetName()),
327+
Thumb: thumb,
325328
},
326329
RawURL: rawURL,
327330
Readme: getReadme(meta, reqPath),

0 commit comments

Comments
 (0)