Merge pull request #1 from cloudreve/master

merge
pull/521/head
Lones 5 years ago committed by GitHub
commit f8f013c996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 6d23b07b7ae655d1ecba23c21a0482950587b4f0
Subproject commit 63ee122d977284e3ccf20f4c1ed228584e705c4d

@ -90,6 +90,7 @@ func addDefaultSettings() {
{Name: "replyTo", Value: `abslant@126.com`, Type: "mail"},
{Name: "smtpUser", Value: `no-reply@acg.blue`, Type: "mail"},
{Name: "smtpPass", Value: ``, Type: "mail"},
{Name: "smtpEncryption", Value: `0`, Type: "mail"},
{Name: "maxEditSize", Value: `4194304`, Type: "file_edit"},
{Name: "archive_timeout", Value: `60`, Type: "timeout"},
{Name: "download_timeout", Value: `60`, Type: "timeout"},

@ -4,7 +4,7 @@ package conf
var BackendVersion = "3.0.0-beta1"
// RequiredDBVersion 与当前版本匹配的数据库版本
var RequiredDBVersion = "3.0.0"
var RequiredDBVersion = "3.0.0-33-g5885661"
// RequiredStaticVersion 与当前版本匹配的静态资源版本
var RequiredStaticVersion = "3.0.0"

@ -30,19 +30,21 @@ func Init() {
"replyTo",
"smtpUser",
"smtpPass",
"smtpEncryption",
)
port := model.GetIntSetting("smtpPort", 25)
keepAlive := model.GetIntSetting("mail_keepalive", 30)
client := NewSMTPClient(SMTPConfig{
Name: options["fromName"],
Address: options["fromAdress"],
ReplyTo: options["replyTo"],
Host: options["smtpHost"],
Port: port,
User: options["smtpUser"],
Password: options["smtpPass"],
Keepalive: keepAlive,
Name: options["fromName"],
Address: options["fromAdress"],
ReplyTo: options["replyTo"],
Host: options["smtpHost"],
Port: port,
User: options["smtpUser"],
Password: options["smtpPass"],
Keepalive: keepAlive,
Encryption: model.IsTrueVal(options["smtpEncryption"]),
})
Client = client

@ -22,7 +22,7 @@ type SMTPConfig struct {
Port int // 服务器端口
User string // 用户名
Password string // 密码
Encryption string // 是否启用加密
Encryption bool // 是否启用加密
Keepalive int // SMTP 连接保留时长
}
@ -77,6 +77,11 @@ func (client *SMTP) Init() {
d.Timeout = time.Duration(client.Config.Keepalive+5) * time.Second
client.chOpen = true
// 是否启用 SSL
if client.Config.Encryption {
d.SSL = true
}
var s mail.SendCloser
var err error
open := false

@ -24,7 +24,7 @@ import (
const (
// SmallFileSize 单文件上传接口最大尺寸
SmallFileSize uint64 = 4 * 1024 * 1024
// ChunkSize 分片上传分片大小
// ChunkSize 服务端中转分片上传分片大小
ChunkSize uint64 = 10 * 1024 * 1024
// ListRetry 列取请求重试次数
ListRetry = 1

@ -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))
}
}

@ -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)
// 预览文件

@ -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 {
// 创建文件系统

Loading…
Cancel
Save