Skip to content

Commit ef68f84

Browse files
authored
fix(baidu_photo): legal album title check (close AlistGo#4479 in AlistGo#4487)
1 parent 2c1f70f commit ef68f84

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

drivers/baidu_photo/help.go

-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"math"
66
"math/rand"
7-
"regexp"
87
"strings"
98
"time"
109

@@ -16,11 +15,6 @@ func getTid() string {
1615
return fmt.Sprintf("3%d%.0f", time.Now().Unix(), math.Floor(9000000*rand.Float64()+1000000))
1716
}
1817

19-
// 检查名称
20-
func checkName(name string) bool {
21-
return len(name) <= 50 && regexp.MustCompile("[\u4e00-\u9fa5A-Za-z0-9_-]").MatchString(name)
22-
}
23-
2418
func toTime(t int64) *time.Time {
2519
tm := time.Unix(t, 0)
2620
return &tm

drivers/baidu_photo/utils.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package baiduphoto
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"net/http"
87

@@ -22,10 +21,6 @@ const (
2221
FILE_API_URL_V2 = API_URL + "/file/v2"
2322
)
2423

25-
var (
26-
ErrNotSupportName = errors.New("only chinese and english, numbers and underscores are supported, and the length is no more than 50")
27-
)
28-
2924
func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
3025
req := base.RestyClient.R().
3126
SetQueryParam("access_token", d.AccessToken)
@@ -48,6 +43,8 @@ func (d *BaiduPhoto) Request(furl string, method string, callback base.ReqCallba
4843
return nil, fmt.Errorf("you have joined album")
4944
case 50820:
5045
return nil, fmt.Errorf("no shared albums found")
46+
case 50100:
47+
return nil, fmt.Errorf("illegal title, only supports 50 characters")
5148
case -6:
5249
if err = d.refreshToken(); err != nil {
5350
return nil, err
@@ -188,9 +185,6 @@ func (d *BaiduPhoto) GetAllAlbumFile(ctx context.Context, album *Album, passwd s
188185

189186
// 创建相册
190187
func (d *BaiduPhoto) CreateAlbum(ctx context.Context, name string) (*Album, error) {
191-
if !checkName(name) {
192-
return nil, ErrNotSupportName
193-
}
194188
var resp JoinOrCreateAlbumResp
195189
_, err := d.Post(ALBUM_API_URL+"/create", func(r *resty.Request) {
196190
r.SetContext(ctx).SetResult(&resp)
@@ -208,10 +202,6 @@ func (d *BaiduPhoto) CreateAlbum(ctx context.Context, name string) (*Album, erro
208202

209203
// 相册改名
210204
func (d *BaiduPhoto) SetAlbumName(ctx context.Context, album *Album, name string) (*Album, error) {
211-
if !checkName(name) {
212-
return nil, ErrNotSupportName
213-
}
214-
215205
_, err := d.Post(ALBUM_API_URL+"/settitle", func(r *resty.Request) {
216206
r.SetContext(ctx)
217207
r.SetFormData(map[string]string{

0 commit comments

Comments
 (0)