Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
8a2be58e
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8a2be58e
编写于
4月 30, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feat: List files in OneDrive
上级
ce778409
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
101 addition
and
2 deletion
+101
-2
pkg/filesystem/driver/onedrive/api.go
pkg/filesystem/driver/onedrive/api.go
+39
-0
pkg/filesystem/driver/onedrive/handler.go
pkg/filesystem/driver/onedrive/handler.go
+46
-2
pkg/filesystem/driver/onedrive/types.go
pkg/filesystem/driver/onedrive/types.go
+16
-0
未找到文件。
pkg/filesystem/driver/onedrive/api.go
浏览文件 @
8a2be58e
...
...
@@ -26,6 +26,8 @@ const (
SmallFileSize
uint64
=
4
*
1024
*
1024
// ChunkSize 分片上传分片大小
ChunkSize
uint64
=
10
*
1024
*
1024
// ListRetry 列取请求重试次数
ListRetry
=
1
)
// GetSourcePath 获取文件的绝对路径
...
...
@@ -59,6 +61,43 @@ func (client *Client) getRequestURL(api string) string {
return
base
.
String
()
}
// ListChildren 根据路径列取子对象
func
(
client
*
Client
)
ListChildren
(
ctx
context
.
Context
,
path
string
)
([]
FileInfo
,
error
)
{
var
requestURL
string
dst
:=
strings
.
TrimPrefix
(
path
,
"/"
)
if
dst
==
""
{
requestURL
=
client
.
getRequestURL
(
"me/drive/root/children"
)
}
else
{
requestURL
=
client
.
getRequestURL
(
"me/drive/root:/"
+
dst
+
":/children"
)
}
res
,
err
:=
client
.
requestWithStr
(
ctx
,
"GET"
,
requestURL
+
"?$top=999999999"
,
""
,
200
)
if
err
!=
nil
{
retried
:=
0
if
v
,
ok
:=
ctx
.
Value
(
fsctx
.
RetryCtx
)
.
(
int
);
ok
{
retried
=
v
}
if
retried
<
ListRetry
{
retried
++
util
.
Log
()
.
Debug
(
"路径[%s]列取请求失败[%s],5秒钟后重试"
,
path
,
err
)
time
.
Sleep
(
time
.
Duration
(
5
)
*
time
.
Second
)
return
client
.
ListChildren
(
context
.
WithValue
(
ctx
,
fsctx
.
RetryCtx
,
retried
),
path
)
}
return
nil
,
err
}
var
(
decodeErr
error
fileInfo
ListResponse
)
decodeErr
=
json
.
Unmarshal
([]
byte
(
res
),
&
fileInfo
)
if
decodeErr
!=
nil
{
return
nil
,
decodeErr
}
return
fileInfo
.
Value
,
nil
}
// Meta 根据资源ID或文件路径获取文件元信息
func
(
client
*
Client
)
Meta
(
ctx
context
.
Context
,
id
string
,
path
string
)
(
*
FileInfo
,
error
)
{
var
requestURL
string
...
...
pkg/filesystem/driver/onedrive/handler.go
浏览文件 @
8a2be58e
...
...
@@ -12,6 +12,9 @@ import (
"github.com/HFO4/cloudreve/pkg/serializer"
"io"
"net/url"
"path"
"path/filepath"
"strings"
"time"
)
...
...
@@ -22,8 +25,49 @@ type Driver struct {
HTTPClient
request
.
Client
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
,
recursive
bool
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
// List 列取项目
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
base
string
,
recursive
bool
)
([]
response
.
Object
,
error
)
{
base
=
strings
.
TrimPrefix
(
base
,
"/"
)
// 列取子项目
objects
,
_
:=
handler
.
Client
.
ListChildren
(
ctx
,
base
)
// 获取真实的列取起始根目录
rootPath
:=
base
if
realBase
,
ok
:=
ctx
.
Value
(
fsctx
.
PathCtx
)
.
(
string
);
ok
{
rootPath
=
realBase
}
else
{
ctx
=
context
.
WithValue
(
ctx
,
fsctx
.
PathCtx
,
base
)
}
// 整理结果
res
:=
make
([]
response
.
Object
,
0
,
len
(
objects
))
for
_
,
object
:=
range
objects
{
source
:=
path
.
Join
(
base
,
object
.
Name
)
rel
,
err
:=
filepath
.
Rel
(
rootPath
,
source
)
if
err
!=
nil
{
continue
}
res
=
append
(
res
,
response
.
Object
{
Name
:
object
.
Name
,
RelativePath
:
filepath
.
ToSlash
(
rel
),
Source
:
source
,
Size
:
object
.
Size
,
IsDir
:
object
.
Folder
!=
nil
,
LastModify
:
time
.
Now
(),
})
}
// 递归列取子目录
if
recursive
{
for
_
,
object
:=
range
objects
{
if
object
.
Folder
!=
nil
{
sub
,
_
:=
handler
.
List
(
ctx
,
path
.
Join
(
base
,
object
.
Name
),
recursive
)
res
=
append
(
res
,
sub
...
)
}
}
}
return
res
,
nil
}
// Get 获取文件
...
...
pkg/filesystem/driver/onedrive/types.go
浏览文件 @
8a2be58e
...
...
@@ -32,6 +32,16 @@ type FileInfo struct {
Image
imageInfo
`json:"image"`
ParentReference
parentReference
`json:"parentReference"`
DownloadURL
string
`json:"@microsoft.graph.downloadUrl"`
File
*
file
`json:"file"`
Folder
*
folder
`json:"folder"`
}
type
file
struct
{
MimeType
string
`json:"mimeType"`
}
type
folder
struct
{
ChildCount
int
`json:"childCount"`
}
type
imageInfo
struct
{
...
...
@@ -83,6 +93,12 @@ type ThumbResponse struct {
URL
string
`json:"url"`
}
// ListResponse 列取子项目响应
type
ListResponse
struct
{
Value
[]
FileInfo
`json:"value"`
Context
string
`json:"@odata.context"`
}
// Chunk 文件分片
type
Chunk
struct
{
Offset
int
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录