[#7] finally made the online proxy to work

This commit is contained in:
2025-03-30 23:33:26 +03:00
parent d8194a7c8f
commit 5ef903b195
+35
View File
@@ -176,6 +176,31 @@ class ProxyService
return $this->processCssContent($content, $baseUrl); return $this->processCssContent($content, $baseUrl);
} }
// Process stylesheet links that don't start with http or https
$content = preg_replace_callback(
'/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\'](?!https?:\/\/)([^"\']+)["\']/i',
function($matches) use ($baseUrl) {
$url = $matches[1];
// If the URL starts with /, use the host from baseUrl
if (strpos($url, '/') === 0) {
$parsedUrl = parse_url($baseUrl);
$url = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $url;
} else {
// Otherwise, append to the base URL
$url = rtrim($baseUrl, '/') . '/' . ltrim($url, '/');
}
// Log the transformation
\Log::info('Stylesheet URL transformed', [
'original' => $matches[0],
'transformed' => $url
]);
return str_replace($matches[1], $url, $matches[0]);
},
$content
);
// For HTML content, process only anchor tags with external URLs // For HTML content, process only anchor tags with external URLs
$patterns = [ $patterns = [
// External links in href attributes (only for anchor tags) // External links in href attributes (only for anchor tags)
@@ -192,6 +217,16 @@ class ProxyService
if (strpos($url, route('proxy.browse')) === 0) { if (strpos($url, route('proxy.browse')) === 0) {
return $matches[0]; return $matches[0];
} }
// Skip URLs that are already proxied
if (strpos($url, route('proxy.browse')) === 0) {
return $matches[0];
}
// Proxy all http/https URLs
if (preg_match('/^https?:\/\//i', $url)) {
$url = route('proxy.browse') . '?url=' . base64_encode($url);
return $matches[1] . '="' . htmlspecialchars($url) . '"';
}
// Only proxy external URLs // Only proxy external URLs
if (strpos($url, 'http') === 0 && strpos($url, parse_url($baseUrl, PHP_URL_HOST)) === false) { if (strpos($url, 'http') === 0 && strpos($url, parse_url($baseUrl, PHP_URL_HOST)) === false) {