From 62229deec5e57a9c4e105248c18dbbd9bb5ce5d8 Mon Sep 17 00:00:00 2001 From: xuu Date: Thu, 27 Mar 2025 16:52:01 -0600 Subject: [PATCH] chore: use XT_URI for seed --- app.go | 25 +++++++++++++++++++------ main.go | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app.go b/app.go index d76d9b4..f23f805 100644 --- a/app.go +++ b/app.go @@ -4,6 +4,8 @@ import ( "context" "database/sql" "fmt" + "io" + "net/http" "os" "runtime/debug" "strconv" @@ -68,13 +70,24 @@ func run(ctx context.Context, c *console.C[args]) error { ctx, span := otel.Span(ctx) defer span.End() - f, err := os.Open(a.baseFeed) - if err != nil { - return err - } - defer f.Close() + var inFile io.Reader - twtfile, err := lextwt.ParseFile(f, &types.Twter{ + if a.baseFeed != "" { + f, err := os.Open(a.baseFeed) + if err != nil { + return err + } + defer f.Close() + } else { + res, err := http.Get(a.URI) + if err != nil { + return err + } + inFile = res.Body + defer res.Body.Close() + } + + twtfile, err := lextwt.ParseFile(inFile, &types.Twter{ Nick: a.Nick, URI: a.URI, }) diff --git a/main.go b/main.go index 1398f9f..506931a 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ func main() { ctx, console := console.New(args{ dbtype: env.Default("XT_DBTYPE", "sqlite3"), dbfile: env.Default("XT_DBFILE", "file:twt.db"), - baseFeed: env.Default("XT_BASE_FEED", "feed"), + baseFeed: env.Default("XT_BASE_FEED", ""), Nick: env.Default("XT_NICK", "xuu"), URI: env.Default("XT_URI", "https://txt.sour.is/user/xuu/twtxt.txt"), Listen: env.Default("XT_LISTEN", ":8080"),