diff --git a/bridges/PixivBridge.php b/bridges/PixivBridge.php index 55e00984..b8f7e36b 100644 --- a/bridges/PixivBridge.php +++ b/bridges/PixivBridge.php @@ -224,6 +224,6 @@ class PixivBridge extends BridgeAbstract file_put_contents($path, $illust); } - return 'cache/pixiv_img/' . preg_replace('/.*\//', '', $path); + return get_home_page_url() . 'cache/pixiv_img/' . preg_replace('/.*\//', '', $path); } } diff --git a/lib/utils.php b/lib/utils.php index 312591f4..a411d2aa 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -18,6 +18,21 @@ final class Json } } +/** + * Returns e.g. 'https://example.com/' or 'https://example.com/bridge/' + */ +function get_home_page_url(): string +{ + $https = $_SERVER['HTTPS'] ?? null; + $host = $_SERVER['HTTP_HOST'] ?? null; + $uri = $_SERVER['REQUEST_URI'] ?? null; + if (($pos = strpos($uri, '?')) !== false) { + $uri = substr($uri, 0, $pos); + } + $scheme = $https === 'on' ? 'https' : 'http'; + return "$scheme://$host$uri"; +} + function create_sane_stacktrace(\Throwable $e): array { $frames = array_reverse($e->getTrace());