entry_scraper.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/json"
  9. "miniflux.app/model"
  10. "miniflux.app/reader/sanitizer"
  11. "miniflux.app/reader/scraper"
  12. )
  13. func (h *handler) fetchContent(w http.ResponseWriter, r *http.Request) {
  14. entryID := request.RouteInt64Param(r, "entryID")
  15. builder := h.store.NewEntryQueryBuilder(request.UserID(r))
  16. builder.WithEntryID(entryID)
  17. builder.WithoutStatus(model.EntryStatusRemoved)
  18. entry, err := builder.GetEntry()
  19. if err != nil {
  20. json.ServerError(w, r, err)
  21. return
  22. }
  23. if entry == nil {
  24. json.NotFound(w, r)
  25. return
  26. }
  27. content, err := scraper.Fetch(entry.URL, entry.Feed.ScraperRules, entry.Feed.UserAgent)
  28. if err != nil {
  29. json.ServerError(w, r, err)
  30. return
  31. }
  32. entry.Content = sanitizer.Sanitize(entry.URL, content)
  33. h.store.UpdateEntryContent(entry)
  34. json.OK(w, r, map[string]string{"content": entry.Content})
  35. }