mirror of https://github.com/Xhofe/alist
feat: impl link
parent
7868a1a524
commit
c39909c641
|
@ -2,7 +2,10 @@ package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -10,6 +13,7 @@ import (
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
|
"github.com/foxxorcat/mopan-sdk-go"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -17,6 +21,8 @@ import (
|
||||||
type ILanZou struct {
|
type ILanZou struct {
|
||||||
model.Storage
|
model.Storage
|
||||||
Addition
|
Addition
|
||||||
|
|
||||||
|
userID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ILanZou) Config() driver.Config {
|
func (d *ILanZou) Config() driver.Config {
|
||||||
|
@ -28,10 +34,18 @@ func (d *ILanZou) GetAddition() driver.Additional {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ILanZou) Init(ctx context.Context) error {
|
func (d *ILanZou) Init(ctx context.Context) error {
|
||||||
res, err := d.proved("/user/info/map", http.MethodGet, nil)
|
if d.UUID == "" {
|
||||||
|
res, err := d.unproved("/getUuid", http.MethodGet, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
d.UUID = utils.Json.Get(res, "uuid").ToString()
|
||||||
|
}
|
||||||
|
res, err := d.proved("/user/account/map", http.MethodGet, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
d.userID = utils.Json.Get(res, "map", "userId").ToString()
|
||||||
log.Debugf("[ilanzou] init response: %s", res)
|
log.Debugf("[ilanzou] init response: %s", res)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -89,8 +103,37 @@ func (d *ILanZou) List(ctx context.Context, dir model.Obj, args model.ListArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
||||||
// TODO return link of file, required
|
u, err := url.Parse("https://api.ilanzou.com/unproved/file/redirect")
|
||||||
return nil, errs.NotImplement
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
query := u.Query()
|
||||||
|
query.Set("uuid", d.UUID)
|
||||||
|
query.Set("devType", "6")
|
||||||
|
query.Set("devCode", d.UUID)
|
||||||
|
query.Set("devModel", "chrome")
|
||||||
|
query.Set("devVersion", "120")
|
||||||
|
query.Set("appVersion", "")
|
||||||
|
ts, err := getTimestamp()
|
||||||
|
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)
|
||||||
|
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)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
query.Set("auth", hex.EncodeToString(auth))
|
||||||
|
u.RawQuery = query.Encode()
|
||||||
|
link := model.Link{URL: u.String()}
|
||||||
|
return &link, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ILanZou) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
func (d *ILanZou) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Addition struct {
|
||||||
Password string `json:"password" type:"string" required:"true"`
|
Password string `json:"password" type:"string" required:"true"`
|
||||||
|
|
||||||
Token string
|
Token string
|
||||||
|
UUID string
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = driver.Config{
|
var config = driver.Config{
|
||||||
|
|
|
@ -56,9 +56,9 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.SetQueryParams(map[string]string{
|
req.SetQueryParams(map[string]string{
|
||||||
//"uuid": "32dcf64b-e314-4c99-b192-a0a98c5c1e5e",
|
"uuid": d.UUID,
|
||||||
"devType": "6",
|
"devType": "6",
|
||||||
//"devCode": "32dcf64b-e314-4c99-b192-a0a98c5c1e5e",
|
"devCode": d.UUID,
|
||||||
"devModel": "chrome",
|
"devModel": "chrome",
|
||||||
"devVersion": "120",
|
"devVersion": "120",
|
||||||
"appVersion": "",
|
"appVersion": "",
|
||||||
|
|
Loading…
Reference in New Issue