Marshal assets AFTER rejecting those that are unreadable
@@ -35,23 +35,25 @@ func (c *AssetsController) many(w http.ResponseWriter, r *http.Request) {
return
}
+ // Fetch assets from store
assets, err := c.Store.GetAssets(r.Context())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+ // Reject those resources the viewer is unauthorized to view
+ rejectAssets(&assets, abilities.CanRead)
+
+ // Marshal assets
assetBytes, err := json.Marshal(assets)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- // Reject those resources the viewer is unauthorized to view
- rejectAssets(&assets, abilities.CanRead)
-
w.Header().Set("Content-Type", "application/json")
- fmt.Fprintf(w, "%s", assetBytes)
+ fmt.Fprintf(w, string(assetBytes))
}
// signle handles requests to /assets/{name}
