mirror of https://github.com/Xhofe/alist
feat: add `feijipan` driver (close #5856)
parent
bff56ffd0f
commit
555ef0eb1a
|
@ -30,10 +30,12 @@ type ILanZou struct {
|
||||||
userID string
|
userID string
|
||||||
account string
|
account string
|
||||||
upClient *resty.Client
|
upClient *resty.Client
|
||||||
|
conf Conf
|
||||||
|
config driver.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ILanZou) Config() driver.Config {
|
func (d *ILanZou) Config() driver.Config {
|
||||||
return config
|
return d.config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ILanZou) GetAddition() driver.Additional {
|
func (d *ILanZou) GetAddition() driver.Additional {
|
||||||
|
@ -123,19 +125,19 @@ func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
||||||
query.Set("devModel", "chrome")
|
query.Set("devModel", "chrome")
|
||||||
query.Set("devVersion", "120")
|
query.Set("devVersion", "120")
|
||||||
query.Set("appVersion", "")
|
query.Set("appVersion", "")
|
||||||
ts, err := getTimestamp()
|
ts, err := getTimestamp(d.conf.secret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
query.Set("timestamp", ts)
|
query.Set("timestamp", ts)
|
||||||
//query.Set("appToken", d.Token)
|
//query.Set("appToken", d.Token)
|
||||||
query.Set("enable", "1")
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
query.Set("downloadId", hex.EncodeToString(downloadId))
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -281,7 +283,7 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
key := fmt.Sprintf("disk/%d/%d/%d/%s/%016d", now.Year(), now.Month(), now.Day(), d.account, now.UnixMilli())
|
key := fmt.Sprintf("disk/%d/%d/%d/%s/%016d", now.Year(), now.Month(), now.Day(), d.account, now.UnixMilli())
|
||||||
var token string
|
var token string
|
||||||
if stream.GetSize() > DefaultPartSize {
|
if stream.GetSize() <= DefaultPartSize {
|
||||||
res, err := d.upClient.R().SetMultipartFormData(map[string]string{
|
res, err := d.upClient.R().SetMultipartFormData(map[string]string{
|
||||||
"token": upToken,
|
"token": upToken,
|
||||||
"key": key,
|
"key": key,
|
||||||
|
@ -294,7 +296,7 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
|
||||||
token = utils.Json.Get(res.Body(), "token").ToString()
|
token = utils.Json.Get(res.Body(), "token").ToString()
|
||||||
} else {
|
} else {
|
||||||
keyBase64 := base64.URLEncoding.EncodeToString([]byte(key))
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -302,8 +304,8 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
|
||||||
parts := make([]Part, 0)
|
parts := make([]Part, 0)
|
||||||
partNum := (stream.GetSize() + DefaultPartSize - 1) / DefaultPartSize
|
partNum := (stream.GetSize() + DefaultPartSize - 1) / DefaultPartSize
|
||||||
for i := 1; i <= int(partNum); i++ {
|
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)
|
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().SetBody(io.LimitReader(tempFile, DefaultPartSize)).Put(u)
|
res, err = d.upClient.R().SetHeader("Authorization", "UpToken "+upToken).SetBody(io.LimitReader(tempFile, DefaultPartSize)).Put(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -313,10 +315,10 @@ func (d *ILanZou) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
|
||||||
ETag: etag,
|
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(),
|
"fnmae": stream.GetName(),
|
||||||
"parts": parts,
|
"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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,18 @@ type Addition struct {
|
||||||
UUID string
|
UUID string
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = driver.Config{
|
type Conf struct {
|
||||||
|
base string
|
||||||
|
secret []byte
|
||||||
|
bucket string
|
||||||
|
unproved string
|
||||||
|
proved string
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
op.RegisterDriver(func() driver.Driver {
|
||||||
|
return &ILanZou{
|
||||||
|
config: driver.Config{
|
||||||
Name: "ILanZou",
|
Name: "ILanZou",
|
||||||
LocalSort: false,
|
LocalSort: false,
|
||||||
OnlyLocal: false,
|
OnlyLocal: false,
|
||||||
|
@ -26,10 +37,38 @@ var config = driver.Config{
|
||||||
CheckStatus: false,
|
CheckStatus: false,
|
||||||
Alert: "",
|
Alert: "",
|
||||||
NoOverwriteUpload: false,
|
NoOverwriteUpload: false,
|
||||||
|
},
|
||||||
|
conf: Conf{
|
||||||
|
base: "https://api.ilanzou.com",
|
||||||
|
secret: []byte("lanZouY-disk-app"),
|
||||||
|
bucket: "wpanstore-lanzou",
|
||||||
|
unproved: "unproved",
|
||||||
|
proved: "proved",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
})
|
||||||
func init() {
|
|
||||||
op.RegisterDriver(func() driver.Driver {
|
op.RegisterDriver(func() driver.Driver {
|
||||||
return &ILanZou{}
|
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",
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,6 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
Base = "https://api.ilanzou.com"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
AesSecret = []byte("lanZouY-disk-app")
|
|
||||||
)
|
|
||||||
|
|
||||||
func (d *ILanZou) login() error {
|
func (d *ILanZou) login() error {
|
||||||
res, err := d.unproved("/login", http.MethodPost, func(req *resty.Request) {
|
res, err := d.unproved("/login", http.MethodPost, func(req *resty.Request) {
|
||||||
req.SetBody(base.Json{
|
req.SetBody(base.Json{
|
||||||
|
@ -39,10 +31,10 @@ func (d *ILanZou) login() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTimestamp() (string, error) {
|
func getTimestamp(secret []byte) (string, error) {
|
||||||
ts := time.Now().UnixMilli()
|
ts := time.Now().UnixMilli()
|
||||||
tsStr := strconv.FormatInt(ts, 10)
|
tsStr := strconv.FormatInt(ts, 10)
|
||||||
res, err := mopan.AesEncrypt([]byte(tsStr), AesSecret)
|
res, err := mopan.AesEncrypt([]byte(tsStr), secret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -51,7 +43,7 @@ func getTimestamp() (string, error) {
|
||||||
|
|
||||||
func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, proved bool, retry ...bool) ([]byte, error) {
|
func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, proved bool, retry ...bool) ([]byte, error) {
|
||||||
req := base.RestyClient.R()
|
req := base.RestyClient.R()
|
||||||
ts, err := getTimestamp()
|
ts, err := getTimestamp(d.conf.secret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -72,7 +64,7 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
|
||||||
if callback != nil {
|
if callback != nil {
|
||||||
callback(req)
|
callback(req)
|
||||||
}
|
}
|
||||||
res, err := req.Execute(method, Base+pathname)
|
res, err := req.Execute(method, d.conf.base+pathname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res != nil {
|
if res != nil {
|
||||||
log.Errorf("[iLanZou] request error: %s", res.String())
|
log.Errorf("[iLanZou] request error: %s", res.String())
|
||||||
|
@ -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) {
|
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) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue