Ver código fonte

feat(api): add `update_content` query parameter to `/entries/{entryID}/fetch-content` endpoint

AiraNadih 1 ano atrás
pai
commit
6b70a7dc81
1 arquivos alterados com 12 adições e 0 exclusões
  1. 12 0
      internal/api/entry.go

+ 12 - 0
internal/api/entry.go

@@ -331,6 +331,18 @@ func (h *handler) fetchContent(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	shouldUpdateContent := request.QueryBoolParam(r, "update_content", false)
+	if shouldUpdateContent {
+		if err := h.store.UpdateEntryTitleAndContent(entry); err != nil {
+			json.ServerError(w, r, err)
+			return
+		}
+
+		json.OK(w, r, map[string]interface{}{"content": mediaproxy.RewriteDocumentWithRelativeProxyURL(h.router, entry.Content), "reading_time": entry.ReadingTime})
+
+		return
+	}
+
 	json.OK(w, r, map[string]string{"content": entry.Content})
 }