This commit is contained in:
2026-07-06 17:06:03 +03:30
parent 0f775d20e8
commit c155d49070
4 changed files with 108 additions and 19 deletions
+25 -6
View File
@@ -111,22 +111,36 @@ class File extends Model
{
$fromSettings = self::baseUrlFromSettings();
if ($fromSettings !== '') {
return $fromSettings;
return self::ensureAbsoluteUrl($fromSettings);
}
$domain = config('app.domain');
if (is_string($domain) && $domain !== '' && ! str_contains($domain, 'localhost')) {
return self::ensureServerPublicBase(rtrim($domain, '/'));
return self::ensureAbsoluteUrl(self::ensureServerPublicBase(rtrim($domain, '/')));
}
$appUrl = config('app.url');
if (is_string($appUrl) && $appUrl !== '' && ! str_contains($appUrl, 'localhost')) {
return self::ensureServerPublicBase(rtrim($appUrl, '/'));
return self::ensureAbsoluteUrl(self::ensureServerPublicBase(rtrim($appUrl, '/')));
}
return '';
}
private static function ensureAbsoluteUrl(string $base): string
{
$base = rtrim(trim($base), '/');
if ($base === '') {
return '';
}
if (! preg_match('/^https?:\/\//i', $base)) {
$base = 'https://'.ltrim($base, '/');
}
return $base;
}
private static function baseUrlFromSettings(): string
{
try {
@@ -137,7 +151,7 @@ class File extends Model
foreach (['server_url', 'bace_url'] as $key) {
$value = trim((string) ($rows[$key] ?? ''));
if ($value !== '' && preg_match('/^https?:\/\//i', $value)) {
if ($value !== '') {
return rtrim($value, '/');
}
}
@@ -148,8 +162,13 @@ class File extends Model
}
$siteUrl = trim((string) ($rows['app_url'] ?? ''));
if ($siteUrl !== '' && preg_match('/^https?:\/\//i', $siteUrl)) {
return rtrim($siteUrl, '/').'/server';
if ($siteUrl !== '') {
$siteUrl = rtrim($siteUrl, '/');
if (! preg_match('#/server$#i', $siteUrl)) {
$siteUrl .= '/server';
}
return $siteUrl;
}
} catch (\Throwable) {
}