diff options
Diffstat (limited to 'src/http')
-rw-r--r-- | src/http/http.go | 11 | ||||
-rw-r--r-- | src/http/posts.go | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/http/http.go b/src/http/http.go index da39374..98cdde3 100644 --- a/src/http/http.go +++ b/src/http/http.go @@ -56,12 +56,17 @@ type Params struct { // AuthRatelimit indicates how much time must pass between subsequent auth // attempts. AuthRatelimit time.Duration + + // GeminiGatewayURL will be used to translate links for `gemini://` into + // `http(s)://`. See gmi.GemtextToMarkdown. + GeminiGatewayURL *url.URL } // SetupCfg implement the cfg.Cfger interface. func (p *Params) SetupCfg(cfg *cfg.Cfg) { publicURLStr := cfg.String("http-public-url", "http://localhost:4000", "URL this service is accessible at") + geminiGatewayURLStr := cfg.String("http-gemini-gateway-url", "", "Optional URL to prefix to all gemini:// links, to make them accessible over https") cfg.StringVar(&p.ListenProto, "http-listen-proto", "tcp", "Protocol to listen for HTTP requests with") cfg.StringVar(&p.ListenAddr, "http-listen-addr", ":4000", "Address/unix socket path to listen for HTTP requests on") @@ -87,6 +92,12 @@ func (p *Params) SetupCfg(cfg *cfg.Cfg) { return fmt.Errorf("parsing -http-public-url: %w", err) } + if *geminiGatewayURLStr != "" { + if p.GeminiGatewayURL, err = url.Parse(*geminiGatewayURLStr); err != nil { + return fmt.Errorf("parsing -http-gemini-gateway-url: %w", err) + } + } + return nil }) } diff --git a/src/http/posts.go b/src/http/posts.go index cae8f43..bb1c899 100644 --- a/src/http/posts.go +++ b/src/http/posts.go @@ -96,7 +96,11 @@ func (a *api) postToPostTplPayload(storedPost post.StoredPost) (postTplPayload, prevBodyBuf := bodyBuf bodyBuf = new(bytes.Buffer) - if err := gmi.GemtextToMarkdown(bodyBuf, prevBodyBuf); err != nil { + err := gmi.GemtextToMarkdown( + bodyBuf, prevBodyBuf, a.params.GeminiGatewayURL, + ) + + if err != nil { return postTplPayload{}, fmt.Errorf("converting gemtext to markdown: %w", err) } } |