diff --git a/core/config/config.go b/core/config/config.go index 01fe6f0..607c267 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -49,11 +49,11 @@ func (s *ServerConfig) InitializeConfig() error { s.SetToken(token) proxyServer, hasProxyServer := os.LookupEnv("PIXIVFE_IMAGEPROXY") - if !hasProxyServer { - log.Fatalln("PIXIVFE_IMAGEPROXY is required, but was not set.") - return errors.New("PIXIVFE_IMAGEPROXY is required, but was not set.\n") + if hasProxyServer { + s.SetProxyServer(proxyServer) + } else { + s.ProxyServer = url.URL{Path: "/proxy/i.pximg.net"} } - s.SetProxyServer(proxyServer) hostname, hasHostname := os.LookupEnv("PIXIVFE_HOST") if hasHostname { diff --git a/core/config/session.go b/core/config/session.go index cfce0a7..ff1d0ac 100644 --- a/core/config/session.go +++ b/core/config/session.go @@ -43,15 +43,27 @@ func ProxyImageUrlNoEscape(c *fiber.Ctx, s string) string { return s } -// footgun: if proxy server has prefix path (.Path != "/""), PixivFE will not work +// note: still cannot believe Go didn't have this function +func urlAuthority(url url.URL) string { + r := "" + if (url.Scheme != "" ) != (url.Host != "") { + log.Panicf("url must have both scheme and authority or neither: %s", url.String()) + } + if url.Scheme != "" { + r += url.Scheme + "://" + } + r += url.Host + return r +} + func GetImageProxyOrigin(c *fiber.Ctx) string { url := GetImageProxy(c) - return url.Scheme + "://" + url.Host + return urlAuthority(url) } func GetImageProxyPrefix(c *fiber.Ctx) string { url := GetImageProxy(c) - return url.Scheme + "://" + url.Host + url.Path + return urlAuthority(url) + url.Path // note: not sure if url.EscapedPath() is useful here. go's standard library is trash at handling URL (:// should be part of the scheme) }