feat: add related objs while get obj
This commit is contained in:
parent
2e8322e99b
commit
1fd4ebe53e
@ -190,7 +190,9 @@ type FsGetOrLinkReq struct {
|
|||||||
|
|
||||||
type FsGetResp struct {
|
type FsGetResp struct {
|
||||||
ObjResp
|
ObjResp
|
||||||
RawURL string `json:"raw_url"`
|
RawURL string `json:"raw_url"`
|
||||||
|
Readme string `json:"readme"`
|
||||||
|
Related []string `json:"related"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func FsGet(c *gin.Context) {
|
func FsGet(c *gin.Context) {
|
||||||
@ -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{
|
common.SuccessResp(c, FsGetResp{
|
||||||
ObjResp: ObjResp{
|
ObjResp: ObjResp{
|
||||||
Name: obj.GetName(),
|
Name: obj.GetName(),
|
||||||
@ -250,10 +257,26 @@ func FsGet(c *gin.Context) {
|
|||||||
Modified: obj.ModTime(),
|
Modified: obj.ModTime(),
|
||||||
Sign: common.Sign(obj),
|
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 {
|
type FsOtherReq struct {
|
||||||
model.FsOtherArgs
|
model.FsOtherArgs
|
||||||
Password string `json:"password" form:"password"`
|
Password string `json:"password" form:"password"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user