-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
60 lines (52 loc) · 1.53 KB
/
structs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package image
import (
"fmt"
"mime/multipart"
"github.com/shlason/kaigon/controllers"
)
type uploadToS3RequestPayload struct {
File *multipart.FileHeader `form:"file"`
Folder string `form:"folder"`
}
func (p *uploadToS3RequestPayload) check() (errRespnse controllers.JSONResponse, isNotValid bool) {
var acceptFolders = map[string]string{
"account": "account",
"article": "article",
"chat": "chat",
}
var acceptImageTypes = map[string]string{
"image/png": "image/png",
"image/jpg": "image/jpg",
"image/jpeg": "image/jpeg",
"image/gif": "image/gif",
}
// 5 MB Limit
const imageMaximumSize int64 = 5242880
if _, ok := acceptFolders[p.Folder]; !ok {
return controllers.JSONResponse{
Code: controllers.ErrCodeRequestPayloadFieldNotValid,
Message: controllers.ErrMessageRequestPayloadFieldNotValid,
Data: nil,
}, true
}
if p.File == nil {
return controllers.JSONResponse{
Code: controllers.ErrCodeRequestPayloadFieldNotValid,
Message: controllers.ErrMessageRequestPayloadFieldNotValid,
Data: nil,
}, true
}
fmt.Println(p.File.Header.Get("Content-Type"))
if _, ok := acceptImageTypes[p.File.Header.Get("Content-Type")]; !ok || p.File.Size > imageMaximumSize {
return controllers.JSONResponse{
Code: errCodeRequestPayloadImageFileNotValid,
Message: errMessageRequestPayloadImageFileNotValid,
Data: nil,
}, true
}
return controllers.JSONResponse{}, false
}
type uploadToS3ResponsePayload struct {
S3URL string `json:"s3Url"`
URL string `json:"url"`
}