Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
514e0691
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,发现更多精彩内容 >>
提交
514e0691
编写于
4月 22, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor: decide if there is a thumbnail based on the file extension
上级
7b571499
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
8 deletion
+29
-8
assets
assets
+1
-1
models/policy.go
models/policy.go
+23
-5
pkg/filesystem/file.go
pkg/filesystem/file.go
+5
-0
pkg/filesystem/hooks.go
pkg/filesystem/hooks.go
+0
-2
未找到文件。
assets
@
c5e374fd
比较
380f844e
...
c5e374fd
Subproject commit
380f844eb9e05d7b3b7746dca9f449a56bf69185
Subproject commit
c5e374fd2c8cdfe8a4bece60dba7d27b047eb0f1
models/policy.go
浏览文件 @
514e0691
...
@@ -8,7 +8,9 @@ import (
...
@@ -8,7 +8,9 @@ import (
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm"
"net/url"
"net/url"
"path"
"path"
"path/filepath"
"strconv"
"strconv"
"strings"
"time"
"time"
)
)
...
@@ -48,6 +50,16 @@ type PolicyOption struct {
...
@@ -48,6 +50,16 @@ type PolicyOption struct {
OdRedirect
string
`json:"od_redirect,omitempty"`
OdRedirect
string
`json:"od_redirect,omitempty"`
}
}
var
thumbSuffix
=
map
[
string
][]
string
{
"local"
:
{},
"qiniu"
:
{
".psd"
,
".jpg"
,
".jpeg"
,
".png"
,
".gif"
,
".webp"
,
".tiff"
,
".bmp"
},
"oss"
:
{
".jpg"
,
".jpeg"
,
".png"
,
".gif"
,
".webp"
,
".tiff"
,
".bmp"
},
"cos"
:
{},
"upyun"
:
{
".svg"
,
".jpg"
,
".jpeg"
,
".png"
,
".gif"
,
".webp"
,
".tiff"
,
".bmp"
},
"remote"
:
{},
"onedrive"
:
{
"*"
},
}
func
init
()
{
func
init
()
{
// 注册缓存用到的复杂结构
// 注册缓存用到的复杂结构
gob
.
Register
(
Policy
{})
gob
.
Register
(
Policy
{})
...
@@ -178,6 +190,17 @@ func (policy *Policy) IsDirectlyPreview() bool {
...
@@ -178,6 +190,17 @@ func (policy *Policy) IsDirectlyPreview() bool {
return
policy
.
Type
==
"local"
return
policy
.
Type
==
"local"
}
}
// IsThumbExist 给定文件名,返回此存储策略下是否可能存在缩略图
func
(
policy
*
Policy
)
IsThumbExist
(
name
string
)
bool
{
if
list
,
ok
:=
thumbSuffix
[
policy
.
Type
];
ok
{
if
len
(
list
)
==
1
&&
list
[
0
]
==
"*"
{
return
true
}
return
util
.
ContainsString
(
list
,
strings
.
ToLower
(
filepath
.
Ext
(
name
)))
}
return
false
}
// IsTransitUpload 返回此策略上传给定size文件时是否需要服务端中转
// IsTransitUpload 返回此策略上传给定size文件时是否需要服务端中转
func
(
policy
*
Policy
)
IsTransitUpload
(
size
uint64
)
bool
{
func
(
policy
*
Policy
)
IsTransitUpload
(
size
uint64
)
bool
{
if
policy
.
Type
==
"local"
{
if
policy
.
Type
==
"local"
{
...
@@ -199,11 +222,6 @@ func (policy *Policy) IsThumbGenerateNeeded() bool {
...
@@ -199,11 +222,6 @@ func (policy *Policy) IsThumbGenerateNeeded() bool {
return
policy
.
Type
==
"local"
return
policy
.
Type
==
"local"
}
}
// IsMockThumbNeeded 返回此策略是否需要在上传后默认当图像文件
func
(
policy
*
Policy
)
IsMockThumbNeeded
()
bool
{
return
policy
.
Type
==
"onedrive"
}
// GetUploadURL 获取文件上传服务API地址
// GetUploadURL 获取文件上传服务API地址
func
(
policy
*
Policy
)
GetUploadURL
()
string
{
func
(
policy
*
Policy
)
GetUploadURL
()
string
{
server
,
err
:=
url
.
Parse
(
policy
.
Server
)
server
,
err
:=
url
.
Parse
(
policy
.
Server
)
...
...
pkg/filesystem/file.go
浏览文件 @
514e0691
...
@@ -63,6 +63,11 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
...
@@ -63,6 +63,11 @@ func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model
FolderID
:
parent
.
ID
,
FolderID
:
parent
.
ID
,
PolicyID
:
fs
.
User
.
Policy
.
ID
,
PolicyID
:
fs
.
User
.
Policy
.
ID
,
}
}
if
fs
.
User
.
Policy
.
IsThumbExist
(
file
.
GetFileName
())
{
newFile
.
PicInfo
=
"1,1"
}
_
,
err
=
newFile
.
Create
()
_
,
err
=
newFile
.
Create
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/filesystem/hooks.go
浏览文件 @
514e0691
...
@@ -297,8 +297,6 @@ func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
...
@@ -297,8 +297,6 @@ func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
// 异步尝试生成缩略图
// 异步尝试生成缩略图
if
fs
.
User
.
Policy
.
IsThumbGenerateNeeded
()
{
if
fs
.
User
.
Policy
.
IsThumbGenerateNeeded
()
{
go
fs
.
GenerateThumbnail
(
ctx
,
file
)
go
fs
.
GenerateThumbnail
(
ctx
,
file
)
}
else
if
fs
.
User
.
Policy
.
IsMockThumbNeeded
()
{
file
.
UpdatePicInfo
(
"1,1"
)
}
}
return
nil
return
nil
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录