feat: impl link

feat/ilanzou
Andy Hsu 2024-01-04 10:59:27 +08:00
parent 7868a1a524
commit c39909c641
3 changed files with 50 additions and 6 deletions

View File

@ -2,7 +2,10 @@ package template
import (
"context"
"encoding/hex"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
@ -10,6 +13,7 @@ import (
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/foxxorcat/mopan-sdk-go"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
)
@ -17,6 +21,8 @@ import (
type ILanZou struct {
model.Storage
Addition
userID string
}
func (d *ILanZou) Config() driver.Config {
@ -28,10 +34,18 @@ func (d *ILanZou) GetAddition() driver.Additional {
}
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 {
return err
}
d.userID = utils.Json.Get(res, "map", "userId").ToString()
log.Debugf("[ilanzou] init response: %s", res)
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) {
// TODO return link of file, required
return nil, errs.NotImplement
u, err := url.Parse("https://api.ilanzou.com/unproved/file/redirect")
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) {

View File

@ -11,6 +11,7 @@ type Addition struct {
Password string `json:"password" type:"string" required:"true"`
Token string
UUID string
}
var config = driver.Config{

View File

@ -56,9 +56,9 @@ func (d *ILanZou) request(pathname, method string, callback base.ReqCallback, pr
return nil, err
}
req.SetQueryParams(map[string]string{
//"uuid": "32dcf64b-e314-4c99-b192-a0a98c5c1e5e",
"devType": "6",
//"devCode": "32dcf64b-e314-4c99-b192-a0a98c5c1e5e",
"uuid": d.UUID,
"devType": "6",
"devCode": d.UUID,
"devModel": "chrome",
"devVersion": "120",
"appVersion": "",