subscription_bookmarklet.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/request"
  9. "github.com/miniflux/miniflux/http/response/html"
  10. "github.com/miniflux/miniflux/ui/form"
  11. "github.com/miniflux/miniflux/ui/session"
  12. "github.com/miniflux/miniflux/ui/view"
  13. )
  14. // Bookmarklet prefill the form to add a subscription from the URL provided by the bookmarklet.
  15. func (c *Controller) Bookmarklet(w http.ResponseWriter, r *http.Request) {
  16. ctx := context.New(r)
  17. sess := session.New(c.store, ctx)
  18. view := view.New(c.tpl, ctx, sess)
  19. user, err := c.store.UserByID(ctx.UserID())
  20. if err != nil {
  21. html.ServerError(w, err)
  22. return
  23. }
  24. categories, err := c.store.Categories(user.ID)
  25. if err != nil {
  26. html.ServerError(w, err)
  27. return
  28. }
  29. bookmarkletURL := request.QueryParam(r, "uri", "")
  30. view.Set("form", form.SubscriptionForm{URL: bookmarkletURL})
  31. view.Set("categories", categories)
  32. view.Set("menu", "feeds")
  33. view.Set("user", user)
  34. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  35. html.OK(w, view.Render("add_subscription"))
  36. }