entry_save.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  5. import (
  6. "errors"
  7. "net/http"
  8. "github.com/miniflux/miniflux/http/context"
  9. "github.com/miniflux/miniflux/http/request"
  10. "github.com/miniflux/miniflux/http/response/json"
  11. "github.com/miniflux/miniflux/integration"
  12. "github.com/miniflux/miniflux/model"
  13. )
  14. // SaveEntry send the link to external services.
  15. func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) {
  16. entryID, err := request.IntParam(r, "entryID")
  17. if err != nil {
  18. json.BadRequest(w, err)
  19. return
  20. }
  21. ctx := context.New(r)
  22. builder := c.store.NewEntryQueryBuilder(ctx.UserID())
  23. builder.WithEntryID(entryID)
  24. builder.WithoutStatus(model.EntryStatusRemoved)
  25. entry, err := builder.GetEntry()
  26. if err != nil {
  27. json.ServerError(w, err)
  28. return
  29. }
  30. if entry == nil {
  31. json.NotFound(w, errors.New("Entry not found"))
  32. return
  33. }
  34. settings, err := c.store.Integration(ctx.UserID())
  35. if err != nil {
  36. json.ServerError(w, err)
  37. return
  38. }
  39. go func() {
  40. integration.SendEntry(c.cfg, entry, settings)
  41. }()
  42. json.Created(w, map[string]string{"message": "saved"})
  43. }