Skip to content

Commit 477c439

Browse files
anobodysanobodys
andauthored
feat(doubao_share): support doubao_share link (#8376)
Co-authored-by: anobodys <anobodys@gmail.com>
1 parent 0a9921f commit 477c439

File tree

5 files changed

+1161
-0
lines changed

5 files changed

+1161
-0
lines changed

drivers/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
_ "github.com/alist-org/alist/v3/drivers/cloudreve"
2525
_ "github.com/alist-org/alist/v3/drivers/crypt"
2626
_ "github.com/alist-org/alist/v3/drivers/doubao"
27+
_ "github.com/alist-org/alist/v3/drivers/doubao_share"
2728
_ "github.com/alist-org/alist/v3/drivers/dropbox"
2829
_ "github.com/alist-org/alist/v3/drivers/febbox"
2930
_ "github.com/alist-org/alist/v3/drivers/ftp"

drivers/doubao_share/driver.go

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package doubao_share
2+
3+
import (
4+
"context"
5+
"errors"
6+
"github.com/alist-org/alist/v3/drivers/base"
7+
"github.com/alist-org/alist/v3/internal/driver"
8+
"github.com/alist-org/alist/v3/internal/errs"
9+
"github.com/alist-org/alist/v3/internal/model"
10+
"github.com/go-resty/resty/v2"
11+
"net/http"
12+
)
13+
14+
type DoubaoShare struct {
15+
model.Storage
16+
Addition
17+
RootFiles []RootFileList
18+
}
19+
20+
func (d *DoubaoShare) Config() driver.Config {
21+
return config
22+
}
23+
24+
func (d *DoubaoShare) GetAddition() driver.Additional {
25+
return &d.Addition
26+
}
27+
28+
func (d *DoubaoShare) Init(ctx context.Context) error {
29+
// 初始化 虚拟分享列表
30+
if err := d.initShareList(); err != nil {
31+
return err
32+
}
33+
34+
return nil
35+
}
36+
37+
func (d *DoubaoShare) Drop(ctx context.Context) error {
38+
return nil
39+
}
40+
41+
func (d *DoubaoShare) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
42+
// 检查是否为根目录
43+
if dir.GetID() == "" && dir.GetPath() == "/" {
44+
return d.listRootDirectory(ctx)
45+
}
46+
47+
// 非根目录,处理不同情况
48+
if fo, ok := dir.(*FileObject); ok {
49+
if fo.ShareID == "" {
50+
// 虚拟目录,需要列出子目录
51+
return d.listVirtualDirectoryContent(dir)
52+
} else {
53+
// 具有分享ID的目录,获取此分享下的文件
54+
shareId, relativePath, err := d._findShareAndPath(dir)
55+
if err != nil {
56+
return nil, err
57+
}
58+
return d.getFilesInPath(ctx, shareId, dir.GetID(), relativePath)
59+
}
60+
}
61+
62+
// 使用通用方法
63+
shareId, relativePath, err := d._findShareAndPath(dir)
64+
if err != nil {
65+
return nil, err
66+
}
67+
68+
// 获取指定路径下的文件
69+
return d.getFilesInPath(ctx, shareId, dir.GetID(), relativePath)
70+
}
71+
72+
func (d *DoubaoShare) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
73+
var downloadUrl string
74+
75+
if u, ok := file.(*FileObject); ok {
76+
switch u.NodeType {
77+
case VideoType, AudioType:
78+
var r GetVideoFileUrlResp
79+
_, err := d.request("/samantha/media/get_play_info", http.MethodPost, func(req *resty.Request) {
80+
req.SetBody(base.Json{
81+
"key": u.Key,
82+
"share_id": u.ShareID,
83+
"node_id": file.GetID(),
84+
})
85+
}, &r)
86+
if err != nil {
87+
return nil, err
88+
}
89+
90+
downloadUrl = r.Data.OriginalMediaInfo.MainURL
91+
default:
92+
var r GetFileUrlResp
93+
_, err := d.request("/alice/message/get_file_url", http.MethodPost, func(req *resty.Request) {
94+
req.SetBody(base.Json{
95+
"uris": []string{u.Key},
96+
"type": FileNodeType[u.NodeType],
97+
})
98+
}, &r)
99+
if err != nil {
100+
return nil, err
101+
}
102+
103+
downloadUrl = r.Data.FileUrls[0].MainURL
104+
}
105+
106+
// 生成标准的Content-Disposition
107+
contentDisposition := generateContentDisposition(u.Name)
108+
109+
return &model.Link{
110+
URL: downloadUrl,
111+
Header: http.Header{
112+
"User-Agent": []string{UserAgent},
113+
"Content-Disposition": []string{contentDisposition},
114+
},
115+
}, nil
116+
}
117+
118+
return nil, errors.New("can't convert obj to URL")
119+
}
120+
121+
func (d *DoubaoShare) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
122+
// TODO create folder, optional
123+
return nil, errs.NotImplement
124+
}
125+
126+
func (d *DoubaoShare) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) {
127+
// TODO move obj, optional
128+
return nil, errs.NotImplement
129+
}
130+
131+
func (d *DoubaoShare) Rename(ctx context.Context, srcObj model.Obj, newName string) (model.Obj, error) {
132+
// TODO rename obj, optional
133+
return nil, errs.NotImplement
134+
}
135+
136+
func (d *DoubaoShare) Copy(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) {
137+
// TODO copy obj, optional
138+
return nil, errs.NotImplement
139+
}
140+
141+
func (d *DoubaoShare) Remove(ctx context.Context, obj model.Obj) error {
142+
// TODO remove obj, optional
143+
return errs.NotImplement
144+
}
145+
146+
func (d *DoubaoShare) Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up driver.UpdateProgress) (model.Obj, error) {
147+
// TODO upload file, optional
148+
return nil, errs.NotImplement
149+
}
150+
151+
func (d *DoubaoShare) GetArchiveMeta(ctx context.Context, obj model.Obj, args model.ArchiveArgs) (model.ArchiveMeta, error) {
152+
// TODO get archive file meta-info, return errs.NotImplement to use an internal archive tool, optional
153+
return nil, errs.NotImplement
154+
}
155+
156+
func (d *DoubaoShare) ListArchive(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) ([]model.Obj, error) {
157+
// TODO list args.InnerPath in the archive obj, return errs.NotImplement to use an internal archive tool, optional
158+
return nil, errs.NotImplement
159+
}
160+
161+
func (d *DoubaoShare) Extract(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) (*model.Link, error) {
162+
// TODO return link of file args.InnerPath in the archive obj, return errs.NotImplement to use an internal archive tool, optional
163+
return nil, errs.NotImplement
164+
}
165+
166+
func (d *DoubaoShare) ArchiveDecompress(ctx context.Context, srcObj, dstDir model.Obj, args model.ArchiveDecompressArgs) ([]model.Obj, error) {
167+
// TODO extract args.InnerPath path in the archive srcObj to the dstDir location, optional
168+
// a folder with the same name as the archive file needs to be created to store the extracted results if args.PutIntoNewDir
169+
// return errs.NotImplement to use an internal archive tool
170+
return nil, errs.NotImplement
171+
}
172+
173+
//func (d *DoubaoShare) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
174+
// return nil, errs.NotSupport
175+
//}
176+
177+
var _ driver.Driver = (*DoubaoShare)(nil)

drivers/doubao_share/meta.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package doubao_share
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+
driver.RootPath
10+
Cookie string `json:"cookie" type:"text"`
11+
ShareIds string `json:"share_ids" type:"text" required:"true"`
12+
}
13+
14+
var config = driver.Config{
15+
Name: "DoubaoShare",
16+
LocalSort: true,
17+
OnlyLocal: false,
18+
OnlyProxy: false,
19+
NoCache: false,
20+
NoUpload: true,
21+
NeedMs: false,
22+
DefaultRoot: "/",
23+
CheckStatus: false,
24+
Alert: "",
25+
NoOverwriteUpload: false,
26+
}
27+
28+
func init() {
29+
op.RegisterDriver(func() driver.Driver {
30+
return &DoubaoShare{}
31+
})
32+
}

0 commit comments

Comments
 (0)