MCPcopy Create free account
hub / github.com/buggregator/server / previewAttachment

Function previewAttachment

internal/server/http/attachments.go:97–126  ·  view source on GitHub ↗
(db *sql.DB, store *storage.AttachmentStore, table string)

Source from the content-addressed store, hash-verified

95}
96
97func previewAttachment(db *sql.DB, store *storage.AttachmentStore, table string) http.HandlerFunc {
98 return func(w http.ResponseWriter, r *http.Request) {
99 eventUUID := r.PathValue("eventUuid")
100 uuid := r.PathValue("uuid")
101
102 var name, path, mime string
103 var storedEventUUID string
104 err := db.QueryRowContext(r.Context(),
105 "SELECT event_uuid, name, path, mime FROM "+table+" WHERE uuid = ?", uuid,
106 ).Scan(&storedEventUUID, &name, &path, &mime)
107 if err != nil {
108 http.Error(w, "attachment not found", 404)
109 return
110 }
111
112 if storedEventUUID != eventUUID {
113 http.Error(w, "forbidden", 403)
114 return
115 }
116
117 data, err := store.Get(path)
118 if err != nil {
119 http.Error(w, "file not found", 404)
120 return
121 }
122
123 w.Header().Set("Content-Type", mime)
124 w.Write(data)
125 }
126}
127

Callers 1

Calls 2

ScanMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected