Modify: parameters in headers should be URIEncoded
This commit is contained in:
parent
28df5ca833
commit
451bdb4ee1
6 changed files with 53 additions and 6 deletions
|
@ -15,6 +15,7 @@ type Group struct {
|
||||||
WebDAVEnabled bool
|
WebDAVEnabled bool
|
||||||
Aria2Option string
|
Aria2Option string
|
||||||
Color string
|
Color string
|
||||||
|
SpeedLimit int
|
||||||
|
|
||||||
// 数据库忽略字段
|
// 数据库忽略字段
|
||||||
PolicyList []uint `gorm:"-"`
|
PolicyList []uint `gorm:"-"`
|
||||||
|
|
|
@ -38,7 +38,6 @@ type PolicyOption struct {
|
||||||
OPPassword string `json:"op_pwd"`
|
OPPassword string `json:"op_pwd"`
|
||||||
FileType []string `json:"file_type"`
|
FileType []string `json:"file_type"`
|
||||||
MimeType string `json:"mimetype"`
|
MimeType string `json:"mimetype"`
|
||||||
SpeedLimit int `json:"speed_limit"`
|
|
||||||
RangeTransferEnabled bool `json:"range_transfer_enabled"`
|
RangeTransferEnabled bool `json:"range_transfer_enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +52,9 @@ func GetPolicyByID(ID interface{}) (Policy, error) {
|
||||||
func (policy *Policy) AfterFind() (err error) {
|
func (policy *Policy) AfterFind() (err error) {
|
||||||
// 解析上传策略设置到OptionsSerialized
|
// 解析上传策略设置到OptionsSerialized
|
||||||
err = json.Unmarshal([]byte(policy.Options), &policy.OptionsSerialized)
|
err = json.Unmarshal([]byte(policy.Options), &policy.OptionsSerialized)
|
||||||
|
if policy.OptionsSerialized.FileType == nil {
|
||||||
|
policy.OptionsSerialized.FileType = []string{}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package serializer
|
package serializer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
model "github.com/HFO4/cloudreve/models"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -23,4 +25,13 @@ func TestBuildSiteConfig(t *testing.T) {
|
||||||
|
|
||||||
res = BuildSiteConfig(map[string]string{"qq_login": "1"}, nil)
|
res = BuildSiteConfig(map[string]string{"qq_login": "1"}, nil)
|
||||||
asserts.Equal(true, res.Data.(SiteConfig).QQLogin)
|
asserts.Equal(true, res.Data.(SiteConfig).QQLogin)
|
||||||
|
asserts.Equal(uint(0), res.Data.(SiteConfig).User.ID)
|
||||||
|
|
||||||
|
// 非空用户
|
||||||
|
res = BuildSiteConfig(map[string]string{"qq_login": "1"}, &model.User{
|
||||||
|
Model: gorm.Model{
|
||||||
|
ID: 5,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
asserts.Equal(uint(5), res.Data.(SiteConfig).User.ID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,21 @@ type User struct {
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
PreferredTheme string `json:"preferred_theme"`
|
PreferredTheme string `json:"preferred_theme"`
|
||||||
Policy struct {
|
Policy Policy `json:"policy"`
|
||||||
} `json:"policy"`
|
Group Group `json:"group"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Policy struct {
|
||||||
|
SaveType string `json:"saveType"`
|
||||||
|
MaxSize string `json:"maxSize"`
|
||||||
|
AllowedType []string `json:"allowedType"`
|
||||||
|
UploadURL string `json:"upUrl"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
AllowShare bool `json:"allowShare"`
|
||||||
|
AllowRemoteDownload bool `json:"allowRemoteDownload"`
|
||||||
|
AllowTorrentDownload bool `json:"allowTorrentDownload"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildUser 序列化用户
|
// BuildUser 序列化用户
|
||||||
|
@ -37,6 +50,17 @@ func BuildUser(user model.User) User {
|
||||||
Avatar: user.Avatar,
|
Avatar: user.Avatar,
|
||||||
CreatedAt: user.CreatedAt.Unix(),
|
CreatedAt: user.CreatedAt.Unix(),
|
||||||
PreferredTheme: user.OptionsSerialized.PreferredTheme,
|
PreferredTheme: user.OptionsSerialized.PreferredTheme,
|
||||||
|
Policy: Policy{
|
||||||
|
SaveType: user.Policy.Type,
|
||||||
|
MaxSize: fmt.Sprintf("%.2fmb", float64(user.Policy.MaxSize)/1024*1024),
|
||||||
|
AllowedType: user.Policy.OptionsSerialized.FileType,
|
||||||
|
UploadURL: user.Policy.Server,
|
||||||
|
},
|
||||||
|
Group: Group{
|
||||||
|
AllowShare: user.Group.ShareEnabled,
|
||||||
|
AllowRemoteDownload: user.Group.Aria2Option[0] == '1',
|
||||||
|
AllowTorrentDownload: user.Group.Aria2Option[2] == '1',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||||
"github.com/HFO4/cloudreve/pkg/util"
|
"github.com/HFO4/cloudreve/pkg/util"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,12 +31,20 @@ func FileUploadStream(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 解码文件名和路径
|
||||||
|
fileName, err := url.QueryUnescape(c.Request.Header.Get("X-FileName"))
|
||||||
|
filePath, err := url.QueryUnescape(c.Request.Header.Get("X-Path"))
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, ErrorResponse(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fileData := local.FileStream{
|
fileData := local.FileStream{
|
||||||
MIMEType: c.Request.Header.Get("Content-Type"),
|
MIMEType: c.Request.Header.Get("Content-Type"),
|
||||||
File: c.Request.Body,
|
File: c.Request.Body,
|
||||||
Size: fileSize,
|
Size: fileSize,
|
||||||
Name: c.Request.Header.Get("X-FileName"),
|
Name: fileName,
|
||||||
VirtualPath: util.DotPathToStandardPath(c.Request.Header.Get("X-Path")),
|
VirtualPath: util.DotPathToStandardPath(filePath),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建文件系统
|
// 创建文件系统
|
||||||
|
|
|
@ -21,7 +21,7 @@ func InitRouter() *gin.Engine {
|
||||||
r.Use(cors.New(cors.Config{
|
r.Use(cors.New(cors.Config{
|
||||||
AllowOrigins: []string{"http://localhost:3000"},
|
AllowOrigins: []string{"http://localhost:3000"},
|
||||||
AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"},
|
AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"},
|
||||||
AllowHeaders: []string{"X-PINGOTHER", "Content-Type"},
|
AllowHeaders: []string{"Content-Length", "Content-Type", "X-Path", "X-FileName"},
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue