feat: makes number of items imported on initial feed add configurable

This commit is contained in:
Dennis Schoepf 2025-08-29 14:31:34 +02:00
parent 0598672fbe
commit 62ecd11a69
2 changed files with 11 additions and 7 deletions

View file

@ -30,12 +30,19 @@ var addCmd = &cobra.Command{
Short: "Adds a new feed to the application.", Short: "Adds a new feed to the application.",
Long: `Validates and stores a feed in the application's database. Depending on the feed type, articles, videos, or updates are fetched right away. Long: `Validates and stores a feed in the application's database. Depending on the feed type, articles, videos, or updates are fetched right away.
The number of articles that are imported initially can be set with the --last flag. If it is not provided the last 10 items are imported.
Supported types currently are: Supported types currently are:
- RSS feeds - RSS feeds
- Atom feeds - Atom feeds
`, `,
Example: `freed add "..."
freed add "..." --last 50 <- Imports the last 50 items in the feed`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
feedName, articlesCount, err := internal.AddFeed(args[0]) addRecentCount := 10
addRecentCount, _ = cmd.Flags().GetInt("last")
feedName, articlesCount, err := internal.AddFeed(args[0], addRecentCount)
if err != nil { if err != nil {
pterm.Error.Printf("Error adding feed: %v\n", err) pterm.Error.Printf("Error adding feed: %v\n", err)

View file

@ -4,12 +4,10 @@ import (
"fmt" "fmt"
"freed/internal/database" "freed/internal/database"
"net/url" "net/url"
"strconv"
"sync" "sync"
"time" "time"
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
"github.com/pterm/pterm"
) )
type Feed struct { type Feed struct {
@ -21,7 +19,7 @@ type Feed struct {
ArticleCount int ArticleCount int
} }
func AddFeed(feedUrl string) (string, int, error) { func AddFeed(feedUrl string, addRecentCount int) (string, int, error) {
if _, err := url.ParseRequestURI(feedUrl); err != nil { if _, err := url.ParseRequestURI(feedUrl); err != nil {
return "", 0, fmt.Errorf("The given URL does not seem to be valid: %s", err) return "", 0, fmt.Errorf("The given URL does not seem to be valid: %s", err)
} }
@ -42,11 +40,10 @@ func AddFeed(feedUrl string) (string, int, error) {
return "", 0, err return "", 0, err
} }
// TODO: Make the amount of articles configurable articles := make([]database.ArticleEntity, 0, addRecentCount)
articles := make([]database.ArticleEntity, 0, 10)
for i, v := range feed.Items { for i, v := range feed.Items {
if i > 10 { if i > addRecentCount {
continue continue
} }