parent
2c1f70fbe9
commit
ef68f84787
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -16,11 +15,6 @@ func getTid() string {
|
|||||||
return fmt.Sprintf("3%d%.0f", time.Now().Unix(), math.Floor(9000000*rand.Float64()+1000000))
|
return fmt.Sprintf("3%d%.0f", time.Now().Unix(), math.Floor(9000000*rand.Float64()+1000000))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查名称
|
|
||||||
func checkName(name string) bool {
|
|
||||||
return len(name) <= 50 && regexp.MustCompile("[\u4e00-\u9fa5A-Za-z0-9_-]").MatchString(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func toTime(t int64) *time.Time {
|
func toTime(t int64) *time.Time {
|
||||||
tm := time.Unix(t, 0)
|
tm := time.Unix(t, 0)
|
||||||
return &tm
|
return &tm
|
||||||
|
@ -2,7 +2,6 @@ package baiduphoto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -22,10 +21,6 @@ const (
|
|||||||
FILE_API_URL_V2 = API_URL + "/file/v2"
|
FILE_API_URL_V2 = API_URL + "/file/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNotSupportName = errors.New("only chinese and english, numbers and underscores are supported, and the length is no more than 50")
|
|
||||||
)
|
|
||||||
|
|
||||||
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{}) ([]byte, error) {
|
||||||
req := base.RestyClient.R().
|
req := base.RestyClient.R().
|
||||||
SetQueryParam("access_token", d.AccessToken)
|
SetQueryParam("access_token", d.AccessToken)
|
||||||
@ -48,6 +43,8 @@ func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallba
|
|||||||
return nil, fmt.Errorf("you have joined album")
|
return nil, fmt.Errorf("you have joined album")
|
||||||
case 50820:
|
case 50820:
|
||||||
return nil, fmt.Errorf("no shared albums found")
|
return nil, fmt.Errorf("no shared albums found")
|
||||||
|
case 50100:
|
||||||
|
return nil, fmt.Errorf("illegal title, only supports 50 characters")
|
||||||
case -6:
|
case -6:
|
||||||
if err = d.refreshToken(); err != nil {
|
if err = d.refreshToken(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -188,9 +185,6 @@ func (d *BaiduPhoto) GetAllAlbumFile(ctx context.Context, album *Album, passwd s
|
|||||||
|
|
||||||
// 创建相册
|
// 创建相册
|
||||||
func (d *BaiduPhoto) CreateAlbum(ctx context.Context, name string) (*Album, error) {
|
func (d *BaiduPhoto) CreateAlbum(ctx context.Context, name string) (*Album, error) {
|
||||||
if !checkName(name) {
|
|
||||||
return nil, ErrNotSupportName
|
|
||||||
}
|
|
||||||
var resp JoinOrCreateAlbumResp
|
var resp JoinOrCreateAlbumResp
|
||||||
_, err := d.Post(ALBUM_API_URL+"/create", func(r *resty.Request) {
|
_, err := d.Post(ALBUM_API_URL+"/create", func(r *resty.Request) {
|
||||||
r.SetContext(ctx).SetResult(&resp)
|
r.SetContext(ctx).SetResult(&resp)
|
||||||
@ -208,10 +202,6 @@ func (d *BaiduPhoto) CreateAlbum(ctx context.Context, name string) (*Album, erro
|
|||||||
|
|
||||||
// 相册改名
|
// 相册改名
|
||||||
func (d *BaiduPhoto) SetAlbumName(ctx context.Context, album *Album, name string) (*Album, error) {
|
func (d *BaiduPhoto) SetAlbumName(ctx context.Context, album *Album, name string) (*Album, error) {
|
||||||
if !checkName(name) {
|
|
||||||
return nil, ErrNotSupportName
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := d.Post(ALBUM_API_URL+"/settitle", func(r *resty.Request) {
|
_, err := d.Post(ALBUM_API_URL+"/settitle", func(r *resty.Request) {
|
||||||
r.SetContext(ctx)
|
r.SetContext(ctx)
|
||||||
r.SetFormData(map[string]string{
|
r.SetFormData(map[string]string{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user