mirror of https://github.com/Xhofe/alist
Co-authored-by: Andy Hsu <i@nn.ci>pull/4875/head
parent
579f0c06af
commit
06f46206db
|
@ -126,7 +126,13 @@ func (d *BaiduPhoto) Link(ctx context.Context, file model.Obj, args model.LinkAr
|
|||
case *File:
|
||||
return d.linkFile(ctx, file, args)
|
||||
case *AlbumFile:
|
||||
return d.linkAlbum(ctx, file, args)
|
||||
f, err := d.CopyAlbumFile(ctx, file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.linkFile(ctx, f, args)
|
||||
// 有概率无法获取到链接
|
||||
//return d.linkAlbum(ctx, file, args)
|
||||
}
|
||||
return nil, errs.NotFile
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package baiduphoto
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/alist-org/alist/v3/drivers/base"
|
||||
|
@ -21,7 +22,7 @@ const (
|
|||
FILE_API_URL_V2 = API_URL + "/file/v2"
|
||||
)
|
||||
|
||||
func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
||||
req := base.RestyClient.R().
|
||||
SetQueryParam("access_token", d.AccessToken)
|
||||
if callback != nil {
|
||||
|
@ -52,9 +53,17 @@ func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallba
|
|||
default:
|
||||
return nil, fmt.Errorf("errno: %d, refer to https://photo.baidu.com/union/doc", erron)
|
||||
}
|
||||
return res.Body(), nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
//func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
// res, err := d.request(furl, method, callback, resp)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// return res.Body(), nil
|
||||
//}
|
||||
|
||||
func (d *BaiduPhoto) refreshToken() error {
|
||||
u := "https://openapi.baidu.com/oauth/2.0/token"
|
||||
var resp base.TokenResp
|
||||
|
@ -79,11 +88,11 @@ func (d *BaiduPhoto) refreshToken() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *BaiduPhoto) Get(furl string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
func (d *BaiduPhoto) Get(furl string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
||||
return d.Request(furl, http.MethodGet, callback, resp)
|
||||
}
|
||||
|
||||
func (d *BaiduPhoto) Post(furl string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
|
||||
func (d *BaiduPhoto) Post(furl string, callback base.ReqCallback, resp interface{}) (*resty.Response, error) {
|
||||
return d.Request(furl, http.MethodPost, callback, resp)
|
||||
}
|
||||
|
||||
|
@ -391,6 +400,49 @@ func (d *BaiduPhoto) linkFile(ctx context.Context, file *File, args model.LinkAr
|
|||
return link, nil
|
||||
}
|
||||
|
||||
func (d *BaiduPhoto) linkStreamAlbum(ctx context.Context, file *AlbumFile) (*model.Link, error) {
|
||||
return &model.Link{
|
||||
Header: http.Header{},
|
||||
Writer: func(w io.Writer) error {
|
||||
res, err := d.Get(ALBUM_API_URL+"/streaming", func(r *resty.Request) {
|
||||
r.SetContext(ctx)
|
||||
r.SetQueryParams(map[string]string{
|
||||
"fsid": fmt.Sprint(file.Fsid),
|
||||
"album_id": file.AlbumID,
|
||||
"tid": fmt.Sprint(file.Tid),
|
||||
"uk": fmt.Sprint(file.Uk),
|
||||
}).SetDoNotParseResponse(true)
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.RawBody().Close()
|
||||
_, err = io.Copy(w, res.RawBody())
|
||||
return err
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *BaiduPhoto) linkStream(ctx context.Context, file *File) (*model.Link, error) {
|
||||
return &model.Link{
|
||||
Header: http.Header{},
|
||||
Writer: func(w io.Writer) error {
|
||||
res, err := d.Get(FILE_API_URL_V1+"/streaming", func(r *resty.Request) {
|
||||
r.SetContext(ctx)
|
||||
r.SetQueryParams(map[string]string{
|
||||
"fsid": fmt.Sprint(file.Fsid),
|
||||
}).SetDoNotParseResponse(true)
|
||||
}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.RawBody().Close()
|
||||
_, err = io.Copy(w, res.RawBody())
|
||||
return err
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 获取uk
|
||||
func (d *BaiduPhoto) uInfo() (*UInfo, error) {
|
||||
var info UInfo
|
||||
|
|
Loading…
Reference in New Issue