Skip to content

Commit

Permalink
feat: add feijipan driver (close #5856)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jan 10, 2024
1 parent bff56ff commit 555ef0e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 37 deletions.
22 changes: 12 additions & 10 deletions drivers/ilanzou/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ type ILanZou struct {
userID string
account string
upClient *resty.Client
conf Conf
config driver.Config
}

func (d *ILanZou) Config() driver.Config {
return config
return d.config
}

func (d *ILanZou) GetAddition() driver.Additional {
Expand Down Expand Up @@ -123,19 +125,19 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
query.Set("devModel", "chrome")
query.Set("devVersion", "120")
query.Set("appVersion", "")
ts, err := getTimestamp()
ts, err := getTimestamp(d.conf.secret)
if err != nil {
return nil, err
}
query.Set("timestamp", ts)
//query.Set("appToken", d.Token)
query.Set("enable", "1")
downloadId, err := mopan.AesEncrypt([]byte(fmt.Sprintf("%s|%s", file.GetID(), d.userID)), AesSecret)
downloadId, err := mopan.AesEncrypt([]byte(fmt.Sprintf("%s|%s", file.GetID(), d.userID)), d.conf.secret)
if err != nil {
return nil, err
}
query.Set("downloadId", hex.EncodeToString(downloadId))
auth, err := mopan.AesEncrypt([]byte(fmt.Sprintf("%s|%d", file.GetID(), time.Now().UnixMilli())), AesSecret)
auth, err := mopan.AesEncrypt([]byte(fmt.Sprintf("%s|%d", file.GetID(), time.Now().UnixMilli())), d.conf.secret)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -281,7 +283,7 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
now := time.Now()
key := fmt.Sprintf("disk/%d/%d/%d/%s/%016d", now.Year(), now.Month(), now.Day(), d.account, now.UnixMilli())
var token string
if stream.GetSize() > DefaultPartSize {
if stream.GetSize() <= DefaultPartSize {
res, err := d.upClient.R().SetMultipartFormData(map[string]string{
"token": upToken,
"key": key,
Expand All @@ -294,16 +296,16 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
token = utils.Json.Get(res.Body(), "token").ToString()
} else {
keyBase64 := base64.URLEncoding.EncodeToString([]byte(key))
res, err := d.upClient.R().Post(fmt.Sprintf("https://upload.qiniup.com/buckets/wpanstore-lanzou/objects/%s/uploads", keyBase64))
res, err := d.upClient.R().SetHeader("Authorization", "UpToken "+upToken).Post(fmt.Sprintf("https://upload.qiniup.com/buckets/%s/objects/%s/uploads", d.conf.bucket, keyBase64))
if err != nil {
return nil, err
}
uploadId := utils.Json.Get(res.Body(), "uploadId").ToString()
parts := make([]Part, 0)
partNum := (stream.GetSize() + DefaultPartSize - 1) / DefaultPartSize
for i := 1; i <= int(partNum); i++ {
u := fmt.Sprintf("https://upload.qiniup.com/buckets/wpanstore-lanzou/objects/%s/uploads/%s/%d", keyBase64, uploadId, i)
res, err = d.upClient.R().SetBody(io.LimitReader(tempFile, DefaultPartSize)).Put(u)
u := fmt.Sprintf("https://upload.qiniup.com/buckets/%s/objects/%s/uploads/%s/%d", d.conf.bucket, keyBase64, uploadId, i)
res, err = d.upClient.R().SetHeader("Authorization", "UpToken "+upToken).SetBody(io.LimitReader(tempFile, DefaultPartSize)).Put(u)
if err != nil {
return nil, err
}
Expand All @@ -313,10 +315,10 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
ETag: etag,
})
}
res, err = d.upClient.R().SetBody(base.Json{
res, err = d.upClient.R().SetHeader("Authorization", "UpToken "+upToken).SetBody(base.Json{
"fnmae": stream.GetName(),
"parts": parts,
}).Post(fmt.Sprintf("https://upload.qiniup.com/buckets/wpanstore-lanzou/objects/%s/uploads/%s", keyBase64, uploadId))
}).Post(fmt.Sprintf("https://upload.qiniup.com/buckets/%s/objects/%s/uploads/%s", d.conf.bucket, keyBase64, uploadId))
if err != nil {
return nil, err
}
Expand Down
65 changes: 52 additions & 13 deletions drivers/ilanzou/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,61 @@ type Addition struct {
UUID string
}

var config = driver.Config{
Name: "ILanZou",
LocalSort: false,
OnlyLocal: false,
OnlyProxy: false,
NoCache: false,
NoUpload: false,
NeedMs: false,
DefaultRoot: "0",
CheckStatus: false,
Alert: "",
NoOverwriteUpload: false,
type Conf struct {
base string
secret []byte
bucket string
unproved string
proved string
}

func init() {
op.RegisterDriver(func() driver.Driver {
return &ILanZou{}
return &ILanZou{
config: driver.Config{
Name: "ILanZou",
LocalSort: false,
OnlyLocal: false,
OnlyProxy: false,
NoCache: false,
NoUpload: false,
NeedMs: false,
DefaultRoot: "0",
CheckStatus: false,
Alert: "",
NoOverwriteUpload: false,
},
conf: Conf{
base: "https://api.ilanzou.com",
secret: []byte("lanZouY-disk-app"),
bucket: "wpanstore-lanzou",
unproved: "unproved",
proved: "proved",
},
}
})
op.RegisterDriver(func() driver.Driver {
return &ILanZou{
config: driver.Config{
Name: "FeijiPan",
LocalSort: false,
OnlyLocal: false,
OnlyProxy: false,
NoCache: false,
NoUpload: false,
NeedMs: false,
DefaultRoot: "0",
CheckStatus: false,
Alert: "",
NoOverwriteUpload: false,
},
conf: Conf{
base: "https://api.feijipan.com",
secret: []byte("dingHao-disk-app"),
bucket: "wpanstore",
unproved: "ws",
proved: "app",
},
}
})
}
20 changes: 6 additions & 14 deletions drivers/ilanzou/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ import (
log "github.com/sirupsen/logrus"
)

const (
Base = "https://api.ilanzou.com"
)

var (
AesSecret = []byte("lanZouY-disk-app")
)

func (d *ILanZou) login() error {
res, err := d.unproved("/login", http.MethodPost, func(req *resty.Request) {
req.SetBody(base.Json{
Expand All @@ -39,10 +31,10 @@ func (d *ILanZou) login() error {
return nil
}

func getTimestamp() (string, error) {
func getTimestamp(secret []byte) (string, error) {
ts := time.Now().UnixMilli()
tsStr := strconv.FormatInt(ts, 10)
res, err := mopan.AesEncrypt([]byte(tsStr), AesSecret)
res, err := mopan.AesEncrypt([]byte(tsStr), secret)
if err != nil {
return "", err
}
Expand All @@ -51,7 +43,7 @@ func getTimestamp() (string, error) {

func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, proved bool, retry ...bool) ([]byte, error) {
req := base.RestyClient.R()
ts, err := getTimestamp()
ts, err := getTimestamp(d.conf.secret)
if err != nil {
return nil, err
}
Expand All @@ -72,7 +64,7 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
if callback != nil {
callback(req)
}
res, err := req.Execute(method, Base+pathname)
res, err := req.Execute(method, d.conf.base+pathname)
if err != nil {
if res != nil {
log.Errorf("[iLanZou] request error: %s", res.String())
Expand All @@ -97,9 +89,9 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
}

func (d *ILanZou) unproved(pathname, method string, callback base.ReqCallback) ([]byte, error) {
return d.request("/unproved"+pathname, method, callback, false)
return d.request("/"+d.conf.unproved+pathname, method, callback, false)
}

func (d *ILanZou) proved(pathname, method string, callback base.ReqCallback) ([]byte, error) {
return d.request("/proved"+pathname, method, callback, true)
return d.request("/"+d.conf.proved+pathname, method, callback, true)
}

0 comments on commit 555ef0e

Please sign in to comment.