2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2017-08-05 21:55:43 +00:00
|
|
|
use Cache;
|
2016-04-02 13:16:09 +00:00
|
|
|
use Exception;
|
2015-12-27 14:06:10 +00:00
|
|
|
use GuzzleHttp\Client;
|
2015-12-13 04:42:28 +00:00
|
|
|
use Illuminate\Foundation\Application as IlluminateApplication;
|
|
|
|
use InvalidArgumentException;
|
2015-12-27 14:06:10 +00:00
|
|
|
use Log;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extends \Illuminate\Foundation\Application to override some defaults.
|
|
|
|
*/
|
|
|
|
class Application extends IlluminateApplication
|
|
|
|
{
|
2015-12-28 01:47:32 +00:00
|
|
|
/**
|
|
|
|
* Current Koel version. Must start with a v, and is synced with git tags/releases.
|
|
|
|
*
|
|
|
|
* @link https://github.com/phanan/koel/releases
|
|
|
|
*/
|
2018-01-28 21:24:56 +00:00
|
|
|
const KOEL_VERSION = 'v3.7.2';
|
2015-12-27 14:06:10 +00:00
|
|
|
|
2015-12-13 06:29:32 +00:00
|
|
|
/**
|
|
|
|
* We have merged public path and base path.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function publicPath()
|
|
|
|
{
|
|
|
|
return $this->basePath;
|
|
|
|
}
|
|
|
|
|
2015-12-13 04:42:28 +00:00
|
|
|
/**
|
|
|
|
* Loads a revision'ed asset file, making use of gulp-rev
|
|
|
|
* This is a copycat of L5's Elixir, but catered to our directory structure.
|
|
|
|
*
|
2018-08-24 15:27:19 +00:00
|
|
|
* @throws InvalidArgumentException
|
2015-12-13 04:42:28 +00:00
|
|
|
*/
|
2018-08-24 15:27:19 +00:00
|
|
|
public function rev(string $file, string $manifestFile = null): string
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
|
|
|
static $manifest = null;
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
$manifestFile = $manifestFile ?: public_path('public/mix-manifest.json');
|
2016-01-28 05:35:51 +00:00
|
|
|
|
2016-08-16 15:12:11 +00:00
|
|
|
if ($manifest === null) {
|
2016-01-28 05:35:51 +00:00
|
|
|
$manifest = json_decode(file_get_contents($manifestFile), true);
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($manifest[$file])) {
|
2017-02-14 06:53:02 +00:00
|
|
|
return file_exists(public_path('public/hot'))
|
|
|
|
? "http://localhost:8080{$manifest[$file]}"
|
|
|
|
: $this->staticUrl("public{$manifest[$file]}");
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
|
|
|
|
}
|
2015-12-27 14:06:10 +00:00
|
|
|
|
2016-01-28 05:35:51 +00:00
|
|
|
/**
|
2016-02-09 00:33:21 +00:00
|
|
|
* Get a URL for static file requests.
|
2016-01-28 05:35:51 +00:00
|
|
|
* If this installation of Koel has a CDN_URL configured, use it as the base.
|
2016-03-14 02:36:03 +00:00
|
|
|
* Otherwise, just use a full URL to the asset.
|
2016-01-28 05:35:51 +00:00
|
|
|
*
|
2016-02-03 15:39:15 +00:00
|
|
|
* @param string $name The additional resource name/path.
|
2016-01-28 05:35:51 +00:00
|
|
|
*/
|
2018-08-24 15:27:19 +00:00
|
|
|
public function staticUrl(?string $name = null): string
|
2016-01-28 05:35:51 +00:00
|
|
|
{
|
2016-08-21 15:19:03 +00:00
|
|
|
$cdnUrl = trim(config('koel.cdn.url'), '/ ');
|
2016-03-14 02:36:03 +00:00
|
|
|
|
|
|
|
return $cdnUrl ? $cdnUrl.'/'.trim(ltrim($name, '/')) : trim(asset($name));
|
2016-01-28 05:35:51 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 14:06:10 +00:00
|
|
|
/**
|
2016-08-16 15:12:11 +00:00
|
|
|
* Get the latest version number of Koel from GitHub.
|
2015-12-27 14:06:10 +00:00
|
|
|
*/
|
2018-08-24 15:27:19 +00:00
|
|
|
public function getLatestVersion(Client $client = null): string
|
2015-12-27 14:06:10 +00:00
|
|
|
{
|
2018-08-24 15:27:19 +00:00
|
|
|
return Cache::remember('latestKoelVersion', 1 * 24 * 60, static function () use ($client) {
|
2017-08-05 21:55:43 +00:00
|
|
|
$client = $client ?: new Client();
|
|
|
|
|
|
|
|
try {
|
2018-08-24 15:27:19 +00:00
|
|
|
return json_decode(
|
|
|
|
$client->get('https://api.github.com/repos/phanan/koel/tags')->getBody()
|
2017-08-05 21:55:43 +00:00
|
|
|
)[0]->name;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
Log::error($e);
|
|
|
|
|
|
|
|
return self::KOEL_VERSION;
|
|
|
|
}
|
|
|
|
});
|
2015-12-27 14:06:10 +00:00
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|