/
feedback.go
56 lines (43 loc) Β· 1.07 KB
/
feedback.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
package api
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/acl"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/get"
"github.com/photoprism/photoprism/pkg/i18n"
)
// SendFeedback sends a feedback message.
//
// POST /api/v1/feedback
func SendFeedback(router *gin.RouterGroup) {
router.POST("/feedback", func(c *gin.Context) {
conf := get.Config()
if conf.Public() {
Abort(c, http.StatusForbidden, i18n.ErrPublic)
return
}
s := Auth(c, acl.ResourceFeedback, acl.ActionCreate)
// Abort if permission was not granted.
if s.Abort(c) {
return
}
conf.RenewApiKeys()
var f form.Feedback
// Assign and validate request form values.
if err := c.BindJSON(&f); err != nil {
AbortBadRequest(c)
return
}
if f.Empty() {
Abort(c, http.StatusBadRequest, i18n.ErrNoItemsSelected)
return
}
if err := conf.Hub().SendFeedback(f); err != nil {
log.Error(err)
AbortSaveFailed(c)
return
}
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK})
})
}