Add command line argument to export user feeds

This commit is contained in:
Frédéric Guillot 2023-09-27 21:15:32 -07:00
parent 39d752ca85
commit f98fc1e03a
5 changed files with 50 additions and 5 deletions

View File

@ -14,13 +14,13 @@ import (
func (h *handler) exportFeeds(w http.ResponseWriter, r *http.Request) {
opmlHandler := opml.NewHandler(h.store)
opml, err := opmlHandler.Export(request.UserID(r))
opmlExport, err := opmlHandler.Export(request.UserID(r))
if err != nil {
json.ServerError(w, r, err)
return
}
xml.OK(w, r, opml)
xml.OK(w, r, opmlExport)
}
func (h *handler) importFeeds(w http.ResponseWriter, r *http.Request) {

View File

@ -32,6 +32,7 @@ const (
flagHealthCheckHelp = `Perform a health check on the given endpoint (the value "auto" try to guess the health check endpoint).`
flagRefreshFeedsHelp = "Refresh a batch of feeds and exit"
flagRunCleanupTasksHelp = "Run cleanup tasks (delete old sessions and archives old entries)"
flagExportUserFeedsHelp = "Export user feeds (provide the username as argument)"
)
// Parse parses command line arguments.
@ -51,6 +52,7 @@ func Parse() {
flagHealthCheck string
flagRefreshFeeds bool
flagRunCleanupTasks bool
flagExportUserFeeds string
)
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
@ -69,6 +71,7 @@ func Parse() {
flag.StringVar(&flagHealthCheck, "healthcheck", "", flagHealthCheckHelp)
flag.BoolVar(&flagRefreshFeeds, "refresh-feeds", false, flagRefreshFeedsHelp)
flag.BoolVar(&flagRunCleanupTasks, "run-cleanup-tasks", false, flagRunCleanupTasksHelp)
flag.StringVar(&flagExportUserFeeds, "export-user-feeds", "", flagExportUserFeedsHelp)
flag.Parse()
cfg := config.NewParser()
@ -177,6 +180,11 @@ func Parse() {
return
}
if flagExportUserFeeds != "" {
exportUserFeeds(store, flagExportUserFeeds)
return
}
if flagFlushSessions {
flushSessions(store)
return

View File

@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package cli // import "miniflux.app/v2/internal/cli"
import (
"fmt"
"miniflux.app/v2/internal/reader/opml"
"miniflux.app/v2/internal/storage"
)
func exportUserFeeds(store *storage.Storage, username string) {
user, err := store.UserByUsername(username)
if err != nil {
printErrorAndExit(fmt.Errorf("unable to find user: %w", err))
}
if user == nil {
printErrorAndExit(fmt.Errorf("user %q not found", username))
}
opmlHandler := opml.NewHandler(store)
opmlExport, err := opmlHandler.Export(user.ID)
if err != nil {
printErrorAndExit(fmt.Errorf("unable to export feeds: %w", err))
}
fmt.Println(opmlExport)
}

View File

@ -13,11 +13,11 @@ import (
)
func (h *handler) exportFeeds(w http.ResponseWriter, r *http.Request) {
opml, err := opml.NewHandler(h.store).Export(request.UserID(r))
opmlExport, err := opml.NewHandler(h.store).Export(request.UserID(r))
if err != nil {
html.ServerError(w, r, err)
return
}
xml.Attachment(w, r, "feeds.opml", opml)
xml.Attachment(w, r, "feeds.opml", opmlExport)
}

View File

@ -1,5 +1,5 @@
.\" Manpage for miniflux.
.TH "MINIFLUX" "1" "September 24, 2023" "\ \&" "\ \&"
.TH "MINIFLUX" "1" "September 27, 2023" "\ \&" "\ \&"
.SH NAME
miniflux \- Minimalist and opinionated feed reader
@ -39,6 +39,13 @@ Create admin user\&.
Set log level to debug\&.
.RE
.PP
.B \-export-user-feeds <username>
.RS 4
Export user feeds (provide the username as argument)\&.
.br
Example: "miniflux -export-user-feeds someone > feeds.xml"\&.
.RE
.PP
.B \-flush-sessions
.RS 4
Flush all sessions (disconnect users)\&.