MCPcopy Create free account
hub / github.com/RaymondCode/simple-demo / Publish

Function Publish

controller/publish.go:16–49  ·  view source on GitHub ↗

Publish check token then save upload file to public directory

(c *gin.Context)

Source from the content-addressed store, hash-verified

14
15// Publish check token then save upload file to public directory
16func Publish(c *gin.Context) {
17 token := c.PostForm("token")
18
19 if _, exist := usersLoginInfo[token]; !exist {
20 c.JSON(http.StatusOK, Response{StatusCode: 1, StatusMsg: "User doesn't exist"})
21 return
22 }
23
24 data, err := c.FormFile("data")
25 if err != nil {
26 c.JSON(http.StatusOK, Response{
27 StatusCode: 1,
28 StatusMsg: err.Error(),
29 })
30 return
31 }
32
33 filename := filepath.Base(data.Filename)
34 user := usersLoginInfo[token]
35 finalName := fmt.Sprintf("%d_%s", user.Id, filename)
36 saveFile := filepath.Join("./public/", finalName)
37 if err := c.SaveUploadedFile(data, saveFile); err != nil {
38 c.JSON(http.StatusOK, Response{
39 StatusCode: 1,
40 StatusMsg: err.Error(),
41 })
42 return
43 }
44
45 c.JSON(http.StatusOK, Response{
46 StatusCode: 0,
47 StatusMsg: finalName + " uploaded successfully",
48 })
49}
50
51// PublishList all users have same publish video list
52func PublishList(c *gin.Context) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected