MCPcopy Create free account
hub / github.com/LeoninCS/DevDesk / Upload

Method Upload

backend/internal/handler/HtmlHostHandler.go:30–65  ·  view source on GitHub ↗

POST /html/upload

(c *gin.Context)

Source from the content-addressed store, hash-verified

28
29// POST /html/upload
30func (h *HtmlHostHandler) Upload(c *gin.Context) {
31 fileHeader, err := c.FormFile("file")
32 if err != nil {
33 c.JSON(http.StatusBadRequest, gin.H{"error": "file is required"})
34 return
35 }
36
37 filename, err := h.svc.SaveHTML(fileHeader)
38 if err != nil {
39 status := http.StatusBadRequest
40 if errors.Is(err, service.ErrHTMLTooLarge) {
41 status = http.StatusRequestEntityTooLarge
42 }
43 c.JSON(status, gin.H{
44 "error": err.Error(),
45 "limit_bytes": h.svc.MaxSizeBytes(),
46 })
47 return
48 }
49
50 relative := strings.TrimRight(h.publicPrefix, "/") + "/" + filename
51 sharePath := "/api" + relative
52
53 scheme := "http"
54 if c.Request.TLS != nil || strings.EqualFold(c.GetHeader("X-Forwarded-Proto"), "https") {
55 scheme = "https"
56 }
57 fullURL := fmt.Sprintf("%s://%s%s", scheme, c.Request.Host, sharePath)
58
59 c.JSON(http.StatusOK, gin.H{
60 "url": sharePath,
61 "full_url": fullURL,
62 "filename": filename,
63 "limit_bytes": h.svc.MaxSizeBytes(),
64 })
65}

Callers

nothing calls this directly

Calls 2

SaveHTMLMethod · 0.80
MaxSizeBytesMethod · 0.80

Tested by

no test coverage detected