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) { func (h *handler) exportFeeds(w http.ResponseWriter, r *http.Request) {
opmlHandler := opml.NewHandler(h.store) opmlHandler := opml.NewHandler(h.store)
opml, err := opmlHandler.Export(request.UserID(r)) opmlExport, err := opmlHandler.Export(request.UserID(r))
if err != nil { if err != nil {
json.ServerError(w, r, err) json.ServerError(w, r, err)
return return
} }
xml.OK(w, r, opml) xml.OK(w, r, opmlExport)
} }
func (h *handler) importFeeds(w http.ResponseWriter, r *http.Request) { 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).` 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" flagRefreshFeedsHelp = "Refresh a batch of feeds and exit"
flagRunCleanupTasksHelp = "Run cleanup tasks (delete old sessions and archives old entries)" 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. // Parse parses command line arguments.
@ -51,6 +52,7 @@ func Parse() {
flagHealthCheck string flagHealthCheck string
flagRefreshFeeds bool flagRefreshFeeds bool
flagRunCleanupTasks bool flagRunCleanupTasks bool
flagExportUserFeeds string
) )
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp) flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
@ -69,6 +71,7 @@ func Parse() {
flag.StringVar(&flagHealthCheck, "healthcheck", "", flagHealthCheckHelp) flag.StringVar(&flagHealthCheck, "healthcheck", "", flagHealthCheckHelp)
flag.BoolVar(&flagRefreshFeeds, "refresh-feeds", false, flagRefreshFeedsHelp) flag.BoolVar(&flagRefreshFeeds, "refresh-feeds", false, flagRefreshFeedsHelp)
flag.BoolVar(&flagRunCleanupTasks, "run-cleanup-tasks", false, flagRunCleanupTasksHelp) flag.BoolVar(&flagRunCleanupTasks, "run-cleanup-tasks", false, flagRunCleanupTasksHelp)
flag.StringVar(&flagExportUserFeeds, "export-user-feeds", "", flagExportUserFeedsHelp)
flag.Parse() flag.Parse()
cfg := config.NewParser() cfg := config.NewParser()
@ -177,6 +180,11 @@ func Parse() {
return return
} }
if flagExportUserFeeds != "" {
exportUserFeeds(store, flagExportUserFeeds)
return
}
if flagFlushSessions { if flagFlushSessions {
flushSessions(store) flushSessions(store)
return 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) { 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 { if err != nil {
html.ServerError(w, r, err) html.ServerError(w, r, err)
return return
} }
xml.Attachment(w, r, "feeds.opml", opml) xml.Attachment(w, r, "feeds.opml", opmlExport)
} }

View file

@ -1,5 +1,5 @@
.\" Manpage for miniflux. .\" Manpage for miniflux.
.TH "MINIFLUX" "1" "September 24, 2023" "\ \&" "\ \&" .TH "MINIFLUX" "1" "September 27, 2023" "\ \&" "\ \&"
.SH NAME .SH NAME
miniflux \- Minimalist and opinionated feed reader miniflux \- Minimalist and opinionated feed reader
@ -39,6 +39,13 @@ Create admin user\&.
Set log level to debug\&. Set log level to debug\&.
.RE .RE
.PP .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 .B \-flush-sessions
.RS 4 .RS 4
Flush all sessions (disconnect users)\&. Flush all sessions (disconnect users)\&.