forked from tangled.org/core
this repo has no description
1package knotserver 2 3import ( 4 "net/http" 5 "os" 6 "path/filepath" 7 8 "github.com/bluesky-social/indigo/atproto/syntax" 9 securejoin "github.com/cyphar/filepath-securejoin" 10 "github.com/go-chi/chi/v5" 11 "github.com/microcosm-cc/bluemonday" 12) 13 14func sanitize(content []byte) []byte { 15 return bluemonday.UGCPolicy().SanitizeBytes([]byte(content)) 16} 17 18func didPath(r *http.Request) string { 19 did := chi.URLParam(r, "did") 20 name := chi.URLParam(r, "name") 21 path, _ := securejoin.SecureJoin(did, name) 22 filepath.Clean(path) 23 return path 24} 25 26func getDescription(path string) (desc string) { 27 db, err := os.ReadFile(filepath.Join(path, "description")) 28 if err == nil { 29 desc = string(db) 30 } else { 31 desc = "" 32 } 33 return 34} 35func setContentDisposition(w http.ResponseWriter, name string) { 36 h := "inline; filename=\"" + name + "\"" 37 w.Header().Add("Content-Disposition", h) 38} 39 40func setGZipMIME(w http.ResponseWriter) { 41 setMIME(w, "application/gzip") 42} 43 44func setMIME(w http.ResponseWriter, mime string) { 45 w.Header().Add("Content-Type", mime) 46} 47 48var TIDClock = syntax.NewTIDClock(0) 49 50func TID() string { 51 return TIDClock.Next().String() 52}