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()
|
||||
|
||||
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
|
||||
if strings.HasSuffix(target, ".md") && isJSON {
|
||||
if isResource {
|
||||
renderedContent, err := renderer.RenderFile(body)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to render file: %w", err))
|
||||
@@ -88,15 +88,18 @@ func (h *Handler) post(w http.ResponseWriter, r *http.Request, target string) {
|
||||
return
|
||||
}
|
||||
|
||||
if isResource {
|
||||
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))
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, data)
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, map[string]any{"success": true})
|
||||
}
|
||||
|
||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
reqPath := r.URL.Path
|
||||
if reqPath == "" {
|
||||
|
||||
Reference in New Issue
Block a user