Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
0e62665d
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 搜索 >>
提交
0e62665d
编写于
1月 16, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: do hard-copy when editing file with soft links
上级
098aa0a0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
88 addition
and
1 deletion
+88
-1
models/file.go
models/file.go
+5
-0
pkg/filesystem/filesystem.go
pkg/filesystem/filesystem.go
+6
-0
pkg/filesystem/fsctx/context.go
pkg/filesystem/fsctx/context.go
+2
-0
pkg/filesystem/hooks.go
pkg/filesystem/hooks.go
+10
-0
pkg/filesystem/oss/handller.go
pkg/filesystem/oss/handller.go
+54
-0
service/explorer/file.go
service/explorer/file.go
+11
-1
未找到文件。
models/file.go
浏览文件 @
0e62665d
...
...
@@ -168,6 +168,11 @@ func (file *File) UpdateSize(value uint64) error {
return
DB
.
Model
(
&
file
)
.
Update
(
"size"
,
value
)
.
Error
}
// UpdateSourceName 更新文件的源文件名
func
(
file
*
File
)
UpdateSourceName
(
value
string
)
error
{
return
DB
.
Model
(
&
file
)
.
Update
(
"source_name"
,
value
)
.
Error
}
/*
实现 webdav.FileInfo 接口
*/
...
...
pkg/filesystem/filesystem.go
浏览文件 @
0e62665d
...
...
@@ -6,6 +6,7 @@ import (
"github.com/HFO4/cloudreve/pkg/auth"
"github.com/HFO4/cloudreve/pkg/conf"
"github.com/HFO4/cloudreve/pkg/filesystem/local"
"github.com/HFO4/cloudreve/pkg/filesystem/oss"
"github.com/HFO4/cloudreve/pkg/filesystem/qiniu"
"github.com/HFO4/cloudreve/pkg/filesystem/remote"
"github.com/HFO4/cloudreve/pkg/filesystem/response"
...
...
@@ -167,6 +168,11 @@ func (fs *FileSystem) dispatchHandler() error {
Policy
:
currentPolicy
,
}
return
nil
case
"oss"
:
fs
.
Handler
=
oss
.
Handler
{
Policy
:
currentPolicy
,
}
return
nil
default
:
return
ErrUnknownPolicyType
}
...
...
pkg/filesystem/fsctx/context.go
浏览文件 @
0e62665d
...
...
@@ -21,4 +21,6 @@ const (
UserCtx
// ThumbSizeCtx 缩略图尺寸
ThumbSizeCtx
// OriginSourceNameCtx 原始原文件名
OriginSourceNameCtx
)
pkg/filesystem/hooks.go
浏览文件 @
0e62665d
...
...
@@ -177,6 +177,16 @@ func HookGiveBackCapacity(ctx context.Context, fs *FileSystem) error {
return
nil
}
// HookUpdateSourceName 更新文件SourceName
// TODO:测试
func
HookUpdateSourceName
(
ctx
context
.
Context
,
fs
*
FileSystem
)
error
{
originFile
,
ok
:=
ctx
.
Value
(
fsctx
.
FileModelCtx
)
.
(
model
.
File
)
if
!
ok
{
return
ErrObjectNotExist
}
return
originFile
.
UpdateSourceName
(
originFile
.
SourceName
)
}
// GenericAfterUpdate 文件内容更新后
func
GenericAfterUpdate
(
ctx
context
.
Context
,
fs
*
FileSystem
)
error
{
// 更新文件尺寸
...
...
pkg/filesystem/oss/handller.go
0 → 100644
浏览文件 @
0e62665d
package
oss
import
(
"context"
"errors"
model
"github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/filesystem/response"
"github.com/HFO4/cloudreve/pkg/serializer"
"io"
"net/url"
)
// Handler 阿里云OSS策略适配器
type
Handler
struct
{
Policy
*
model
.
Policy
}
// Get 获取文件
func
(
handler
Handler
)
Get
(
ctx
context
.
Context
,
path
string
)
(
response
.
RSCloser
,
error
)
{
return
nil
,
errors
.
New
(
"未实现"
)
}
// Put 将文件流保存到指定目录
func
(
handler
Handler
)
Put
(
ctx
context
.
Context
,
file
io
.
ReadCloser
,
dst
string
,
size
uint64
)
error
{
return
errors
.
New
(
"未实现"
)
}
// Delete 删除一个或多个文件,
// 返回未删除的文件,及遇到的最后一个错误
func
(
handler
Handler
)
Delete
(
ctx
context
.
Context
,
files
[]
string
)
([]
string
,
error
)
{
return
[]
string
{},
errors
.
New
(
"未实现"
)
}
// Thumb 获取文件缩略图
func
(
handler
Handler
)
Thumb
(
ctx
context
.
Context
,
path
string
)
(
*
response
.
ContentResponse
,
error
)
{
return
nil
,
errors
.
New
(
"未实现"
)
}
// Source 获取外链URL
func
(
handler
Handler
)
Source
(
ctx
context
.
Context
,
path
string
,
baseURL
url
.
URL
,
ttl
int64
,
isDownload
bool
,
speed
int
,
)
(
string
,
error
)
{
return
""
,
errors
.
New
(
"未实现"
)
}
// Token 获取上传策略和认证Token
func
(
handler
Handler
)
Token
(
ctx
context
.
Context
,
TTL
int64
,
key
string
)
(
serializer
.
UploadCredential
,
error
)
{
return
serializer
.
UploadCredential
{},
errors
.
New
(
"未实现"
)
}
service/explorer/file.go
浏览文件 @
0e62665d
...
...
@@ -268,6 +268,7 @@ func (service *SingleFileService) PutContent(ctx context.Context, c *gin.Context
if
err
!=
nil
{
return
serializer
.
Err
(
serializer
.
CodePolicyNotAllowed
,
err
.
Error
(),
err
)
}
uploadCtx
:=
context
.
WithValue
(
ctx
,
fsctx
.
GinCtx
,
c
)
// 取得现有文件
exist
,
originFile
:=
fs
.
IsFileExist
(
service
.
Path
)
...
...
@@ -275,6 +276,16 @@ func (service *SingleFileService) PutContent(ctx context.Context, c *gin.Context
return
serializer
.
Err
(
404
,
"文件不存在"
,
nil
)
}
// 检查此文件是否有软链接
fileList
,
err
:=
model
.
RemoveFilesWithSoftLinks
([]
model
.
File
{
*
originFile
})
if
err
==
nil
&&
len
(
fileList
)
==
0
{
// 如果包含软连接,应重新生成新文件副本,并更新source_name
originFile
.
SourceName
=
fs
.
GenerateSavePath
(
uploadCtx
,
fileData
)
fs
.
Use
(
"AfterUpload"
,
filesystem
.
HookUpdateSourceName
)
fs
.
Use
(
"AfterUploadCanceled"
,
filesystem
.
HookUpdateSourceName
)
fs
.
Use
(
"AfterValidateFailed"
,
filesystem
.
HookUpdateSourceName
)
}
// 给文件系统分配钩子
fs
.
Use
(
"BeforeUpload"
,
filesystem
.
HookValidateFile
)
fs
.
Use
(
"BeforeUpload"
,
filesystem
.
HookResetPolicy
)
...
...
@@ -288,7 +299,6 @@ func (service *SingleFileService) PutContent(ctx context.Context, c *gin.Context
fs
.
Use
(
"AfterValidateFailed"
,
filesystem
.
HookGiveBackCapacity
)
// 执行上传
uploadCtx
:=
context
.
WithValue
(
ctx
,
fsctx
.
GinCtx
,
c
)
uploadCtx
=
context
.
WithValue
(
uploadCtx
,
fsctx
.
FileModelCtx
,
*
originFile
)
err
=
fs
.
Upload
(
uploadCtx
,
fileData
)
if
err
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录