mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Fix: untracked files
This commit is contained in:
@@ -2,6 +2,7 @@ package serializer
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
@@ -13,11 +14,25 @@ type UploadPolicy struct {
|
||||
MaxSize uint64 `json:"max_size"`
|
||||
AllowedExtension []string `json:"allowed_extension"`
|
||||
CallbackURL string `json:"callback_url"`
|
||||
CallbackKey string `json:"callback_key"`
|
||||
}
|
||||
|
||||
// UploadCredential 返回给客户端的上传凭证
|
||||
type UploadCredential struct {
|
||||
Token string `json:"token"`
|
||||
Policy string `json:"policy"`
|
||||
}
|
||||
|
||||
// UploadSession 上传会话
|
||||
type UploadSession struct {
|
||||
UID uint
|
||||
VirtualPath string
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register(UploadSession{})
|
||||
}
|
||||
|
||||
// DecodeUploadPolicy 反序列化Header中携带的上传策略
|
||||
// TODO 测试
|
||||
func DecodeUploadPolicy(raw string) (*UploadPolicy, error) {
|
||||
var res UploadPolicy
|
||||
|
||||
@@ -33,3 +48,16 @@ func DecodeUploadPolicy(raw string) (*UploadPolicy, error) {
|
||||
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// EncodeUploadPolicy 序列化Header中携带的上传策略
|
||||
// TODO 测试
|
||||
func (policy *UploadPolicy) EncodeUploadPolicy() (string, error) {
|
||||
jsonRes, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
res := base64.StdEncoding.EncodeToString(jsonRes)
|
||||
return res, nil
|
||||
|
||||
}
|
||||
@@ -33,10 +33,10 @@ func TestDecodeUploadPolicy(t *testing.T) {
|
||||
&UploadPolicy{},
|
||||
},
|
||||
{
|
||||
"eyJjYWxsYmFja19rZXkiOiJ0ZXN0In0=",
|
||||
"eyJjYWxsYmFja191cmwiOiJ0ZXN0In0=",
|
||||
false,
|
||||
false,
|
||||
&UploadPolicy{CallbackKey: "test"},
|
||||
&UploadPolicy{CallbackURL: "test"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -53,3 +53,11 @@ func TestDecodeUploadPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUploadPolicy_EncodeUploadPolicy(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
testPolicy := UploadPolicy{}
|
||||
res, err := testPolicy.EncodeUploadPolicy()
|
||||
asserts.NoError(err)
|
||||
asserts.NotEmpty(res)
|
||||
}
|
||||
Reference in New Issue
Block a user