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

Function listAttachments

internal/server/http/attachments.go:34–61  ·  view source on GitHub ↗
(db *sql.DB, table string)

Source from the content-addressed store, hash-verified

32}
33
34func listAttachments(db *sql.DB, table string) http.HandlerFunc {
35 return func(w http.ResponseWriter, r *http.Request) {
36 eventUUID := r.PathValue("uuid")
37
38 rows, err := db.QueryContext(r.Context(),
39 "SELECT uuid, name, path, size, mime FROM "+table+" WHERE event_uuid = ?", eventUUID)
40 if err != nil {
41 writeError(w, err.Error(), 500)
42 return
43 }
44 defer rows.Close()
45
46 var attachments []map[string]any
47 for rows.Next() {
48 var uuid, name, path, mime string
49 var size int
50 rows.Scan(&uuid, &name, &path, &size, &mime)
51 attachments = append(attachments, map[string]any{
52 "uuid": uuid, "name": name, "path": path, "size": size, "mime": mime,
53 })
54 }
55 if attachments == nil {
56 attachments = []map[string]any{}
57 }
58
59 writeJSON(w, map[string]any{"data": attachments, "meta": map[string]any{}})
60 }
61}
62
63func downloadAttachment(db *sql.DB, store *storage.AttachmentStore, table string) http.HandlerFunc {
64 return func(w http.ResponseWriter, r *http.Request) {

Callers 1

Calls 3

writeErrorFunction · 0.85
ScanMethod · 0.80
writeJSONFunction · 0.70

Tested by

no test coverage detected