blossom: implement bud06 (upload requirements).

This commit is contained in:
fiatjaf 2024-10-28 17:30:25 -03:00
parent 7f878121fc
commit 92d1a5b671
2 changed files with 33 additions and 4 deletions

View File

@ -264,6 +264,29 @@ func (bs BlossomServer) handleDelete(w http.ResponseWriter, r *http.Request) {
}
}
func (bs BlossomServer) handleUploadCheck(w http.ResponseWriter, r *http.Request) {
auth, err := readAuthorization(r)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
mimetype := r.Header.Get("X-Content-Type")
exts, _ := mime.ExtensionsByType(mimetype)
var ext string
if len(exts) > 0 {
ext = exts[0]
}
for _, rb := range bs.RejectUpload {
reject, reason, code := rb(r.Context(), auth, ext)
if reject {
http.Error(w, reason, code)
return
}
}
}
func (bs BlossomServer) handleMirror(w http.ResponseWriter, r *http.Request) {
}

View File

@ -32,10 +32,16 @@ func New(rl *khatru.Relay, serviceURL string) *BlossomServer {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/upload" && r.Method == "PUT" {
setCors(w)
bs.handleUpload(w, r)
return
if r.URL.Path == "/upload" {
if r.Method == "PUT" {
setCors(w)
bs.handleUpload(w, r)
return
} else if r.Method == "HEAD" {
setCors(w)
bs.handleUploadCheck(w, r)
return
}
}
if strings.HasPrefix(r.URL.Path, "/list/") && r.Method == "GET" {