Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paths starting with ~ are now supported in the opml import path #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"log"
"net/http"
"os/user"
"path/filepath"
"strings"
"sync"

"github.com/gilliek/go-opml/opml"
Expand All @@ -25,7 +28,15 @@ func (r *RSS) Init(c *Controller) {

// Check if we have any OMPL file to load
if r.c.conf.OPMLFile != "" {
doc, err := opml.NewOPMLFromFile(r.c.conf.OPMLFile)
opmlpath := r.c.conf.OPMLFile
// if the path contains ~
if strings.HasPrefix(opmlpath, "~/") {
usr, _ := user.Current()
Copy link
Owner

@Lallassu Lallassu Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably check for errors here. Then log an appropriate message in case it fails and return.

homedir := usr.HomeDir
opmlpath = strings.Replace(opmlpath, "~/", "", 1)
opmlpath = filepath.Join(homedir, opmlpath)
}
doc, err := opml.NewOPMLFromFile(opmlpath)
if err != nil {
log.Printf("Failed to load OPML file, %v", err)
return
Expand Down Expand Up @@ -110,7 +121,6 @@ func (r *RSS) FetchURL(fp *gofeed.Parser, url string) (feed *gofeed.Feed, err er

req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
resp, err := client.Do(req)

if err != nil {
return nil, err
}
Expand Down