Skip to content

Commit 89f76d7

Browse files
zqxiaojinlj98568xhofe
authored
feat: add UC driver (close AlistGo#1127 in AlistGo#4459)
Co-authored-by: lj98568 <[email protected]> Co-authored-by: Andy Hsu <[email protected]>
1 parent ef68f84 commit 89f76d7

File tree

9 files changed

+89
-56
lines changed

9 files changed

+89
-56
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ English | [中文](./README_cn.md) | [Contributing](./CONTRIBUTING.md) | [CODE_O
6262
- [x] [YandexDisk](https://disk.yandex.com/)
6363
- [x] [BaiduNetdisk](http://pan.baidu.com/)
6464
- [x] [Terabox](https://www.terabox.com/main)
65+
- [x] [UC](https://drive.uc.cn)
6566
- [x] [Quark](https://pan.quark.cn)
6667
- [x] [Thunder](https://pan.xunlei.com)
6768
- [x] [Lanzou](https://www.lanzou.com/)

README_cn.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
- [x] [和彩云](https://yun.139.com/) (个人云, 家庭云)
6262
- [x] [Yandex.Disk](https://disk.yandex.com/)
6363
- [x] [百度网盘](http://pan.baidu.com/)
64+
- [x] [UC网盘](https://drive.uc.cn)
6465
- [x] [夸克网盘](https://pan.quark.cn)
6566
- [x] [迅雷网盘](https://pan.xunlei.com)
6667
- [x] [蓝奏云](https://www.lanzou.com/)

drivers/all.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
_ "github.com/alist-org/alist/v3/drivers/onedrive_app"
2929
_ "github.com/alist-org/alist/v3/drivers/pikpak"
3030
_ "github.com/alist-org/alist/v3/drivers/pikpak_share"
31-
_ "github.com/alist-org/alist/v3/drivers/quark"
31+
_ "github.com/alist-org/alist/v3/drivers/quark_uc"
3232
_ "github.com/alist-org/alist/v3/drivers/s3"
3333
_ "github.com/alist-org/alist/v3/drivers/seafile"
3434
_ "github.com/alist-org/alist/v3/drivers/sftp"

drivers/quark/meta.go

-26
This file was deleted.

drivers/quark/driver.go drivers/quark_uc/driver.go

+19-17
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@ import (
2222
log "github.com/sirupsen/logrus"
2323
)
2424

25-
type Quark struct {
25+
type QuarkOrUC struct {
2626
model.Storage
2727
Addition
28+
config driver.Config
29+
conf Conf
2830
}
2931

30-
func (d *Quark) Config() driver.Config {
31-
return config
32+
func (d *QuarkOrUC) Config() driver.Config {
33+
return d.config
3234
}
3335

34-
func (d *Quark) GetAddition() driver.Additional {
36+
func (d *QuarkOrUC) GetAddition() driver.Additional {
3537
return &d.Addition
3638
}
3739

38-
func (d *Quark) Init(ctx context.Context) error {
40+
func (d *QuarkOrUC) Init(ctx context.Context) error {
3941
_, err := d.request("/config", http.MethodGet, nil, nil)
4042
return err
4143
}
4244

43-
func (d *Quark) Drop(ctx context.Context) error {
45+
func (d *QuarkOrUC) Drop(ctx context.Context) error {
4446
return nil
4547
}
4648

47-
func (d *Quark) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
49+
func (d *QuarkOrUC) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
4850
files, err := d.GetFiles(dir.GetID())
4951
if err != nil {
5052
return nil, err
@@ -54,12 +56,12 @@ func (d *Quark) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
5456
})
5557
}
5658

57-
func (d *Quark) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
59+
func (d *QuarkOrUC) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
5860
data := base.Json{
5961
"fids": []string{file.GetID()},
6062
}
6163
var resp DownResp
62-
ua := "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) quark-cloud-drive/2.5.20 Chrome/100.0.4896.160 Electron/18.3.5.4-b478491100 Safari/537.36 Channel/pckk_other_ch"
64+
ua := d.conf.ua
6365
_, err := d.request("/file/download", http.MethodPost, func(req *resty.Request) {
6466
req.SetHeader("User-Agent", ua).
6567
SetBody(data)
@@ -103,7 +105,7 @@ func (d *Quark) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
103105
req.Header.Set("Range", _range)
104106
req.Header.Set("User-Agent", ua)
105107
req.Header.Set("Cookie", d.Cookie)
106-
req.Header.Set("Referer", "https://pan.quark.cn")
108+
req.Header.Set("Referer", d.conf.referer)
107109
resp, err := base.HttpClient.Do(req)
108110
if err != nil {
109111
return err
@@ -125,7 +127,7 @@ func (d *Quark) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
125127
return &link, nil
126128
}
127129

128-
func (d *Quark) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
130+
func (d *QuarkOrUC) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
129131
data := base.Json{
130132
"dir_init_lock": false,
131133
"dir_path": "",
@@ -141,7 +143,7 @@ func (d *Quark) MakeDir(ctx context.Context, parentDir model.Obj, dirName string
141143
return err
142144
}
143145

144-
func (d *Quark) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
146+
func (d *QuarkOrUC) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
145147
data := base.Json{
146148
"action_type": 1,
147149
"exclude_fids": []string{},
@@ -154,7 +156,7 @@ func (d *Quark) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
154156
return err
155157
}
156158

157-
func (d *Quark) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
159+
func (d *QuarkOrUC) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
158160
data := base.Json{
159161
"fid": srcObj.GetID(),
160162
"file_name": newName,
@@ -165,11 +167,11 @@ func (d *Quark) Rename(ctx context.Context, srcObj model.Obj, newName string) er
165167
return err
166168
}
167169

168-
func (d *Quark) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
170+
func (d *QuarkOrUC) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
169171
return errs.NotSupport
170172
}
171173

172-
func (d *Quark) Remove(ctx context.Context, obj model.Obj) error {
174+
func (d *QuarkOrUC) Remove(ctx context.Context, obj model.Obj) error {
173175
data := base.Json{
174176
"action_type": 1,
175177
"exclude_fids": []string{},
@@ -181,7 +183,7 @@ func (d *Quark) Remove(ctx context.Context, obj model.Obj) error {
181183
return err
182184
}
183185

184-
func (d *Quark) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
186+
func (d *QuarkOrUC) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
185187
tempFile, err := utils.CreateTempFile(stream.GetReadCloser())
186188
if err != nil {
187189
return err
@@ -266,4 +268,4 @@ func (d *Quark) Put(ctx context.Context, dstDir model.Obj, stream model.FileStre
266268
return d.upFinish(pre)
267269
}
268270

269-
var _ driver.Driver = (*Quark)(nil)
271+
var _ driver.Driver = (*QuarkOrUC)(nil)

drivers/quark_uc/meta.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package quark
2+
3+
import (
4+
"github.com/alist-org/alist/v3/internal/driver"
5+
"github.com/alist-org/alist/v3/internal/op"
6+
)
7+
8+
type Addition struct {
9+
Cookie string `json:"cookie" required:"true"`
10+
driver.RootID
11+
OrderBy string `json:"order_by" type:"select" options:"none,file_type,file_name,updated_at" default:"none"`
12+
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
13+
}
14+
15+
type Conf struct {
16+
ua string
17+
referer string
18+
api string
19+
pr string
20+
}
21+
22+
func init() {
23+
op.RegisterDriver(func() driver.Driver {
24+
return &QuarkOrUC{
25+
config: driver.Config{
26+
Name: "Quark",
27+
OnlyLocal: true,
28+
DefaultRoot: "0",
29+
NoOverwriteUpload: true,
30+
},
31+
conf: Conf{
32+
ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) quark-cloud-drive/2.5.20 Chrome/100.0.4896.160 Electron/18.3.5.4-b478491100 Safari/537.36 Channel/pckk_other_ch",
33+
referer: "https://pan.quark.cn",
34+
api: "https://drive.quark.cn/1/clouddrive",
35+
pr: "ucpro",
36+
},
37+
}
38+
})
39+
op.RegisterDriver(func() driver.Driver {
40+
return &QuarkOrUC{
41+
config: driver.Config{
42+
Name: "UC",
43+
OnlyLocal: true,
44+
DefaultRoot: "0",
45+
NoOverwriteUpload: true,
46+
},
47+
conf: Conf{
48+
ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) uc-cloud-drive/2.5.20 Chrome/100.0.4896.160 Electron/18.3.5.4-b478491100 Safari/537.36 Channel/pckk_other_ch",
49+
referer: "https://drive.uc.cn",
50+
api: "https://pc-api.uc.cn/1/clouddrive",
51+
pr: "UCBrowser",
52+
},
53+
}
54+
})
55+
}
File renamed without changes.

drivers/quark/util.go drivers/quark_uc/util.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import (
2222

2323
// do others that not defined in Driver interface
2424

25-
func (d *Quark) request(pathname string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
26-
u := "https://drive.quark.cn/1/clouddrive" + pathname
25+
func (d *QuarkOrUC) request(pathname string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
26+
u := d.conf.api + pathname
2727
req := base.RestyClient.R()
2828
req.SetHeaders(map[string]string{
2929
"Cookie": d.Cookie,
3030
"Accept": "application/json, text/plain, */*",
31-
"Referer": "https://pan.quark.cn/",
31+
"Referer": d.conf.referer,
3232
})
33-
req.SetQueryParam("pr", "ucpro")
33+
req.SetQueryParam("pr", d.conf.pr)
3434
req.SetQueryParam("fr", "pc")
3535
if callback != nil {
3636
callback(req)
@@ -55,7 +55,7 @@ func (d *Quark) request(pathname string, method string, callback base.ReqCallbac
5555
return res.Body(), nil
5656
}
5757

58-
func (d *Quark) GetFiles(parent string) ([]File, error) {
58+
func (d *QuarkOrUC) GetFiles(parent string) ([]File, error) {
5959
files := make([]File, 0)
6060
page := 1
6161
size := 100
@@ -85,7 +85,7 @@ func (d *Quark) GetFiles(parent string) ([]File, error) {
8585
return files, nil
8686
}
8787

88-
func (d *Quark) upPre(file model.FileStreamer, parentId string) (UpPreResp, error) {
88+
func (d *QuarkOrUC) upPre(file model.FileStreamer, parentId string) (UpPreResp, error) {
8989
now := time.Now()
9090
data := base.Json{
9191
"ccp_hash_update": true,
@@ -105,7 +105,7 @@ func (d *Quark) upPre(file model.FileStreamer, parentId string) (UpPreResp, erro
105105
return resp, err
106106
}
107107

108-
func (d *Quark) upHash(md5, sha1, taskId string) (bool, error) {
108+
func (d *QuarkOrUC) upHash(md5, sha1, taskId string) (bool, error) {
109109
data := base.Json{
110110
"md5": md5,
111111
"sha1": sha1,
@@ -119,8 +119,8 @@ func (d *Quark) upHash(md5, sha1, taskId string) (bool, error) {
119119
return resp.Data.Finish, err
120120
}
121121

122-
func (d *Quark) upPart(ctx context.Context, pre UpPreResp, mineType string, partNumber int, bytes []byte) (string, error) {
123-
//func (driver Quark) UpPart(pre UpPreResp, mineType string, partNumber int, bytes []byte, account *model.Account, md5Str, sha1Str string) (string, error) {
122+
func (d *QuarkOrUC) upPart(ctx context.Context, pre UpPreResp, mineType string, partNumber int, bytes []byte) (string, error) {
123+
//func (driver QuarkOrUC) UpPart(pre UpPreResp, mineType string, partNumber int, bytes []byte, account *model.Account, md5Str, sha1Str string) (string, error) {
124124
timeStr := time.Now().UTC().Format(http.TimeFormat)
125125
data := base.Json{
126126
"auth_info": pre.Data.AuthInfo,
@@ -169,7 +169,7 @@ x-oss-user-agent:aliyun-sdk-js/6.6.1 Chrome 98.0.4758.80 on Windows 10 64-bit
169169
return res.Header().Get("ETag"), nil
170170
}
171171

172-
func (d *Quark) upCommit(pre UpPreResp, md5s []string) error {
172+
func (d *QuarkOrUC) upCommit(pre UpPreResp, md5s []string) error {
173173
timeStr := time.Now().UTC().Format(http.TimeFormat)
174174
log.Debugf("md5s: %+v", md5s)
175175
bodyBuilder := strings.Builder{}
@@ -236,7 +236,7 @@ x-oss-user-agent:aliyun-sdk-js/6.6.1 Chrome 98.0.4758.80 on Windows 10 64-bit
236236
return nil
237237
}
238238

239-
func (d *Quark) upFinish(pre UpPreResp) error {
239+
func (d *QuarkOrUC) upFinish(pre UpPreResp) error {
240240
data := base.Json{
241241
"obj_key": pre.Data.ObjKey,
242242
"task_id": pre.Data.TaskId,

internal/model/args.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type LinkArgs struct {
1919

2020
type Link struct {
2121
URL string `json:"url"`
22-
Header http.Header `json:"header"` // needed header
22+
Header http.Header `json:"header"` // needed header (for url) or response header(for data or writer)
2323
Data io.ReadCloser // return file reader directly
2424
Status int // status maybe 200 or 206, etc
2525
FilePath *string // local file, return the filepath

0 commit comments

Comments
 (0)