Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
f7311f90
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 搜索 >>
提交
f7311f90
编写于
4月 24, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feat: add List method to Handler interface / implement local.List
上级
6006ff4d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
97 addition
and
2 deletion
+97
-2
pkg/filesystem/driver/cos/handler.go
pkg/filesystem/driver/cos/handler.go
+4
-0
pkg/filesystem/driver/local/handler.go
pkg/filesystem/driver/local/handler.go
+41
-0
pkg/filesystem/driver/local/handler_test.go
pkg/filesystem/driver/local/handler_test.go
+10
-0
pkg/filesystem/driver/onedrive/handler.go
pkg/filesystem/driver/onedrive/handler.go
+4
-0
pkg/filesystem/driver/oss/handler.go
pkg/filesystem/driver/oss/handler.go
+4
-0
pkg/filesystem/driver/qiniu/handler.go
pkg/filesystem/driver/qiniu/handler.go
+4
-0
pkg/filesystem/driver/remote/handler.go
pkg/filesystem/driver/remote/handler.go
+4
-0
pkg/filesystem/driver/upyun/handler.go
pkg/filesystem/driver/upyun/handler.go
+4
-0
pkg/filesystem/filesystem.go
pkg/filesystem/filesystem.go
+4
-1
pkg/filesystem/response/common.go
pkg/filesystem/response/common.go
+14
-1
pkg/filesystem/upload_test.go
pkg/filesystem/upload_test.go
+4
-0
未找到文件。
pkg/filesystem/driver/cos/handler.go
浏览文件 @
f7311f90
...
...
@@ -46,6 +46,10 @@ type Driver struct {
HTTPClient
request
.
Client
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
// CORS 创建跨域策略
func
(
handler
Driver
)
CORS
()
error
{
_
,
err
:=
handler
.
Client
.
Bucket
.
PutCORS
(
context
.
Background
(),
&
cossdk
.
BucketPutCORSOptions
{
...
...
pkg/filesystem/driver/local/handler.go
浏览文件 @
f7311f90
...
...
@@ -23,6 +23,47 @@ type Driver struct {
Policy
*
model
.
Policy
}
// List 递归列取给定物理路径下所有文件
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
var
res
[]
response
.
Object
// 取得起始路径
root
:=
util
.
RelativePath
(
filepath
.
FromSlash
(
path
))
// 开始遍历路径下的文件、目录
err
:=
filepath
.
Walk
(
root
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
// 跳过根目录
if
path
==
root
{
return
nil
}
if
err
!=
nil
{
util
.
Log
()
.
Warning
(
"无法遍历目录 %s, %s"
,
path
,
err
)
return
filepath
.
SkipDir
}
// 将遍历对象的绝对路径转换为相对路径
rel
,
err
:=
filepath
.
Rel
(
root
,
path
)
if
err
!=
nil
{
return
err
}
res
=
append
(
res
,
response
.
Object
{
Name
:
info
.
Name
(),
RelativePath
:
filepath
.
ToSlash
(
rel
),
Source
:
path
,
Size
:
uint64
(
info
.
Size
()),
IsDir
:
info
.
IsDir
(),
LastModify
:
info
.
ModTime
(),
})
return
nil
})
return
res
,
err
}
// Get 获取文件内容
func
(
handler
Driver
)
Get
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
// 打开文件
...
...
pkg/filesystem/driver/local/handler_test.go
浏览文件 @
f7311f90
...
...
@@ -2,6 +2,7 @@ package local
import
(
"context"
"fmt"
model
"github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/auth"
"github.com/HFO4/cloudreve/pkg/conf"
...
...
@@ -230,3 +231,12 @@ func TestHandler_Token(t *testing.T) {
_
,
err
:=
handler
.
Token
(
ctx
,
10
,
"123"
)
asserts
.
NoError
(
err
)
}
func
TestDriver_List
(
t
*
testing
.
T
)
{
//asserts := assert.New(t)
handler
:=
Driver
{}
ctx
:=
context
.
Background
()
res
,
err
:=
handler
.
List
(
ctx
,
"KKV"
)
fmt
.
Println
(
res
,
err
)
}
pkg/filesystem/driver/onedrive/handler.go
浏览文件 @
f7311f90
...
...
@@ -22,6 +22,10 @@ type Driver struct {
HTTPClient
request
.
Client
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
// Get 获取文件
func
(
handler
Driver
)
Get
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
// 获取文件源地址
...
...
pkg/filesystem/driver/oss/handler.go
浏览文件 @
f7311f90
...
...
@@ -42,6 +42,10 @@ type Driver struct {
HTTPClient
request
.
Client
}
func
(
handler
*
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
type
key
int
const
(
...
...
pkg/filesystem/driver/qiniu/handler.go
浏览文件 @
f7311f90
...
...
@@ -22,6 +22,10 @@ type Driver struct {
Policy
*
model
.
Policy
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
// Get 获取文件
func
(
handler
Driver
)
Get
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
// 给文件名加上随机参数以强制拉取
...
...
pkg/filesystem/driver/remote/handler.go
浏览文件 @
f7311f90
...
...
@@ -27,6 +27,10 @@ type Driver struct {
AuthInstance
auth
.
Auth
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
// getAPIUrl 获取接口请求地址
func
(
handler
Driver
)
getAPIUrl
(
scope
string
,
routes
...
string
)
string
{
serverURL
,
err
:=
url
.
Parse
(
handler
.
Policy
.
Server
)
...
...
pkg/filesystem/driver/upyun/handler.go
浏览文件 @
f7311f90
...
...
@@ -40,6 +40,10 @@ type Driver struct {
Policy
*
model
.
Policy
}
func
(
handler
Driver
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
// Get 获取文件
func
(
handler
Driver
)
Get
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
// 给文件名加上随机参数以强制拉取
...
...
pkg/filesystem/filesystem.go
浏览文件 @
f7311f90
...
...
@@ -41,7 +41,7 @@ type FileHeader interface {
GetVirtualPath
()
string
}
//
Driv
er 存储策略适配器
//
Handl
er 存储策略适配器
type
Handler
interface
{
// 上传文件, dst为文件存储路径,size 为文件大小。上下文关闭
// 时,应取消上传并清理临时文件
...
...
@@ -64,6 +64,9 @@ type Handler interface {
// Token 获取有效期为ttl的上传凭证和签名,同时回调会话有效期为sessionTTL
Token
(
ctx
context
.
Context
,
ttl
int64
,
callbackKey
string
)
(
serializer
.
UploadCredential
,
error
)
// List 递归列取远程端path路径下文件、目录,不包含path本身,返回的对象路径以path作为起始根目录
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
}
// FileSystem 管理文件的文件系统
...
...
pkg/filesystem/response/common.go
浏览文件 @
f7311f90
package
response
import
"io"
import
(
"io"
"time"
)
// ContentResponse 获取文件内容类方法的通用返回值。
// 有些上传策略需要重定向,
...
...
@@ -17,3 +20,13 @@ type RSCloser interface {
io
.
ReadSeeker
io
.
Closer
}
// Object 列出文件、目录时返回的对象
type
Object
struct
{
Name
string
RelativePath
string
Source
string
Size
uint64
IsDir
bool
LastModify
time
.
Time
}
pkg/filesystem/upload_test.go
浏览文件 @
f7311f90
...
...
@@ -26,6 +26,10 @@ type FileHeaderMock struct {
testMock
.
Mock
}
func
(
m
FileHeaderMock
)
List
(
ctx
context
.
Context
,
path
string
)
([]
response
.
Object
,
error
)
{
panic
(
"implement me"
)
}
func
(
m
FileHeaderMock
)
Get
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
args
:=
m
.
Called
(
ctx
,
path
)
return
args
.
Get
(
0
)
.
(
response
.
RSCloser
),
args
.
Error
(
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录