mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Refactor HTTP response builder
This commit is contained in:
parent
ddfe969d6c
commit
1f58b37a5e
94 changed files with 1701 additions and 644 deletions
|
@ -18,7 +18,7 @@ import (
|
|||
func (c *Controller) About(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -19,7 +19,7 @@ import (
|
|||
func (c *Controller) ShowStarredPage(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,13 @@ func (c *Controller) ShowStarredPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
func (c *Controller) CreateCategory(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -21,19 +21,19 @@ func (c *Controller) EditCategory(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categoryID := request.RouteInt64Param(r, "categoryID")
|
||||
category, err := c.store.Category(request.UserID(r), categoryID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if category == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -19,19 +19,19 @@ import (
|
|||
func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categoryID := request.RouteInt64Param(r, "categoryID")
|
||||
category, err := c.store.Category(request.UserID(r), categoryID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if category == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -46,13 +46,13 @@ func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -17,13 +17,13 @@ import (
|
|||
func (c *Controller) CategoryList(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.CategoriesWithFeedCount(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
)
|
||||
|
@ -17,26 +16,26 @@ import (
|
|||
func (c *Controller) RemoveCategory(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categoryID := request.RouteInt64Param(r, "categoryID")
|
||||
category, err := c.store.Category(request.UserID(r), categoryID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if category == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.store.RemoveCategory(user.ID, category.ID); err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "categories"))
|
||||
html.Redirect(w, r, route.Path(c.router, "categories"))
|
||||
}
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/http/request"
|
||||
|
@ -22,7 +21,7 @@ import (
|
|||
func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -44,7 +43,7 @@ func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
duplicateCategory, err := c.store.CategoryByTitle(user.ID, categoryForm.Title)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -66,5 +65,5 @@ func (c *Controller) SaveCategory(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "categories"))
|
||||
html.Redirect(w, r, route.Path(c.router, "categories"))
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -21,19 +20,19 @@ import (
|
|||
func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categoryID := request.RouteInt64Param(r, "categoryID")
|
||||
category, err := c.store.Category(request.UserID(r), categoryID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if category == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -68,5 +67,5 @@ func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "categories"))
|
||||
html.Redirect(w, r, route.Path(c.router, "categories"))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -10,7 +10,6 @@ import (
|
|||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/model"
|
||||
"miniflux.app/storage"
|
||||
"miniflux.app/ui/session"
|
||||
|
@ -21,7 +20,7 @@ import (
|
|||
func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -32,20 +31,19 @@ func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if entry.Status == model.EntryStatusUnread {
|
||||
err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ShowReadEntry] %v", err)
|
||||
html.ServerError(w, nil)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -56,7 +54,7 @@ func (c *Controller) ShowStarredEntry(w http.ResponseWriter, r *http.Request) {
|
|||
entryPaginationBuilder.WithStarred()
|
||||
prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -10,7 +10,6 @@ import (
|
|||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/model"
|
||||
"miniflux.app/storage"
|
||||
"miniflux.app/ui/session"
|
||||
|
@ -21,7 +20,7 @@ import (
|
|||
func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -35,20 +34,19 @@ func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if entry.Status == model.EntryStatusUnread {
|
||||
err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ShowCategoryEntry] %v", err)
|
||||
html.ServerError(w, nil)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -59,7 +57,7 @@ func (c *Controller) ShowCategoryEntry(w http.ResponseWriter, r *http.Request) {
|
|||
entryPaginationBuilder.WithCategoryID(categoryID)
|
||||
prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -10,7 +10,6 @@ import (
|
|||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/model"
|
||||
"miniflux.app/storage"
|
||||
"miniflux.app/ui/session"
|
||||
|
@ -21,7 +20,7 @@ import (
|
|||
func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -35,20 +34,19 @@ func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if entry.Status == model.EntryStatusUnread {
|
||||
err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ShowFeedEntry] %v", err)
|
||||
html.ServerError(w, nil)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -59,7 +57,7 @@ func (c *Controller) ShowFeedEntry(w http.ResponseWriter, r *http.Request) {
|
|||
entryPaginationBuilder.WithFeedID(feedID)
|
||||
prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -20,7 +20,7 @@ import (
|
|||
func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,12 @@ func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ func (c *Controller) ShowReadEntry(w http.ResponseWriter, r *http.Request) {
|
|||
entryPaginationBuilder.WithStatus(model.EntryStatusRead)
|
||||
prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
|
@ -23,18 +22,18 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
json.ServerError(w, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
json.NotFound(w, errors.New("Entry not found"))
|
||||
json.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
settings, err := c.store.Integration(request.UserID(r))
|
||||
if err != nil {
|
||||
json.ServerError(w, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -42,5 +41,5 @@ func (c *Controller) SaveEntry(w http.ResponseWriter, r *http.Request) {
|
|||
integration.SendEntry(c.cfg, entry, settings)
|
||||
}()
|
||||
|
||||
json.Created(w, map[string]string{"message": "saved"})
|
||||
json.Created(w, r, map[string]string{"message": "saved"})
|
||||
}
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
|
@ -24,18 +23,18 @@ func (c *Controller) FetchContent(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
json.ServerError(w, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
json.NotFound(w, errors.New("Entry not found"))
|
||||
json.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
content, err := scraper.Fetch(entry.URL, entry.Feed.ScraperRules, entry.Feed.UserAgent)
|
||||
if err != nil {
|
||||
json.ServerError(w, err)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -21,7 +21,7 @@ import (
|
|||
func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -34,12 +34,12 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) {
|
|||
err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ShowSearchEntry] %v", err)
|
||||
html.ServerError(w, nil)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ func (c *Controller) ShowSearchEntry(w http.ResponseWriter, r *http.Request) {
|
|||
entryPaginationBuilder.WithSearchQuery(searchQuery)
|
||||
prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -9,15 +9,13 @@ import (
|
|||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/json"
|
||||
"miniflux.app/logger"
|
||||
)
|
||||
|
||||
// ToggleBookmark handles Ajax request to toggle bookmark value.
|
||||
func (c *Controller) ToggleBookmark(w http.ResponseWriter, r *http.Request) {
|
||||
entryID := request.RouteInt64Param(r, "entryID")
|
||||
if err := c.store.ToggleBookmark(request.UserID(r), entryID); err != nil {
|
||||
logger.Error("[Controller:ToggleBookmark] %v", err)
|
||||
json.ServerError(w, nil)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -10,7 +10,6 @@ import (
|
|||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/model"
|
||||
"miniflux.app/storage"
|
||||
"miniflux.app/ui/session"
|
||||
|
@ -21,7 +20,7 @@ import (
|
|||
func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -32,12 +31,12 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entry, err := builder.GetEntry()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if entry == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -45,8 +44,7 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) {
|
|||
if entry.Status == model.EntryStatusRead {
|
||||
err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusUnread)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ShowUnreadEntry] %v", err)
|
||||
html.ServerError(w, nil)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +53,7 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) {
|
|||
entryPaginationBuilder.WithStatus(model.EntryStatusUnread)
|
||||
prevEntry, nextEntry, err := entryPaginationBuilder.Entries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -72,8 +70,7 @@ func (c *Controller) ShowUnreadEntry(w http.ResponseWriter, r *http.Request) {
|
|||
// Always mark the entry as read after fetching the pagination.
|
||||
err = c.store.SetEntriesStatus(user.ID, []int64{entry.ID}, model.EntryStatusRead)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ShowUnreadEntry] %v", err)
|
||||
html.ServerError(w, nil)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
entry.Status = model.EntryStatusRead
|
||||
|
|
|
@ -10,27 +10,24 @@ import (
|
|||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/json"
|
||||
"miniflux.app/logger"
|
||||
)
|
||||
|
||||
// UpdateEntriesStatus updates the status for a list of entries.
|
||||
func (c *Controller) UpdateEntriesStatus(w http.ResponseWriter, r *http.Request) {
|
||||
entryIDs, status, err := decodeEntryStatusPayload(r.Body)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:UpdateEntryStatus] %v", err)
|
||||
json.BadRequest(w, nil)
|
||||
json.BadRequest(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(entryIDs) == 0 {
|
||||
json.BadRequest(w, errors.New("The list of entryID is empty"))
|
||||
json.BadRequest(w, r, errors.New("The list of entry IDs is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
err = c.store.SetEntriesStatus(request.UserID(r), entryIDs, status)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:UpdateEntryStatus] %v", err)
|
||||
json.ServerError(w, nil)
|
||||
json.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -19,25 +19,25 @@ import (
|
|||
func (c *Controller) EditFeed(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
feedID := request.RouteInt64Param(r, "feedID")
|
||||
feed, err := c.store.FeedByID(user.ID, feedID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if feed == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -19,19 +19,19 @@ import (
|
|||
func (c *Controller) ShowFeedEntries(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
feedID := request.RouteInt64Param(r, "feedID")
|
||||
feed, err := c.store.FeedByID(user.ID, feedID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if feed == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -46,13 +46,13 @@ func (c *Controller) ShowFeedEntries(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -18,14 +18,19 @@ func (c *Controller) ShowIcon(w http.ResponseWriter, r *http.Request) {
|
|||
iconID := request.RouteInt64Param(r, "iconID")
|
||||
icon, err := c.store.IconByID(iconID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if icon == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
response.Cache(w, r, icon.MimeType, icon.Hash, icon.Content, 72*time.Hour)
|
||||
response.New(w, r).WithCaching(icon.Hash, 72*time.Hour, func(b *response.Builder) {
|
||||
b.WithHeader("Content-Type", icon.MimeType)
|
||||
b.WithBody(icon.Content)
|
||||
b.WithoutCompression()
|
||||
b.Write()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ import (
|
|||
func (c *Controller) ShowFeedsPage(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
feeds, err := c.store.Feeds(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -21,7 +20,7 @@ func (c *Controller) RefreshFeed(w http.ResponseWriter, r *http.Request) {
|
|||
logger.Error("[Controller:RefreshFeed] %v", err)
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feedID))
|
||||
html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feedID))
|
||||
}
|
||||
|
||||
// RefreshAllFeeds refresh all feeds in the background for the current user.
|
||||
|
@ -29,7 +28,7 @@ func (c *Controller) RefreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
|||
userID := request.UserID(r)
|
||||
jobs, err := c.store.NewUserBatch(userID, c.store.CountFeeds(userID))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,5 +36,5 @@ func (c *Controller) RefreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
|||
c.pool.Push(jobs)
|
||||
}()
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feeds"))
|
||||
html.Redirect(w, r, route.Path(c.router, "feeds"))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
)
|
||||
|
@ -17,9 +16,9 @@ import (
|
|||
func (c *Controller) RemoveFeed(w http.ResponseWriter, r *http.Request) {
|
||||
feedID := request.RouteInt64Param(r, "feedID")
|
||||
if err := c.store.RemoveFeed(request.UserID(r), feedID); err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feeds"))
|
||||
html.Redirect(w, r, route.Path(c.router, "feeds"))
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -22,25 +21,25 @@ import (
|
|||
func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
feedID := request.RouteInt64Param(r, "feedID")
|
||||
feed, err := c.store.FeedByID(user.ID, feedID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if feed == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -71,5 +70,5 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID))
|
||||
html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -19,7 +19,7 @@ import (
|
|||
func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -33,13 +33,13 @@ func (c *Controller) ShowHistoryPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
)
|
||||
|
@ -17,9 +16,9 @@ import (
|
|||
func (c *Controller) FlushHistory(w http.ResponseWriter, r *http.Request) {
|
||||
err := c.store.FlushHistory(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "history"))
|
||||
html.Redirect(w, r, route.Path(c.router, "history"))
|
||||
}
|
||||
|
|
|
@ -7,9 +7,8 @@ package ui // import "miniflux.app/ui"
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/integration/pocket"
|
||||
"miniflux.app/locale"
|
||||
|
@ -22,13 +21,13 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) {
|
|||
printer := locale.NewPrinter(request.UserLanguage(r))
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -39,12 +38,12 @@ func (c *Controller) PocketAuthorize(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
logger.Error("[Pocket:Authorize] %v", err)
|
||||
sess.NewFlashErrorMessage(printer.Printf("error.pocket_request_token"))
|
||||
response.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
html.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
return
|
||||
}
|
||||
|
||||
sess.SetPocketRequestToken(requestToken)
|
||||
response.Redirect(w, r, connector.AuthorizationURL(requestToken, redirectURL))
|
||||
html.Redirect(w, r, connector.AuthorizationURL(requestToken, redirectURL))
|
||||
}
|
||||
|
||||
// PocketCallback saves the personal access token after the authorization step.
|
||||
|
@ -54,13 +53,13 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -69,7 +68,7 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
logger.Error("[Pocket:Callback] %v", err)
|
||||
sess.NewFlashErrorMessage(printer.Printf("error.pocket_access_token"))
|
||||
response.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
html.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,10 +77,10 @@ func (c *Controller) PocketCallback(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = c.store.UpdateIntegration(integration)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
sess.NewFlashMessage(printer.Printf("alert.pocket_linked"))
|
||||
response.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
html.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -18,13 +18,13 @@ import (
|
|||
func (c *Controller) ShowIntegrations(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,15 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/locale"
|
||||
"miniflux.app/ui/form"
|
||||
|
@ -24,13 +23,13 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) {
|
|||
sess := session.New(c.store, request.SessionID(r))
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
integration, err := c.store.Integration(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -39,7 +38,7 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if integration.FeverUsername != "" && c.store.HasDuplicateFeverUsername(user.ID, integration.FeverUsername) {
|
||||
sess.NewFlashErrorMessage(printer.Printf("error.duplicate_fever_username"))
|
||||
response.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
html.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -51,10 +50,10 @@ func (c *Controller) UpdateIntegration(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = c.store.UpdateIntegration(integration)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
sess.NewFlashMessage(printer.Printf("alert.prefs_saved"))
|
||||
response.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
html.Redirect(w, r, route.Path(c.router, "integrations"))
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"miniflux.app/http/cookie"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -38,7 +37,7 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
sessionToken, userID, err := c.store.CreateUserSession(authForm.Username, r.UserAgent(), clientIP)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -47,7 +46,7 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -61,5 +60,5 @@ func (c *Controller) CheckLogin(w http.ResponseWriter, r *http.Request) {
|
|||
c.cfg.BasePath(),
|
||||
))
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
html.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/ui/session"
|
||||
"miniflux.app/ui/view"
|
||||
|
@ -18,7 +17,7 @@ import (
|
|||
// ShowLoginPage shows the login form.
|
||||
func (c *Controller) ShowLoginPage(w http.ResponseWriter, r *http.Request) {
|
||||
if request.IsAuthenticated(r) {
|
||||
response.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
html.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/cookie"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -21,7 +20,7 @@ func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) {
|
|||
sess := session.New(c.store, request.SessionID(r))
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -38,5 +37,5 @@ func (c *Controller) Logout(w http.ResponseWriter, r *http.Request) {
|
|||
c.cfg.BasePath(),
|
||||
))
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"miniflux.app/config"
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/cookie"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/locale"
|
||||
|
@ -26,71 +25,71 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
|||
provider := request.RouteStringParam(r, "provider")
|
||||
if provider == "" {
|
||||
logger.Error("[OAuth2] Invalid or missing provider")
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
code := request.QueryStringParam(r, "code", "")
|
||||
if code == "" {
|
||||
logger.Error("[OAuth2] No code received on callback")
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
state := request.QueryStringParam(r, "state", "")
|
||||
if state == "" || state != request.OAuth2State(r) {
|
||||
logger.Error(`[OAuth2] Invalid state value: got "%s" instead of "%s"`, state, request.OAuth2State(r))
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
authProvider, err := getOAuth2Manager(c.cfg).Provider(provider)
|
||||
if err != nil {
|
||||
logger.Error("[OAuth2] %v", err)
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
profile, err := authProvider.GetProfile(code)
|
||||
if err != nil {
|
||||
logger.Error("[OAuth2] %v", err)
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
if request.IsAuthenticated(r) {
|
||||
user, err := c.store.UserByExtraField(profile.Key, profile.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if user != nil {
|
||||
logger.Error("[OAuth2] User #%d cannot be associated because %s is already associated", request.UserID(r), user.Username)
|
||||
sess.NewFlashErrorMessage(printer.Printf("error.duplicate_linked_account"))
|
||||
response.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
html.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.store.UpdateExtraField(request.UserID(r), profile.Key, profile.ID); err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
sess.NewFlashMessage(printer.Printf("alert.account_linked"))
|
||||
response.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
html.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.store.UserByExtraField(profile.Key, profile.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
if !c.cfg.IsOAuth2UserCreationAllowed() {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -100,14 +99,14 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
|||
user.Extra[profile.Key] = profile.ID
|
||||
|
||||
if err := c.store.CreateUser(user); err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
sessionToken, _, err := c.store.CreateUserSession(user.Username, r.UserAgent(), request.ClientIP(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -123,5 +122,5 @@ func (c *Controller) OAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
|||
c.cfg.BasePath(),
|
||||
))
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
html.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/ui/session"
|
||||
|
@ -21,16 +21,16 @@ func (c *Controller) OAuth2Redirect(w http.ResponseWriter, r *http.Request) {
|
|||
provider := request.RouteStringParam(r, "provider")
|
||||
if provider == "" {
|
||||
logger.Error("[OAuth2] Invalid or missing provider: %s", provider)
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
authProvider, err := getOAuth2Manager(c.cfg).Provider(provider)
|
||||
if err != nil {
|
||||
logger.Error("[OAuth2] %v", err)
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State()))
|
||||
html.Redirect(w, r, authProvider.GetRedirectURL(sess.NewOAuth2State()))
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/locale"
|
||||
|
@ -22,14 +21,14 @@ func (c *Controller) OAuth2Unlink(w http.ResponseWriter, r *http.Request) {
|
|||
provider := request.RouteStringParam(r, "provider")
|
||||
if provider == "" {
|
||||
logger.Info("[OAuth2] Invalid or missing provider")
|
||||
response.Redirect(w, r, route.Path(c.router, "login"))
|
||||
html.Redirect(w, r, route.Path(c.router, "login"))
|
||||
return
|
||||
}
|
||||
|
||||
authProvider, err := getOAuth2Manager(c.cfg).Provider(provider)
|
||||
if err != nil {
|
||||
logger.Error("[OAuth2] %v", err)
|
||||
response.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
html.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,21 +36,21 @@ func (c *Controller) OAuth2Unlink(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
hasPassword, err := c.store.HasPassword(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !hasPassword {
|
||||
sess.NewFlashErrorMessage(printer.Printf("error.unlink_account_without_password"))
|
||||
response.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
html.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.store.RemoveExtraField(request.UserID(r), authProvider.GetUserExtraKey()); err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
sess.NewFlashMessage(printer.Printf("alert.account_unlinked"))
|
||||
response.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
html.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ import (
|
|||
func (c *Controller) Export(w http.ResponseWriter, r *http.Request) {
|
||||
opml, err := opml.NewHandler(c.store).Export(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
xml.Attachment(w, "feeds.opml", opml)
|
||||
xml.Attachment(w, r, "feeds.opml", opml)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -17,7 +17,7 @@ import (
|
|||
func (c *Controller) Import(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -21,14 +20,14 @@ import (
|
|||
func (c *Controller) UploadOPML(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
file, fileHeader, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
logger.Error("[Controller:UploadOPML] %v", err)
|
||||
response.Redirect(w, r, route.Path(c.router, "import"))
|
||||
html.Redirect(w, r, route.Path(c.router, "import"))
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
@ -59,5 +58,5 @@ func (c *Controller) UploadOPML(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feeds"))
|
||||
html.Redirect(w, r, route.Path(c.router, "feeds"))
|
||||
}
|
||||
|
|
23
ui/proxy.go
23
ui/proxy.go
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
@ -16,44 +16,47 @@ import (
|
|||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/logger"
|
||||
)
|
||||
|
||||
// ImageProxy fetch an image from a remote server and sent it back to the browser.
|
||||
func (c *Controller) ImageProxy(w http.ResponseWriter, r *http.Request) {
|
||||
// If we receive a "If-None-Match" header we assume the image in stored in browser cache
|
||||
// If we receive a "If-None-Match" header, we assume the image is already stored in browser cache.
|
||||
if r.Header.Get("If-None-Match") != "" {
|
||||
response.NotModified(w)
|
||||
w.WriteHeader(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
|
||||
encodedURL := request.RouteStringParam(r, "encodedURL")
|
||||
if encodedURL == "" {
|
||||
html.BadRequest(w, errors.New("No URL provided"))
|
||||
html.BadRequest(w, r, errors.New("No URL provided"))
|
||||
return
|
||||
}
|
||||
|
||||
decodedURL, err := base64.URLEncoding.DecodeString(encodedURL)
|
||||
if err != nil {
|
||||
html.BadRequest(w, errors.New("Unable to decode this URL"))
|
||||
html.BadRequest(w, r, errors.New("Unable to decode this URL"))
|
||||
return
|
||||
}
|
||||
|
||||
clt := client.New(string(decodedURL))
|
||||
resp, err := clt.Get()
|
||||
if err != nil {
|
||||
logger.Error("[Controller:ImageProxy] %v", err)
|
||||
html.NotFound(w)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.HasServerFailure() {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
etag := crypto.HashFromBytes(body)
|
||||
|
||||
response.Cache(w, r, resp.ContentType, etag, body, 72*time.Hour)
|
||||
response.New(w ,r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) {
|
||||
b.WithHeader("Content-Type", resp.ContentType)
|
||||
b.WithBody(body)
|
||||
b.WithoutCompression()
|
||||
b.Write()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -19,7 +19,7 @@ import (
|
|||
func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,13 @@ func (c *Controller) ShowSearchEntries(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
count, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/ui/session"
|
||||
"miniflux.app/ui/view"
|
||||
"miniflux.app/http/response/html"
|
||||
)
|
||||
|
||||
// ShowSessions shows the list of active user sessions.
|
||||
|
@ -20,13 +20,13 @@ func (c *Controller) ShowSessions(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
sessions, err := c.store.UserSessions(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
)
|
||||
|
@ -21,5 +21,5 @@ func (c *Controller) RemoveSession(w http.ResponseWriter, r *http.Request) {
|
|||
logger.Error("[Controller:RemoveSession] %v", err)
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "sessions"))
|
||||
html.Redirect(w, r, route.Path(c.router, "sessions"))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -23,7 +23,7 @@ func (c *Controller) ShowSettings(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ func (c *Controller) ShowSettings(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
timezones, err := c.store.Timezones()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -26,13 +25,13 @@ func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
timezones, err := c.store.Timezones()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,5 +69,5 @@ func (c *Controller) UpdateSettings(w http.ResponseWriter, r *http.Request) {
|
|||
sess.SetLanguage(user.Language)
|
||||
sess.SetTheme(user.Theme)
|
||||
sess.NewFlashMessage(locale.NewPrinter(request.UserLanguage(r)).Printf("alert.prefs_saved"))
|
||||
response.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
html.Redirect(w, r, route.Path(c.router, "settings"))
|
||||
}
|
||||
|
|
|
@ -12,26 +12,28 @@ import (
|
|||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/ui/static"
|
||||
)
|
||||
|
||||
// AppIcon renders application icons.
|
||||
// AppIcon shows application icons.
|
||||
func (c *Controller) AppIcon(w http.ResponseWriter, r *http.Request) {
|
||||
filename := request.RouteStringParam(r, "filename")
|
||||
encodedBlob, found := static.Binaries[filename]
|
||||
etag, found := static.BinariesChecksums[filename]
|
||||
if !found {
|
||||
logger.Info("[Controller:AppIcon] This icon doesn't exists: %s", filename)
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
blob, err := base64.StdEncoding.DecodeString(encodedBlob)
|
||||
if err != nil {
|
||||
logger.Error("[Controller:AppIcon] %v", err)
|
||||
html.NotFound(w)
|
||||
return
|
||||
}
|
||||
response.New(w, r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) {
|
||||
blob, err := base64.StdEncoding.DecodeString(static.Binaries[filename])
|
||||
if err != nil {
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Cache(w, r, "image/png", static.BinariesChecksums[filename], blob, 48*time.Hour)
|
||||
b.WithHeader("Content-Type", "image/png")
|
||||
b.WithoutCompression()
|
||||
b.WithBody(blob)
|
||||
b.Write()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
@ -11,18 +11,27 @@ import (
|
|||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/logger"
|
||||
"miniflux.app/ui/static"
|
||||
)
|
||||
|
||||
// Favicon renders the application favicon.
|
||||
// Favicon shows the application favicon.
|
||||
func (c *Controller) Favicon(w http.ResponseWriter, r *http.Request) {
|
||||
blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"])
|
||||
if err != nil {
|
||||
logger.Error("[Controller:Favicon] %v", err)
|
||||
html.NotFound(w)
|
||||
etag, found := static.BinariesChecksums["favicon.ico"]
|
||||
if !found {
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
response.Cache(w, r, "image/x-icon", static.BinariesChecksums["favicon.ico"], blob, 48*time.Hour)
|
||||
response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
|
||||
blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"])
|
||||
if err != nil {
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
b.WithHeader("Content-Type", "image/x-icon")
|
||||
b.WithoutCompression()
|
||||
b.WithBody(blob)
|
||||
b.Write()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,13 +17,15 @@ import (
|
|||
// Javascript renders application client side code.
|
||||
func (c *Controller) Javascript(w http.ResponseWriter, r *http.Request) {
|
||||
filename := request.RouteStringParam(r, "name")
|
||||
if _, found := static.Javascripts[filename]; !found {
|
||||
html.NotFound(w)
|
||||
etag, found := static.JavascriptsChecksums[filename]
|
||||
if !found {
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
body := static.Javascripts[filename]
|
||||
etag := static.JavascriptsChecksums[filename]
|
||||
|
||||
response.Cache(w, r, "text/javascript; charset=utf-8", etag, []byte(body), 48*time.Hour)
|
||||
response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
|
||||
b.WithHeader("Content-Type", "text/javascript; charset=utf-8")
|
||||
b.WithBody(static.Javascripts[filename])
|
||||
b.Write()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,14 +16,16 @@ import (
|
|||
|
||||
// Stylesheet renders the CSS.
|
||||
func (c *Controller) Stylesheet(w http.ResponseWriter, r *http.Request) {
|
||||
stylesheet := request.RouteStringParam(r, "name")
|
||||
if _, found := static.Stylesheets[stylesheet]; !found {
|
||||
html.NotFound(w)
|
||||
filename := request.RouteStringParam(r, "name")
|
||||
etag, found := static.StylesheetsChecksums[filename]
|
||||
if !found {
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
body := static.Stylesheets[stylesheet]
|
||||
etag := static.StylesheetsChecksums[stylesheet]
|
||||
|
||||
response.Cache(w, r, "text/css; charset=utf-8", etag, []byte(body), 48*time.Hour)
|
||||
response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
|
||||
b.WithHeader("Content-Type", "text/css; charset=utf-8")
|
||||
b.WithBody(static.Stylesheets[filename])
|
||||
b.Write()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ func (c *Controller) AddSubscription(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ func (c *Controller) Bookmarklet(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -24,13 +23,13 @@ func (c *Controller) ChooseSubscription(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -65,5 +64,5 @@ func (c *Controller) ChooseSubscription(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID))
|
||||
html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/client"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -26,13 +25,13 @@ func (c *Controller) SubmitSubscription(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -90,7 +89,7 @@ func (c *Controller) SubmitSubscription(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID))
|
||||
html.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feed.ID))
|
||||
case n > 1:
|
||||
v := view.New(c.tpl, r, sess)
|
||||
v.Set("subscriptions", subscriptions)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -22,7 +22,7 @@ func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) {
|
|||
builder.WithStatus(model.EntryStatusUnread)
|
||||
countUnread, err := builder.CountEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ func (c *Controller) ShowUnreadPage(w http.ResponseWriter, r *http.Request) {
|
|||
builder.WithLimit(nbItemsPerPage)
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
)
|
||||
|
@ -19,5 +19,5 @@ func (c *Controller) MarkAllAsRead(w http.ResponseWriter, r *http.Request) {
|
|||
logger.Error("[MarkAllAsRead] %v", err)
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
html.Redirect(w, r, route.Path(c.router, "unread"))
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsAdmin {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -21,24 +21,24 @@ func (c *Controller) EditUser(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsAdmin {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
userID := request.RouteInt64Param(r, "userID")
|
||||
selectedUser, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if selectedUser == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
@ -20,18 +20,18 @@ func (c *Controller) ShowUsers(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsAdmin {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
users, err := c.store.Users()
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
)
|
||||
|
@ -17,31 +16,31 @@ import (
|
|||
func (c *Controller) RemoveUser(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsAdmin {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
userID := request.RouteInt64Param(r, "userID")
|
||||
selectedUser, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if selectedUser == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.store.RemoveUser(selectedUser.ID); err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "users"))
|
||||
html.Redirect(w, r, route.Path(c.router, "users"))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package ui // import "miniflux.app/ui"
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/route"
|
||||
|
@ -21,12 +20,12 @@ import (
|
|||
func (c *Controller) SaveUser(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsAdmin {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -60,5 +59,5 @@ func (c *Controller) SaveUser(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "users"))
|
||||
html.Redirect(w, r, route.Path(c.router, "users"))
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ui // import "miniflux.app/ui"
|
||||
package ui // import "miniflux.app/ui"
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
"miniflux.app/http/response"
|
||||
"miniflux.app/http/response/html"
|
||||
"miniflux.app/http/route"
|
||||
"miniflux.app/logger"
|
||||
|
@ -21,24 +20,24 @@ import (
|
|||
func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := c.store.UserByID(request.UserID(r))
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.IsAdmin {
|
||||
html.Forbidden(w)
|
||||
html.Forbidden(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
userID := request.RouteInt64Param(r, "userID")
|
||||
selectedUser, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
html.ServerError(w, err)
|
||||
html.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
if selectedUser == nil {
|
||||
html.NotFound(w)
|
||||
html.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -73,5 +72,5 @@ func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
response.Redirect(w, r, route.Path(c.router, "users"))
|
||||
html.Redirect(w, r, route.Path(c.router, "users"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue