mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
i dont know
This commit is contained in:
@@ -10,7 +10,7 @@ class ImageDownloader
|
||||
private Client $httpClient;
|
||||
private string $basePath;
|
||||
|
||||
public function __construct(string $basePath = 'public/images', ?string $apiKey = null)
|
||||
public function __construct(string $basePath = 'storage/images', ?string $apiKey = null)
|
||||
{
|
||||
$headers = [
|
||||
'User-Agent' => 'MediaCollector/1.0'
|
||||
@@ -25,7 +25,13 @@ class ImageDownloader
|
||||
'headers' => $headers,
|
||||
'verify' => false // Disable SSL verification for problematic servers
|
||||
]);
|
||||
$this->basePath = rtrim($basePath, '/');
|
||||
|
||||
// Convert relative path to absolute path
|
||||
if (strpos($basePath, '/') !== 0) {
|
||||
$this->basePath = __DIR__ . '/../' . $basePath;
|
||||
} else {
|
||||
$this->basePath = $basePath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,6 +121,8 @@ class ImageDownloader
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // Not a valid image type
|
||||
}
|
||||
|
||||
public function saveImage(string $imageData, string $filename, string $subfolder = ''): ?string
|
||||
@@ -167,9 +175,9 @@ class ImageDownloader
|
||||
return null;
|
||||
}
|
||||
|
||||
// Remove the public/ prefix to get the web-accessible path
|
||||
// Remove the absolute basePath prefix to get the relative path
|
||||
$relativePath = str_replace($this->basePath . '/', '', $localPath);
|
||||
|
||||
return '/' . $relativePath;
|
||||
return '/images/' . $relativePath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user