fix: make sure we dont try to decode jpgs into json
All checks were successful
Build and Push Server / build-and-push (push) Successful in 3m17s
All checks were successful
Build and Push Server / build-and-push (push) Successful in 3m17s
This commit is contained in:
@@ -69,10 +69,10 @@ func (h *Handler) post(w http.ResponseWriter, r *http.Request, target string) {
|
|||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
|
|
||||||
contentType := r.Header.Get("Content-Type")
|
contentType := r.Header.Get("Content-Type")
|
||||||
isJSON := strings.HasPrefix(contentType, "application/json")
|
isResource := strings.HasPrefix(contentType, "application/json") && strings.HasSuffix(target, ".md")
|
||||||
|
|
||||||
var contentToWrite []byte
|
var contentToWrite []byte
|
||||||
if strings.HasSuffix(target, ".md") && isJSON {
|
if isResource {
|
||||||
renderedContent, err := renderer.RenderFile(body)
|
renderedContent, err := renderer.RenderFile(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to render file: %w", err))
|
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to render file: %w", err))
|
||||||
@@ -88,13 +88,16 @@ func (h *Handler) post(w http.ResponseWriter, r *http.Request, target string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isResource {
|
||||||
var data map[string]any
|
var data map[string]any
|
||||||
if err := json.Unmarshal(body, &data); err != nil {
|
if err := json.Unmarshal(body, &data); err != nil && strings.HasSuffix(target, ".md") {
|
||||||
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to decode body: %w", err))
|
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to decode body: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, http.StatusOK, data)
|
writeJSON(w, http.StatusOK, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{"success": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user