mirror of https://github.com/Xhofe/alist
* feat(cloudreve): support thumbnail * chore: remove unnecessary codepull/5391/head
parent
b9e192b29c
commit
7f7335435c
|
@ -49,7 +49,11 @@ func (d *Cloudreve) List(ctx context.Context, dir model.Obj, args model.ListArgs
|
|||
}
|
||||
|
||||
return utils.SliceConvert(r.Objects, func(src Object) (model.Obj, error) {
|
||||
return objectToObj(src), nil
|
||||
thumb, err := d.GetThumb(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return objectToObj(src, thumb), nil
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -44,13 +44,16 @@ type Object struct {
|
|||
SourceEnabled bool `json:"source_enabled"`
|
||||
}
|
||||
|
||||
func objectToObj(f Object) *model.Object {
|
||||
return &model.Object{
|
||||
func objectToObj(f Object, t model.Thumbnail) *model.ObjThumb {
|
||||
return &model.ObjThumb{
|
||||
Object: model.Object{
|
||||
ID: f.Id,
|
||||
Name: f.Name,
|
||||
Size: int64(f.Size),
|
||||
Modified: f.Date,
|
||||
IsFolder: f.Type == "dir",
|
||||
},
|
||||
Thumbnail: t,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,3 +149,23 @@ func convertSrc(obj model.Obj) map[string]interface{} {
|
|||
m["items"] = items
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *Cloudreve) GetThumb(file Object) (model.Thumbnail, error) {
|
||||
ua := d.CustomUA
|
||||
if ua == "" {
|
||||
ua = base.UserAgent
|
||||
}
|
||||
req := base.NoRedirectClient.R()
|
||||
req.SetHeaders(map[string]string{
|
||||
"Cookie": "cloudreve-session=" + d.Cookie,
|
||||
"Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
||||
"User-Agent": ua,
|
||||
})
|
||||
resp, err := req.Execute(http.MethodGet, d.Address+"/api/v3/file/thumb/"+file.Id)
|
||||
if err != nil {
|
||||
return model.Thumbnail{}, err
|
||||
}
|
||||
return model.Thumbnail{
|
||||
Thumbnail: resp.Header().Get("Location"),
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue