koel/app/Helpers.php

68 lines
1.7 KiB
PHP
Raw Normal View History

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
/**
* 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'))
? "http://localhost:8080{$manifest[$file]}"
: static_url($manifest[$file]);
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
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
}
/**
* @see album_cover_url()
*/
2020-09-06 21:20:42 +00:00
function album_thumbnail_url(string $fileName): string
{
2020-06-13 12:19:24 +00:00
return album_cover_url($fileName);
}
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
}