-
Notifications
You must be signed in to change notification settings - Fork 3
/
fileserver.go
75 lines (57 loc) · 1.84 KB
/
fileserver.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package restful
import (
"net/http"
"github.com/quanxiang-cloud/cabin/logger"
"github.com/quanxiang-cloud/cabin/tailormade/header"
"github.com/quanxiang-cloud/cabin/tailormade/resp"
"github.com/quanxiang-cloud/fileserver/internal/service"
"github.com/quanxiang-cloud/fileserver/pkg/misc/config"
"github.com/gin-gonic/gin"
)
// FileServer file service.
type FileServer struct {
fileserver service.FileServer
}
// NewFileServer new a fileserver.
func NewFileServer(conf *config.Config) (*FileServer, error) {
fileserver, err := service.NewFileServer(conf)
if err != nil {
return nil, err
}
return &FileServer{
fileserver: fileserver,
}, nil
}
// DelFile delete file.
func (f *FileServer) DelFile(c *gin.Context) {
ctx := header.MutateContext(c)
req := &service.DelUploadFileReq{}
if err := c.ShouldBind(req); err != nil {
logger.Logger.WithName("delete").Errorw(err.Error(), header.GetRequestIDKV(ctx).Fuzzy()...)
resp.Format(nil, err).Context(c, http.StatusBadRequest)
return
}
resp.Format(f.fileserver.DelUploadFile(ctx, req)).Context(c)
}
// Thumbnail Thumbnail.
func (f *FileServer) Thumbnail(c *gin.Context) {
ctx := header.MutateContext(c)
req := &service.ThumbnailReq{}
if err := c.ShouldBind(req); err != nil {
logger.Logger.WithName("thumbnail").Errorw(err.Error(), header.GetRequestIDKV(ctx).Fuzzy()...)
resp.Format(nil, err).Context(c, http.StatusBadRequest)
return
}
resp.Format(f.fileserver.Thumbnail(ctx, req)).Context(c)
}
// Domain Domain.
func (f *FileServer) Domain(c *gin.Context) {
ctx := header.MutateContext(c)
req := &service.DomainReq{}
if err := c.ShouldBind(req); err != nil {
logger.Logger.WithName("domain").Errorw(err.Error(), header.GetRequestIDKV(ctx).Fuzzy()...)
resp.Format(nil, err).Context(c, http.StatusBadRequest)
return
}
resp.Format(f.fileserver.Domain(ctx, req)).Context(c)
}