mirror of https://github.com/cloudreve/Cloudreve
Fix: do hard-copy when editing file with soft links
parent
098aa0a0c0
commit
0e62665d7f
|
@ -168,6 +168,11 @@ func (file *File) UpdateSize(value uint64) error {
|
||||||
return DB.Model(&file).Update("size", value).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 接口
|
实现 webdav.FileInfo 接口
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/HFO4/cloudreve/pkg/auth"
|
"github.com/HFO4/cloudreve/pkg/auth"
|
||||||
"github.com/HFO4/cloudreve/pkg/conf"
|
"github.com/HFO4/cloudreve/pkg/conf"
|
||||||
"github.com/HFO4/cloudreve/pkg/filesystem/local"
|
"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/qiniu"
|
||||||
"github.com/HFO4/cloudreve/pkg/filesystem/remote"
|
"github.com/HFO4/cloudreve/pkg/filesystem/remote"
|
||||||
"github.com/HFO4/cloudreve/pkg/filesystem/response"
|
"github.com/HFO4/cloudreve/pkg/filesystem/response"
|
||||||
|
@ -167,6 +168,11 @@ func (fs *FileSystem) dispatchHandler() error {
|
||||||
Policy: currentPolicy,
|
Policy: currentPolicy,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
case "oss":
|
||||||
|
fs.Handler = oss.Handler{
|
||||||
|
Policy: currentPolicy,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
return ErrUnknownPolicyType
|
return ErrUnknownPolicyType
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,6 @@ const (
|
||||||
UserCtx
|
UserCtx
|
||||||
// ThumbSizeCtx 缩略图尺寸
|
// ThumbSizeCtx 缩略图尺寸
|
||||||
ThumbSizeCtx
|
ThumbSizeCtx
|
||||||
|
// OriginSourceNameCtx 原始原文件名
|
||||||
|
OriginSourceNameCtx
|
||||||
)
|
)
|
||||||
|
|
|
@ -177,6 +177,16 @@ func HookGiveBackCapacity(ctx context.Context, fs *FileSystem) error {
|
||||||
return nil
|
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 文件内容更新后
|
// GenericAfterUpdate 文件内容更新后
|
||||||
func GenericAfterUpdate(ctx context.Context, fs *FileSystem) error {
|
func GenericAfterUpdate(ctx context.Context, fs *FileSystem) error {
|
||||||
// 更新文件尺寸
|
// 更新文件尺寸
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
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("未实现")
|
||||||
|
}
|
|
@ -268,6 +268,7 @@ func (service *SingleFileService) PutContent(ctx context.Context, c *gin.Context
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
return serializer.Err(serializer.CodePolicyNotAllowed, err.Error(), err)
|
||||||
}
|
}
|
||||||
|
uploadCtx := context.WithValue(ctx, fsctx.GinCtx, c)
|
||||||
|
|
||||||
// 取得现有文件
|
// 取得现有文件
|
||||||
exist, originFile := fs.IsFileExist(service.Path)
|
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)
|
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.HookValidateFile)
|
||||||
fs.Use("BeforeUpload", filesystem.HookResetPolicy)
|
fs.Use("BeforeUpload", filesystem.HookResetPolicy)
|
||||||
|
@ -288,7 +299,6 @@ func (service *SingleFileService) PutContent(ctx context.Context, c *gin.Context
|
||||||
fs.Use("AfterValidateFailed", filesystem.HookGiveBackCapacity)
|
fs.Use("AfterValidateFailed", filesystem.HookGiveBackCapacity)
|
||||||
|
|
||||||
// 执行上传
|
// 执行上传
|
||||||
uploadCtx := context.WithValue(ctx, fsctx.GinCtx, c)
|
|
||||||
uploadCtx = context.WithValue(uploadCtx, fsctx.FileModelCtx, *originFile)
|
uploadCtx = context.WithValue(uploadCtx, fsctx.FileModelCtx, *originFile)
|
||||||
err = fs.Upload(uploadCtx, fileData)
|
err = fs.Upload(uploadCtx, fileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue