2020-06-13 12:19:24 +00:00
|
|
|
<?php
|
|
|
|
|
2020-12-22 23:01:49 +00:00
|
|
|
/**
|
|
|
|
* Get a URL for static file requests.
|
|
|
|
* If this installation of Koel has a CDN_URL configured, use it as the base.
|
|
|
|
* Otherwise, just use a full URL to the asset.
|
|
|
|
*
|
|
|
|
* @param string $name The optional resource name/path
|
|
|
|
*/
|
|
|
|
function static_url(?string $name = null): string
|
|
|
|
{
|
|
|
|
$cdnUrl = trim(config('koel.cdn.url'), '/ ');
|
|
|
|
|
|
|
|
return $cdnUrl ? $cdnUrl . '/' . trim(ltrim($name, '/')) : trim(asset($name));
|
|
|
|
}
|
2020-06-13 12:19:24 +00:00
|
|
|
|
2020-12-22 23:12:05 +00:00
|
|
|
/**
|
|
|
|
* A copy of Laravel Mix but catered to our directory structure.
|
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function asset_rev(string $file, ?string $manifestFile = null): string
|
|
|
|
{
|
|
|
|
static $manifest = null;
|
|
|
|
|
|
|
|
$manifestFile = $manifestFile ?: public_path('mix-manifest.json');
|
|
|
|
|
|
|
|
if ($manifest === null) {
|
|
|
|
$manifest = json_decode(file_get_contents($manifestFile), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($manifest[$file])) {
|
|
|
|
return file_exists(public_path('hot'))
|
2021-06-05 10:47:56 +00:00
|
|
|
? "http://localhost:8080$manifest[$file]"
|
2020-12-22 23:12:05 +00:00
|
|
|
: static_url($manifest[$file]);
|
|
|
|
}
|
|
|
|
|
2021-06-05 10:47:56 +00:00
|
|
|
throw new InvalidArgumentException("File $file not defined in asset manifest.");
|
2020-12-22 23:12:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 21:20:42 +00:00
|
|
|
function album_cover_path(string $fileName): string
|
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
return public_path(config('koel.album_cover_dir') . $fileName);
|
2020-06-13 12:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 21:20:42 +00:00
|
|
|
function album_cover_url(string $fileName): string
|
|
|
|
{
|
2020-12-22 23:01:49 +00:00
|
|
|
return static_url(config('koel.album_cover_dir') . $fileName);
|
2020-06-13 12:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 21:20:42 +00:00
|
|
|
function artist_image_path(string $fileName): string
|
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
return public_path(config('koel.artist_image_dir') . $fileName);
|
2020-06-13 12:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 21:20:42 +00:00
|
|
|
function artist_image_url(string $fileName): string
|
|
|
|
{
|
2020-12-22 23:01:49 +00:00
|
|
|
return static_url(config('koel.artist_image_dir') . $fileName);
|
2020-06-13 12:19:24 +00:00
|
|
|
}
|
2021-01-10 22:17:37 +00:00
|
|
|
|
|
|
|
function koel_version(): string
|
|
|
|
{
|
|
|
|
return trim(file_get_contents(base_path('.version')));
|
|
|
|
}
|