Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
cfaf2092
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 搜索 >>
提交
cfaf2092
编写于
4月 29, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feat: List files in COS bucket
上级
305497e7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
8 deletion
+85
-8
pkg/filesystem/driver/cos/handler.go
pkg/filesystem/driver/cos/handler.go
+75
-2
pkg/filesystem/driver/oss/handler.go
pkg/filesystem/driver/oss/handler.go
+10
-6
未找到文件。
pkg/filesystem/driver/cos/handler.go
浏览文件 @
cfaf2092
...
...
@@ -18,6 +18,9 @@ import (
"io"
"net/http"
"net/url"
"path"
"path/filepath"
"strings"
"time"
)
...
...
@@ -46,8 +49,78 @@ type Driver struct {
HTTPClient
request
.
Client
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
,
recursive
bool
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
// List 列出COS文件
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
base
string
,
recursive
bool
)
([]
response
.
Object
,
error
)
{
// 初始化列目录参数
opt
:=
&
cossdk
.
BucketGetOptions
{
Prefix
:
strings
.
TrimPrefix
(
base
,
"/"
),
EncodingType
:
""
,
MaxKeys
:
1000
,
}
// 是否为递归列出
if
!
recursive
{
opt
.
Delimiter
=
"/"
}
// 手动补齐结尾的slash
if
opt
.
Prefix
!=
""
{
opt
.
Prefix
+=
"/"
}
var
(
marker
string
objects
[]
cossdk
.
Object
commons
[]
string
)
for
{
res
,
_
,
err
:=
handler
.
Client
.
Bucket
.
Get
(
ctx
,
opt
)
if
err
!=
nil
{
return
nil
,
err
}
objects
=
append
(
objects
,
res
.
Contents
...
)
commons
=
append
(
commons
,
res
.
CommonPrefixes
...
)
// 如果本次未列取完,则继续使用marker获取结果
marker
=
res
.
NextMarker
// marker 为空时结果列取完毕,跳出
if
marker
==
""
{
break
}
}
// 处理列取结果
res
:=
make
([]
response
.
Object
,
0
,
len
(
objects
)
+
len
(
commons
))
// 处理目录
for
_
,
object
:=
range
commons
{
rel
,
err
:=
filepath
.
Rel
(
opt
.
Prefix
,
object
)
if
err
!=
nil
{
continue
}
res
=
append
(
res
,
response
.
Object
{
Name
:
path
.
Base
(
object
),
RelativePath
:
filepath
.
ToSlash
(
rel
),
Size
:
0
,
IsDir
:
true
,
LastModify
:
time
.
Now
(),
})
}
// 处理文件
for
_
,
object
:=
range
objects
{
rel
,
err
:=
filepath
.
Rel
(
opt
.
Prefix
,
object
.
Key
)
if
err
!=
nil
{
continue
}
res
=
append
(
res
,
response
.
Object
{
Name
:
path
.
Base
(
object
.
Key
),
Source
:
object
.
Key
,
RelativePath
:
filepath
.
ToSlash
(
rel
),
Size
:
uint64
(
object
.
Size
),
IsDir
:
false
,
LastModify
:
time
.
Now
(),
})
}
return
res
,
nil
}
// CORS 创建跨域策略
...
...
pkg/filesystem/driver/oss/handler.go
浏览文件 @
cfaf2092
...
...
@@ -110,15 +110,19 @@ func (handler Driver) List(ctx context.Context, base string, recursive bool) ([]
// 列取文件
base
=
strings
.
TrimPrefix
(
base
,
"/"
)
delimiter
:=
""
if
!
recursive
{
delimiter
=
"/"
if
base
!=
""
{
base
+=
"/"
}
marker
:=
""
var
(
objects
[]
oss
.
ObjectProperties
commons
[]
string
delimiter
string
marker
string
objects
[]
oss
.
ObjectProperties
commons
[]
string
)
if
!
recursive
{
delimiter
=
"/"
}
for
{
subRes
,
err
:=
handler
.
bucket
.
ListObjects
(
oss
.
Marker
(
marker
),
oss
.
Prefix
(
base
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录