Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
58856612
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 搜索 >>
提交
58856612
编写于
5月 09, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Feat: create empty file in web panel (#305)
上级
ee0f224c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
2 deletion
+51
-2
assets
assets
+1
-1
routers/controllers/file.go
routers/controllers/file.go
+11
-0
routers/router.go
routers/router.go
+2
-0
service/explorer/file.go
service/explorer/file.go
+37
-1
未找到文件。
assets
@
538bd95a
比较
6d23b07b
...
538bd95a
Subproject commit
6d23b07b7ae655d1ecba23c21a0482950587b4f0
Subproject commit
538bd95a7ba1712bf8b079375d1aa419d803273a
routers/controllers/file.go
浏览文件 @
58856612
...
...
@@ -353,3 +353,14 @@ func SearchFile(c *gin.Context) {
c
.
JSON
(
200
,
ErrorResponse
(
err
))
}
}
// CreateFile 创建空白文件
func
CreateFile
(
c
*
gin
.
Context
)
{
var
service
explorer
.
SingleFileService
if
err
:=
c
.
ShouldBindJSON
(
&
service
);
err
==
nil
{
res
:=
service
.
Create
(
c
)
c
.
JSON
(
200
,
res
)
}
else
{
c
.
JSON
(
200
,
ErrorResponse
(
err
))
}
}
routers/router.go
浏览文件 @
58856612
...
...
@@ -445,6 +445,8 @@ func InitMasterRouter() *gin.Engine {
file
.
GET
(
"upload/credential"
,
controllers
.
GetUploadCredential
)
// 更新文件
file
.
PUT
(
"update/:id"
,
controllers
.
PutContent
)
// 创建空白文件
file
.
POST
(
"create"
,
controllers
.
CreateFile
)
// 创建文件下载会话
file
.
PUT
(
"download/:id"
,
controllers
.
CreateDownloadSession
)
// 预览文件
...
...
service/explorer/file.go
浏览文件 @
58856612
...
...
@@ -13,15 +13,18 @@ import (
"github.com/HFO4/cloudreve/pkg/serializer"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"io/ioutil"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"
)
// SingleFileService 对单文件进行操作的五福,path为文件完整路径
type
SingleFileService
struct
{
Path
string
`uri:"path" binding:"required,min=1,max=65535"`
Path
string
`uri:"path"
json:"path"
binding:"required,min=1,max=65535"`
}
// FileIDService 通过文件ID对文件进行操作的服务
...
...
@@ -62,6 +65,39 @@ type SlaveListService struct {
Recursive
bool
`json:"recursive"`
}
// New 创建新文件
func
(
service
*
SingleFileService
)
Create
(
c
*
gin
.
Context
)
serializer
.
Response
{
// 创建文件系统
fs
,
err
:=
filesystem
.
NewFileSystemFromContext
(
c
)
if
err
!=
nil
{
return
serializer
.
Err
(
serializer
.
CodePolicyNotAllowed
,
err
.
Error
(),
err
)
}
defer
fs
.
Recycle
()
// 上下文
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
// 给文件系统分配钩子
fs
.
Use
(
"BeforeUpload"
,
filesystem
.
HookValidateFile
)
fs
.
Use
(
"AfterUpload"
,
filesystem
.
GenericAfterUpload
)
// 上传空文件
err
=
fs
.
Upload
(
ctx
,
local
.
FileStream
{
File
:
ioutil
.
NopCloser
(
strings
.
NewReader
(
""
)),
Size
:
0
,
VirtualPath
:
path
.
Dir
(
service
.
Path
),
Name
:
path
.
Base
(
service
.
Path
),
})
if
err
!=
nil
{
return
serializer
.
Err
(
serializer
.
CodeUploadFailed
,
err
.
Error
(),
err
)
}
return
serializer
.
Response
{
Code
:
0
,
}
}
// List 列出从机上的文件
func
(
service
*
SlaveListService
)
List
(
c
*
gin
.
Context
)
serializer
.
Response
{
// 创建文件系统
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录