refactor api package comments

* use encoding/json for comment parsing

* refactor by moving loop code to an UnmarshalJSON

* use a preallocated array and indices to maintain order while using
  goroutines again, this was removed a while ago

* use new struct in comment.hbs and contextComment.hbs

* rewriteUrl partial to reduce rimgo-specific code in api

* move RenderError into pages package to avoid import cycle between render and utils
This commit is contained in:
orangix
2026-01-25 05:08:10 +01:00
parent c208a55f40
commit 02be603dcc
15 changed files with 234 additions and 137 deletions

View File

@@ -24,10 +24,10 @@ func HandleEmbed(w http.ResponseWriter, r *http.Request) error {
post, err = ApiClient.FetchMedia(r.PathValue("postID"))
}
if err != nil && err.Error() == "ratelimited by imgur" {
return utils.RenderError(w, r, 429)
return RenderError(w, r, 429)
}
if err != nil && post.Id == "" && strings.Contains(err.Error(), "404") {
return utils.RenderError(w, r, 404)
return RenderError(w, r, 404)
}
if err != nil {
return err