-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_transform.go
57 lines (41 loc) · 998 Bytes
/
handle_transform.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
package transformer
import (
"net/http"
"github.com/Arimeka/image-transformer/transform"
"github.com/Arimeka/image-transformer/transform/options"
"github.com/valyala/fasthttp"
)
func TransformHandle(ctx *fasthttp.RequestCtx) {
if ctx.IsOptions() {
ctx.SetStatusCode(http.StatusNoContent)
return
}
fHeader, err := ctx.FormFile("file")
if err != nil {
ctx.SetStatusCode(http.StatusBadRequest)
return
}
transformOpts, err := options.NewOptions(fHeader)
if err != nil {
ctx.SetStatusCode(http.StatusInternalServerError)
return
}
defer transformOpts.Free()
err = transformOpts.Parse(ctx)
if err != nil {
ctx.SetStatusCode(http.StatusBadRequest)
return
}
processor, err := transform.New(transformOpts)
if err != nil {
ctx.SetStatusCode(http.StatusInternalServerError)
return
}
result, err := processor.Process()
if err != nil {
ctx.SetStatusCode(http.StatusInternalServerError)
return
}
defer result.Clear()
ctx.SendFile(result.Filename)
}