minimum viable (excluding auth)

This commit is contained in:
simon987
2019-03-09 09:20:51 -05:00
parent 5a7f3316e6
commit 6048cfbebc
11 changed files with 812 additions and 0 deletions

71
api/models.go Normal file
View File

@@ -0,0 +1,71 @@
package api
import (
"path/filepath"
"strings"
)
type GenericResponse struct {
Ok bool `json:"ok"`
}
type CreateClientRequest struct {
Alias string `json:"alias"`
}
func (req *CreateClientRequest) IsValid() bool {
return len(req.Alias) > 3
}
type CreateClientResponse struct {
Ok bool `json:"ok"`
Secret string `json:"secret,omitempty"`
}
type Client struct {
ID int64
Alias string `json:"alias"`
Secret string `json:"secret"`
}
type AllocateUploadSlotRequest struct {
Token string `json:"token"`
MaxSize int64 `json:"max_size"`
FileName string `json:"file_name"`
}
func (req *AllocateUploadSlotRequest) IsValid() bool {
if len(req.Token) < 3 {
return false
}
if len(req.FileName) <= 0 {
return false
}
path := filepath.Join(WorkDir, req.FileName)
pathAbs, err := filepath.Abs(path)
if err != nil {
return false
}
if !strings.HasPrefix(pathAbs, WorkDir) {
return false
}
if req.MaxSize < 0 {
return false
}
return true
}
type UploadSlot struct {
MaxSize int64 `json:"max_size"`
Token string `gorm:"primary_key",json:"token"`
FileName string `json:"file_name"`
}
type WebsocketMotd struct {
Info Info `json:"info"`
Motd string `json:"motd"`
}