fix(s3): serve files using media base url to allow for CDN setup
This commit is contained in:
parent
c5a1359218
commit
502f53c970
|
@ -57,14 +57,7 @@ class FS implements FileManagerInterface
|
|||
|
||||
public function getUrl(string $key): string
|
||||
{
|
||||
$appConfig = config('App');
|
||||
$mediaBaseUrl = $this->config->baseURL === '' ? $appConfig->baseURL : $this->config->baseURL;
|
||||
|
||||
return rtrim((string) $mediaBaseUrl, '/') .
|
||||
'/' .
|
||||
$this->config->root .
|
||||
'/' .
|
||||
$key;
|
||||
return media_url($this->config->root . '/' . $key);
|
||||
}
|
||||
|
||||
public function rename(string $oldKey, string $newKey): bool
|
||||
|
|
|
@ -64,7 +64,7 @@ class S3 implements FileManagerInterface
|
|||
|
||||
public function getUrl(string $key): string
|
||||
{
|
||||
return url_to('media-serve', $key);
|
||||
return media_url((string) route_to('media-serve', $key));
|
||||
}
|
||||
|
||||
public function rename(string $oldKey, string $newKey): bool
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use CodeIgniter\HTTP\URI;
|
||||
use Modules\Media\Config\Media;
|
||||
|
||||
if (! function_exists('media_url')) {
|
||||
/**
|
||||
* Returns a media URL as defined by the Media config.
|
||||
*
|
||||
* @param array|string $relativePath URI string or array of URI segments
|
||||
*/
|
||||
function media_url($relativePath = '', ?string $scheme = null): string
|
||||
{
|
||||
// Convert array of segments to a string
|
||||
if (is_array($relativePath)) {
|
||||
$relativePath = implode('/', $relativePath);
|
||||
}
|
||||
|
||||
$uri = new URI(rtrim((string) config(Media::class)->baseURL, '/') . '/' . ltrim($relativePath));
|
||||
|
||||
return URI::createURIString(
|
||||
$scheme ?? $uri->getScheme(),
|
||||
$uri->getAuthority(),
|
||||
$uri->getPath(),
|
||||
$uri->getQuery(),
|
||||
$uri->getFragment()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue