Skip to content

Commit

Permalink
fix(baidu_photo): legal album title check (close #4479 in #4487)
Browse files Browse the repository at this point in the history
  • Loading branch information
foxxorcat authored May 27, 2023
1 parent 2c1f70f commit ef68f84
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
6 changes: 0 additions & 6 deletions drivers/baidu_photo/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"math"
"math/rand"
"regexp"
"strings"
"time"

Expand All @@ -16,11 +15,6 @@ func getTid() string {
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 {
tm := time.Unix(t, 0)
return &tm
Expand Down
14 changes: 2 additions & 12 deletions drivers/baidu_photo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package baiduphoto

import (
"context"
"errors"
"fmt"
"net/http"

Expand All @@ -22,10 +21,6 @@ const (
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) {
req := base.RestyClient.R().
SetQueryParam("access_token", d.AccessToken)
Expand All @@ -48,6 +43,8 @@ func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallba
return nil, fmt.Errorf("you have joined album")
case 50820:
return nil, fmt.Errorf("no shared albums found")
case 50100:
return nil, fmt.Errorf("illegal title, only supports 50 characters")
case -6:
if err = d.refreshToken(); err != nil {
return nil, err
Expand Down Expand Up @@ -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) {
if !checkName(name) {
return nil, ErrNotSupportName
}
var resp JoinOrCreateAlbumResp
_, err := d.Post(ALBUM_API_URL+"/create", func(r *resty.Request) {
r.SetContext(ctx).SetResult(&resp)
Expand All @@ -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) {
if !checkName(name) {
return nil, ErrNotSupportName
}

_, err := d.Post(ALBUM_API_URL+"/settitle", func(r *resty.Request) {
r.SetContext(ctx)
r.SetFormData(map[string]string{
Expand Down

0 comments on commit ef68f84

Please sign in to comment.