Skip to content

Commit

Permalink
feat: add related objs while get obj
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Aug 7, 2022
1 parent 2e8322e commit 1fd4ebe
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions server/handles/fsread.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ type FsGetOrLinkReq struct {

type FsGetResp struct {
ObjResp
RawURL string `json:"raw_url"`
RawURL string `json:"raw_url"`
Readme string `json:"readme"`
Related []string `json:"related"`
}

func FsGet(c *gin.Context) {
Expand Down Expand Up @@ -242,6 +244,11 @@ func FsGet(c *gin.Context) {
}
}
}
var related []string
sameLevelFiles, err := fs.List(c, stdpath.Dir(req.Path))
if err == nil {
related = filterRelated(sameLevelFiles, obj)
}
common.SuccessResp(c, FsGetResp{
ObjResp: ObjResp{
Name: obj.GetName(),
Expand All @@ -250,10 +257,26 @@ func FsGet(c *gin.Context) {
Modified: obj.ModTime(),
Sign: common.Sign(obj),
},
RawURL: rawURL,
RawURL: rawURL,
Readme: getReadme(meta, req.Path),
Related: related,
})
}

func filterRelated(objs []model.Obj, obj model.Obj) []string {
var related []string
nameWithoutExt := strings.TrimSuffix(obj.GetName(), stdpath.Ext(obj.GetName()))
for _, o := range objs {
if o.GetName() == obj.GetName() {
continue
}
if strings.HasPrefix(o.GetName(), nameWithoutExt) {
related = append(related, o.GetName())
}
}
return related
}

type FsOtherReq struct {
model.FsOtherArgs
Password string `json:"password" form:"password"`
Expand Down

0 comments on commit 1fd4ebe

Please sign in to comment.