forked from tangled.org/core
Monorepo for Tangled — https://tangled.org
1package knotserver 2 3import ( 4 "net/http" 5 "os" 6 "path/filepath" 7 8 "github.com/go-chi/chi/v5" 9 "github.com/microcosm-cc/bluemonday" 10) 11 12func sanitize(content []byte) []byte { 13 return bluemonday.UGCPolicy().SanitizeBytes([]byte(content)) 14} 15 16func didPath(r *http.Request) string { 17 did := chi.URLParam(r, "did") 18 name := chi.URLParam(r, "name") 19 path := filepath.Join(did, name) 20 filepath.Clean(path) 21 return path 22} 23 24func getDescription(path string) (desc string) { 25 db, err := os.ReadFile(filepath.Join(path, "description")) 26 if err == nil { 27 desc = string(db) 28 } else { 29 desc = "" 30 } 31 return 32} 33func setContentDisposition(w http.ResponseWriter, name string) { 34 h := "inline; filename=\"" + name + "\"" 35 w.Header().Add("Content-Disposition", h) 36} 37 38func setGZipMIME(w http.ResponseWriter) { 39 setMIME(w, "application/gzip") 40} 41 42func setMIME(w http.ResponseWriter, mime string) { 43 w.Header().Add("Content-Type", mime) 44}