2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-10-05 07:30:25 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2019-10-05 07:30:25 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response"
|
|
|
|
"miniflux.app/v2/internal/http/response/html"
|
|
|
|
"miniflux.app/v2/internal/http/route"
|
|
|
|
"miniflux.app/v2/internal/storage"
|
|
|
|
"miniflux.app/v2/internal/ui/session"
|
|
|
|
"miniflux.app/v2/internal/ui/view"
|
2019-10-05 07:30:25 -04:00
|
|
|
)
|
|
|
|
|
2020-03-22 21:48:14 -04:00
|
|
|
func (h *handler) createSharedEntry(w http.ResponseWriter, r *http.Request) {
|
2019-10-05 07:30:25 -04:00
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
2020-03-22 21:48:14 -04:00
|
|
|
shareCode, err := h.store.EntryShareCode(request.UserID(r), entryID)
|
2019-10-05 07:30:25 -04:00
|
|
|
if err != nil {
|
|
|
|
html.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:48:14 -04:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "sharedEntry", "shareCode", shareCode))
|
2019-10-05 07:30:25 -04:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:48:14 -04:00
|
|
|
func (h *handler) unshareEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
|
|
|
if err := h.store.UnshareEntry(request.UserID(r), entryID); err != nil {
|
|
|
|
html.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
html.Redirect(w, r, route.Path(h.router, "sharedEntries"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handler) sharedEntry(w http.ResponseWriter, r *http.Request) {
|
2019-10-05 07:30:25 -04:00
|
|
|
shareCode := request.RouteStringParam(r, "shareCode")
|
|
|
|
if shareCode == "" {
|
|
|
|
html.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
etag := shareCode
|
|
|
|
response.New(w, r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) {
|
|
|
|
builder := storage.NewAnonymousQueryBuilder(h.store)
|
|
|
|
builder.WithShareCode(shareCode)
|
|
|
|
|
|
|
|
entry, err := builder.GetEntry()
|
|
|
|
if err != nil || entry == nil {
|
|
|
|
html.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
|
|
|
view.Set("entry", entry)
|
|
|
|
|
|
|
|
b.WithHeader("Content-Type", "text/html; charset=utf-8")
|
|
|
|
b.WithBody(view.Render("entry"))
|
|
|
|
b.Write()
|
|
|
|
})
|
|
|
|
}
|