Modify: parameters in headers should be URIEncoded

pull/247/head
HFO4 5 years ago
parent 28df5ca833
commit 451bdb4ee1

@ -15,6 +15,7 @@ type Group struct {
WebDAVEnabled bool
Aria2Option string
Color string
SpeedLimit int
// 数据库忽略字段
PolicyList []uint `gorm:"-"`

@ -38,7 +38,6 @@ type PolicyOption struct {
OPPassword string `json:"op_pwd"`
FileType []string `json:"file_type"`
MimeType string `json:"mimetype"`
SpeedLimit int `json:"speed_limit"`
RangeTransferEnabled bool `json:"range_transfer_enabled"`
}
@ -53,6 +52,9 @@ func GetPolicyByID(ID interface{}) (Policy, error) {
func (policy *Policy) AfterFind() (err error) {
// 解析上传策略设置到OptionsSerialized
err = json.Unmarshal([]byte(policy.Options), &policy.OptionsSerialized)
if policy.OptionsSerialized.FileType == nil {
policy.OptionsSerialized.FileType = []string{}
}
return err
}

@ -1,6 +1,8 @@
package serializer
import (
model "github.com/HFO4/cloudreve/models"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"testing"
)
@ -23,4 +25,13 @@ func TestBuildSiteConfig(t *testing.T) {
res = BuildSiteConfig(map[string]string{"qq_login": "1"}, nil)
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"`
CreatedAt int64 `json:"created_at"`
PreferredTheme string `json:"preferred_theme"`
Policy struct {
} `json:"policy"`
Policy 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 序列化用户
@ -37,6 +50,17 @@ func BuildUser(user model.User) User {
Avatar: user.Avatar,
CreatedAt: user.CreatedAt.Unix(),
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/util"
"github.com/gin-gonic/gin"
"net/url"
"strconv"
)
@ -30,12 +31,20 @@ func FileUploadStream(c *gin.Context) {
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{
MIMEType: c.Request.Header.Get("Content-Type"),
File: c.Request.Body,
Size: fileSize,
Name: c.Request.Header.Get("X-FileName"),
VirtualPath: util.DotPathToStandardPath(c.Request.Header.Get("X-Path")),
Name: fileName,
VirtualPath: util.DotPathToStandardPath(filePath),
}
// 创建文件系统

@ -21,7 +21,7 @@ func InitRouter() *gin.Engine {
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"},
AllowHeaders: []string{"X-PINGOTHER", "Content-Type"},
AllowHeaders: []string{"Content-Length", "Content-Type", "X-Path", "X-FileName"},
AllowCredentials: true,
}))

Loading…
Cancel
Save