Feat: fslist add more filed

pull/47/head
zijiren233 1 year ago
parent abacb145d0
commit 1731cf22aa

@ -33,6 +33,14 @@ func (r *ListReq) Decode(ctx *gin.Context) error {
return json.NewDecoder(ctx.Request.Body).Decode(r)
}
type AlistFileItem struct {
*model.Item
Size uint64 `json:"size"`
Modified uint64 `json:"modified"`
}
type AlistFSListResp = model.VendorFSListResp[*AlistFileItem]
func List(ctx *gin.Context) {
user := ctx.MustGet("user").(*op.User)
@ -79,15 +87,19 @@ func List(ctx *gin.Context) {
}
req.Path = strings.TrimRight(req.Path, "/")
resp := model.VendorFSListResp{
resp := AlistFSListResp{
Total: data.Total,
Paths: model.GenDefaultPaths(req.Path),
}
for _, flr := range data.Content {
resp.Items = append(resp.Items, &model.Item{
Name: flr.Name,
Path: fmt.Sprintf("%s/%s", req.Path, flr.Name),
IsDir: flr.IsDir,
resp.Items = append(resp.Items, &AlistFileItem{
Item: &model.Item{
Name: flr.Name,
Path: fmt.Sprintf("%s/%s", req.Path, flr.Name),
IsDir: flr.IsDir,
},
Size: flr.Size,
Modified: flr.Modified,
})
}

@ -36,6 +36,13 @@ func (r *ListReq) Decode(ctx *gin.Context) error {
return json.NewDecoder(ctx.Request.Body).Decode(r)
}
type EmbyFileItem struct {
*model.Item
Type string `json:"type"`
}
type EmbyFSListResp = model.VendorFSListResp[*EmbyFileItem]
func List(ctx *gin.Context) {
user := ctx.MustGet("user").(*op.User)
@ -70,7 +77,7 @@ func List(ctx *gin.Context) {
return
}
var resp model.VendorFSListResp
var resp EmbyFSListResp
for _, p := range data.Paths {
var n = p.Name
if p.Path == "1" {
@ -82,10 +89,13 @@ func List(ctx *gin.Context) {
})
}
for _, i := range data.Items {
resp.Items = append(resp.Items, &model.Item{
Name: i.Name,
Path: i.Id,
IsDir: i.IsFolder,
resp.Items = append(resp.Items, &EmbyFileItem{
Item: &model.Item{
Name: i.Name,
Path: i.Id,
IsDir: i.IsFolder,
},
Type: i.Type,
})
}

@ -10,9 +10,9 @@ type VendorMeResp[T any] struct {
Info T `json:"info,omitempty"`
}
type VendorFSListResp struct {
type VendorFSListResp[T any] struct {
Paths []*Path `json:"paths"`
Items []*Item `json:"items"`
Items []T `json:"items"`
Total uint64 `json:"total"`
}

Loading…
Cancel
Save