2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-20 06:10:04 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package api // import "miniflux.app/v2/internal/api"
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
import (
|
2021-01-05 00:32:32 +01:00
|
|
|
json_parser "encoding/json"
|
2017-11-20 06:10:04 +01:00
|
|
|
"errors"
|
2018-04-30 01:35:04 +02:00
|
|
|
"net/http"
|
2022-04-14 06:53:06 +02:00
|
|
|
"strconv"
|
2022-10-15 08:17:17 +02:00
|
|
|
"strings"
|
2018-06-10 04:13:41 +02:00
|
|
|
"time"
|
2017-11-25 07:29:20 +01:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/json"
|
|
|
|
"miniflux.app/v2/internal/integration"
|
2024-03-21 04:59:09 +01:00
|
|
|
"miniflux.app/v2/internal/mediaproxy"
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
"miniflux.app/v2/internal/reader/processor"
|
2023-10-07 07:42:59 +02:00
|
|
|
"miniflux.app/v2/internal/reader/readingtime"
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/storage"
|
2023-08-14 04:09:01 +02:00
|
|
|
"miniflux.app/v2/internal/urllib"
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/validator"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2022-10-15 08:17:17 +02:00
|
|
|
func (h *handler) getEntryFromBuilder(w http.ResponseWriter, r *http.Request, b *storage.EntryQueryBuilder) {
|
2021-01-19 04:44:02 +01:00
|
|
|
entry, err := b.GetEntry()
|
2017-11-20 06:10:04 +01:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.ServerError(w, r, err)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry == nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.NotFound(w, r)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-21 04:59:09 +01:00
|
|
|
entry.Content = mediaproxy.RewriteDocumentWithAbsoluteProxyURL(h.router, r.Host, entry.Content)
|
|
|
|
proxyOption := config.Opts.MediaProxyMode()
|
2022-10-15 08:17:17 +02:00
|
|
|
|
|
|
|
for i := range entry.Enclosures {
|
2023-08-14 04:09:01 +02:00
|
|
|
if proxyOption == "all" || proxyOption != "none" && !urllib.IsHTTPS(entry.Enclosures[i].URL) {
|
2024-03-21 04:59:09 +01:00
|
|
|
for _, mediaType := range config.Opts.MediaProxyResourceTypes() {
|
2023-02-25 09:36:19 +01:00
|
|
|
if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") {
|
2024-03-21 04:59:09 +01:00
|
|
|
entry.Enclosures[i].URL = mediaproxy.ProxifyAbsoluteURL(h.router, r.Host, entry.Enclosures[i].URL)
|
2023-02-25 09:36:19 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-10-15 08:17:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-20 04:27:05 +02:00
|
|
|
json.OK(w, r, entry)
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-19 04:44:02 +01:00
|
|
|
func (h *handler) getFeedEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2018-09-24 06:02:26 +02:00
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
2021-01-19 04:44:02 +01:00
|
|
|
|
2018-11-11 19:22:47 +01:00
|
|
|
builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
2021-01-19 04:44:02 +01:00
|
|
|
builder.WithFeedID(feedID)
|
2017-12-22 20:33:01 +01:00
|
|
|
builder.WithEntryID(entryID)
|
|
|
|
|
2022-10-15 08:17:17 +02:00
|
|
|
h.getEntryFromBuilder(w, r, builder)
|
2021-01-19 04:44:02 +01:00
|
|
|
}
|
2017-12-22 20:33:01 +01:00
|
|
|
|
2021-01-19 04:44:02 +01:00
|
|
|
func (h *handler) getCategoryEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
|
categoryID := request.RouteInt64Param(r, "categoryID")
|
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
2017-12-22 20:33:01 +01:00
|
|
|
|
2021-01-19 04:44:02 +01:00
|
|
|
builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
|
builder.WithCategoryID(categoryID)
|
|
|
|
builder.WithEntryID(entryID)
|
|
|
|
|
2022-10-15 08:17:17 +02:00
|
|
|
h.getEntryFromBuilder(w, r, builder)
|
2021-01-19 04:44:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handler) getEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
|
|
|
builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
|
builder.WithEntryID(entryID)
|
|
|
|
|
2022-10-15 08:17:17 +02:00
|
|
|
h.getEntryFromBuilder(w, r, builder)
|
2017-12-22 20:33:01 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 19:22:47 +01:00
|
|
|
func (h *handler) getFeedEntries(w http.ResponseWriter, r *http.Request) {
|
2018-09-24 06:02:26 +02:00
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2021-01-19 04:44:02 +01:00
|
|
|
h.findEntries(w, r, feedID, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handler) getCategoryEntries(w http.ResponseWriter, r *http.Request) {
|
|
|
|
categoryID := request.RouteInt64Param(r, "categoryID")
|
|
|
|
h.findEntries(w, r, 0, categoryID)
|
2017-11-27 00:07:59 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 19:22:47 +01:00
|
|
|
func (h *handler) getEntries(w http.ResponseWriter, r *http.Request) {
|
2021-01-19 04:44:02 +01:00
|
|
|
h.findEntries(w, r, 0, 0)
|
2020-09-14 06:38:11 +02:00
|
|
|
}
|
|
|
|
|
2021-01-19 04:44:02 +01:00
|
|
|
func (h *handler) findEntries(w http.ResponseWriter, r *http.Request, feedID int64, categoryID int64) {
|
2020-09-13 06:17:55 +02:00
|
|
|
statuses := request.QueryStringParamList(r, "status")
|
|
|
|
for _, status := range statuses {
|
2021-01-05 00:32:32 +01:00
|
|
|
if err := validator.ValidateEntryStatus(status); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.BadRequest(w, r, err)
|
2017-11-27 00:07:59 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 06:02:26 +02:00
|
|
|
order := request.QueryStringParam(r, "order", model.DefaultSortingOrder)
|
2021-01-05 00:32:32 +01:00
|
|
|
if err := validator.ValidateEntryOrder(order); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.BadRequest(w, r, err)
|
2017-11-27 00:07:59 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-24 06:02:26 +02:00
|
|
|
direction := request.QueryStringParam(r, "direction", model.DefaultSortingDirection)
|
2021-01-05 00:32:32 +01:00
|
|
|
if err := validator.ValidateDirection(direction); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.BadRequest(w, r, err)
|
2017-11-27 00:07:59 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-30 01:35:04 +02:00
|
|
|
limit := request.QueryIntParam(r, "limit", 100)
|
|
|
|
offset := request.QueryIntParam(r, "offset", 0)
|
2021-01-05 00:32:32 +01:00
|
|
|
if err := validator.ValidateRange(offset, limit); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.BadRequest(w, r, err)
|
2017-11-27 00:07:59 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-13 06:40:13 +02:00
|
|
|
userID := request.UserID(r)
|
2021-01-19 04:44:02 +01:00
|
|
|
categoryID = request.QueryInt64Param(r, "category_id", categoryID)
|
2021-01-04 07:28:04 +01:00
|
|
|
if categoryID > 0 && !h.store.CategoryIDExists(userID, categoryID) {
|
2023-07-31 00:33:56 +02:00
|
|
|
json.BadRequest(w, r, errors.New("invalid category ID"))
|
2020-09-13 06:40:13 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-14 06:38:11 +02:00
|
|
|
feedID = request.QueryInt64Param(r, "feed_id", feedID)
|
|
|
|
if feedID > 0 && !h.store.FeedExists(userID, feedID) {
|
2023-07-31 00:33:56 +02:00
|
|
|
json.BadRequest(w, r, errors.New("invalid feed ID"))
|
2020-09-14 06:38:11 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-25 05:52:45 +01:00
|
|
|
tags := request.QueryStringParamList(r, "tags")
|
|
|
|
|
2020-09-13 06:40:13 +02:00
|
|
|
builder := h.store.NewEntryQueryBuilder(userID)
|
2020-09-14 06:38:11 +02:00
|
|
|
builder.WithFeedID(feedID)
|
2020-09-13 06:40:13 +02:00
|
|
|
builder.WithCategoryID(categoryID)
|
2020-09-13 06:17:55 +02:00
|
|
|
builder.WithStatuses(statuses)
|
2023-06-19 23:00:10 +02:00
|
|
|
builder.WithSorting(order, direction)
|
2017-11-20 06:10:04 +01:00
|
|
|
builder.WithOffset(offset)
|
|
|
|
builder.WithLimit(limit)
|
2023-02-25 05:52:45 +01:00
|
|
|
builder.WithTags(tags)
|
2023-10-06 05:51:00 +02:00
|
|
|
builder.WithEnclosures()
|
2018-06-10 04:13:41 +02:00
|
|
|
configureFilters(builder, r)
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
entries, err := builder.GetEntries()
|
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.ServerError(w, r, err)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
count, err := builder.CountEntries()
|
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.ServerError(w, r, err)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-15 08:17:17 +02:00
|
|
|
for i := range entries {
|
2024-03-21 04:59:09 +01:00
|
|
|
entries[i].Content = mediaproxy.RewriteDocumentWithAbsoluteProxyURL(h.router, r.Host, entries[i].Content)
|
2022-10-15 08:17:17 +02:00
|
|
|
}
|
|
|
|
|
2018-07-20 04:27:05 +02:00
|
|
|
json.OK(w, r, &entriesResponse{Total: count, Entries: entries})
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 19:22:47 +01:00
|
|
|
func (h *handler) setEntryStatus(w http.ResponseWriter, r *http.Request) {
|
2021-01-05 00:32:32 +01:00
|
|
|
var entriesStatusUpdateRequest model.EntriesStatusUpdateRequest
|
|
|
|
if err := json_parser.NewDecoder(r.Body).Decode(&entriesStatusUpdateRequest); err != nil {
|
|
|
|
json.BadRequest(w, r, err)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-05 00:32:32 +01:00
|
|
|
if err := validator.ValidateEntriesStatusUpdateRequest(&entriesStatusUpdateRequest); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.BadRequest(w, r, err)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-05 00:32:32 +01:00
|
|
|
if err := h.store.SetEntriesStatus(request.UserID(r), entriesStatusUpdateRequest.EntryIDs, entriesStatusUpdateRequest.Status); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.ServerError(w, r, err)
|
2017-11-20 06:10:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-08 03:42:43 +02:00
|
|
|
json.NoContent(w, r)
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
2017-12-22 20:33:01 +01:00
|
|
|
|
2018-11-11 19:22:47 +01:00
|
|
|
func (h *handler) toggleBookmark(w http.ResponseWriter, r *http.Request) {
|
2018-09-24 06:02:26 +02:00
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
2018-11-11 19:22:47 +01:00
|
|
|
if err := h.store.ToggleBookmark(request.UserID(r), entryID); err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
json.ServerError(w, r, err)
|
2017-12-22 20:33:01 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-08 03:42:43 +02:00
|
|
|
json.NoContent(w, r)
|
2017-12-22 20:33:01 +01:00
|
|
|
}
|
2018-06-10 04:13:41 +02:00
|
|
|
|
2023-07-28 22:56:59 +02:00
|
|
|
func (h *handler) saveEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
|
|
|
builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
|
builder.WithEntryID(entryID)
|
|
|
|
builder.WithoutStatus(model.EntryStatusRemoved)
|
2023-07-31 00:33:56 +02:00
|
|
|
|
2023-07-28 22:56:59 +02:00
|
|
|
if !h.store.HasSaveEntry(request.UserID(r)) {
|
2023-07-31 00:33:56 +02:00
|
|
|
json.BadRequest(w, r, errors.New("no third-party integration enabled"))
|
2023-07-28 22:56:59 +02:00
|
|
|
return
|
|
|
|
}
|
2023-07-31 00:33:56 +02:00
|
|
|
|
2023-07-28 22:56:59 +02:00
|
|
|
entry, err := builder.GetEntry()
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
json.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settings, err := h.store.Integration(request.UserID(r))
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-31 00:33:56 +02:00
|
|
|
go integration.SendEntry(entry, settings)
|
2023-07-28 22:56:59 +02:00
|
|
|
|
2023-07-31 00:33:56 +02:00
|
|
|
json.Accepted(w, r)
|
2023-07-28 22:56:59 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 07:42:59 +02:00
|
|
|
func (h *handler) updateEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var entryUpdateRequest model.EntryUpdateRequest
|
|
|
|
if err := json_parser.NewDecoder(r.Body).Decode(&entryUpdateRequest); err != nil {
|
|
|
|
json.BadRequest(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validator.ValidateEntryModification(&entryUpdateRequest); err != nil {
|
|
|
|
json.BadRequest(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
loggedUserID := request.UserID(r)
|
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
|
|
|
|
|
|
|
entryBuilder := h.store.NewEntryQueryBuilder(loggedUserID)
|
|
|
|
entryBuilder.WithEntryID(entryID)
|
|
|
|
entryBuilder.WithoutStatus(model.EntryStatusRemoved)
|
|
|
|
|
|
|
|
entry, err := entryBuilder.GetEntry()
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
json.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := h.store.UserByID(loggedUserID)
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if user == nil {
|
|
|
|
json.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
entryUpdateRequest.Patch(entry)
|
2024-02-29 13:07:36 +01:00
|
|
|
if user.ShowReadingTime {
|
|
|
|
entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed)
|
|
|
|
}
|
2023-10-07 07:42:59 +02:00
|
|
|
|
|
|
|
if err := h.store.UpdateEntryTitleAndContent(entry); err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Created(w, r, entry)
|
|
|
|
}
|
|
|
|
|
2022-01-27 05:29:37 +01:00
|
|
|
func (h *handler) fetchContent(w http.ResponseWriter, r *http.Request) {
|
|
|
|
loggedUserID := request.UserID(r)
|
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
|
|
|
|
|
|
|
entryBuilder := h.store.NewEntryQueryBuilder(loggedUserID)
|
|
|
|
entryBuilder.WithEntryID(entryID)
|
|
|
|
entryBuilder.WithoutStatus(model.EntryStatusRemoved)
|
|
|
|
|
|
|
|
entry, err := entryBuilder.GetEntry()
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry == nil {
|
|
|
|
json.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-07 07:42:59 +02:00
|
|
|
user, err := h.store.UserByID(loggedUserID)
|
2021-08-30 16:53:05 +02:00
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
2022-07-19 06:03:18 +02:00
|
|
|
return
|
2021-08-30 16:53:05 +02:00
|
|
|
}
|
2022-07-19 06:03:18 +02:00
|
|
|
|
2021-08-30 16:53:05 +02:00
|
|
|
if user == nil {
|
|
|
|
json.NotFound(w, r)
|
2022-07-19 06:03:18 +02:00
|
|
|
return
|
2021-08-30 16:53:05 +02:00
|
|
|
}
|
|
|
|
|
2022-01-27 05:29:37 +01:00
|
|
|
feedBuilder := storage.NewFeedQueryBuilder(h.store, loggedUserID)
|
|
|
|
feedBuilder.WithFeedID(entry.FeedID)
|
|
|
|
feed, err := feedBuilder.GetFeed()
|
|
|
|
if err != nil {
|
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if feed == nil {
|
|
|
|
json.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-30 16:53:05 +02:00
|
|
|
if err := processor.ProcessEntryWebPage(feed, entry, user); err != nil {
|
2022-01-27 05:29:37 +01:00
|
|
|
json.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
json.OK(w, r, map[string]string{"content": entry.Content})
|
|
|
|
}
|
|
|
|
|
2023-10-06 06:37:45 +02:00
|
|
|
func (h *handler) flushHistory(w http.ResponseWriter, r *http.Request) {
|
|
|
|
loggedUserID := request.UserID(r)
|
|
|
|
go h.store.FlushHistory(loggedUserID)
|
|
|
|
json.Accepted(w, r)
|
|
|
|
}
|
|
|
|
|
2018-06-10 04:13:41 +02:00
|
|
|
func configureFilters(builder *storage.EntryQueryBuilder, r *http.Request) {
|
2023-10-06 05:28:36 +02:00
|
|
|
if beforeEntryID := request.QueryInt64Param(r, "before_entry_id", 0); beforeEntryID > 0 {
|
2018-06-10 04:13:41 +02:00
|
|
|
builder.BeforeEntryID(beforeEntryID)
|
|
|
|
}
|
|
|
|
|
2023-10-06 05:28:36 +02:00
|
|
|
if afterEntryID := request.QueryInt64Param(r, "after_entry_id", 0); afterEntryID > 0 {
|
2018-06-10 04:13:41 +02:00
|
|
|
builder.AfterEntryID(afterEntryID)
|
|
|
|
}
|
|
|
|
|
2023-10-06 05:28:36 +02:00
|
|
|
if beforePublishedTimestamp := request.QueryInt64Param(r, "before", 0); beforePublishedTimestamp > 0 {
|
|
|
|
builder.BeforePublishedDate(time.Unix(beforePublishedTimestamp, 0))
|
2018-06-10 04:13:41 +02:00
|
|
|
}
|
|
|
|
|
2023-10-06 05:28:36 +02:00
|
|
|
if afterPublishedTimestamp := request.QueryInt64Param(r, "after", 0); afterPublishedTimestamp > 0 {
|
|
|
|
builder.AfterPublishedDate(time.Unix(afterPublishedTimestamp, 0))
|
2018-06-10 04:13:41 +02:00
|
|
|
}
|
|
|
|
|
2023-10-06 05:28:36 +02:00
|
|
|
if beforePublishedTimestamp := request.QueryInt64Param(r, "published_before", 0); beforePublishedTimestamp > 0 {
|
|
|
|
builder.BeforePublishedDate(time.Unix(beforePublishedTimestamp, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
if afterPublishedTimestamp := request.QueryInt64Param(r, "published_after", 0); afterPublishedTimestamp > 0 {
|
|
|
|
builder.AfterPublishedDate(time.Unix(afterPublishedTimestamp, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
if beforeChangedTimestamp := request.QueryInt64Param(r, "changed_before", 0); beforeChangedTimestamp > 0 {
|
|
|
|
builder.BeforeChangedDate(time.Unix(beforeChangedTimestamp, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
if afterChangedTimestamp := request.QueryInt64Param(r, "changed_after", 0); afterChangedTimestamp > 0 {
|
|
|
|
builder.AfterChangedDate(time.Unix(afterChangedTimestamp, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
if categoryID := request.QueryInt64Param(r, "category_id", 0); categoryID > 0 {
|
2019-11-18 07:53:11 +01:00
|
|
|
builder.WithCategoryID(categoryID)
|
|
|
|
}
|
|
|
|
|
2018-06-10 04:13:41 +02:00
|
|
|
if request.HasQueryParam(r, "starred") {
|
2022-04-14 06:53:06 +02:00
|
|
|
starred, err := strconv.ParseBool(r.URL.Query().Get("starred"))
|
|
|
|
if err == nil {
|
|
|
|
builder.WithStarred(starred)
|
|
|
|
}
|
2018-06-10 04:13:41 +02:00
|
|
|
}
|
2018-07-05 02:40:03 +02:00
|
|
|
|
2023-10-06 05:28:36 +02:00
|
|
|
if searchQuery := request.QueryStringParam(r, "search", ""); searchQuery != "" {
|
2018-07-05 02:40:03 +02:00
|
|
|
builder.WithSearchQuery(searchQuery)
|
|
|
|
}
|
2018-06-10 04:13:41 +02:00
|
|
|
}
|