move env variables to config (#415)

This commit is contained in:
bdgold 2016-08-21 11:19:03 -04:00 committed by Phan An
parent aaaa3e1a4e
commit 27933d49cf
13 changed files with 129 additions and 28 deletions

View file

@ -70,7 +70,7 @@ class Application extends IlluminateApplication
*/
public function staticUrl($name = null)
{
$cdnUrl = trim(env('CDN_URL'), '/ ');
$cdnUrl = trim(config('koel.cdn.url'), '/ ');
return $cdnUrl ? $cdnUrl.'/'.trim(ltrim($name, '/')) : trim(asset($name));
}

View file

@ -44,14 +44,14 @@ class Init extends Command
$this->comment('Remember, you can always install/upgrade manually following the guide here:');
$this->info('📙 https://github.com/phanan/koel/wiki'.PHP_EOL);
if (!env('APP_KEY')) {
if (!config('app.key')) {
$this->info('Generating app key');
Artisan::call('key:generate');
} else {
$this->comment('App key exists -- skipping');
}
if (!env('JWT_SECRET')) {
if (!config('jwt.secret')) {
$this->info('Generating JWT secret');
Artisan::call('koel:generate-jwt-secret');
} else {

View file

@ -36,7 +36,7 @@ class DataController extends Controller
'currentUser' => auth()->user(),
'useLastfm' => Lastfm::used(),
'useYouTube' => YouTube::enabled(),
'allowDownload' => env('ALLOW_DOWNLOAD', true),
'allowDownload' => config('koel.download.allow'),
'cdnUrl' => app()->staticUrl(),
'currentVersion' => Application::VERSION,
'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION,

View file

@ -42,11 +42,11 @@ class SongController extends Controller
if ($transcode) {
$streamer = new TranscodingStreamer(
$song,
$bitRate ?: env('OUTPUT_BIT_RATE', 128),
$bitRate ?: config('koel.streaming.bitrate'),
request()->input('time', 0)
);
} else {
switch (env('STREAMING_METHOD')) {
switch (config('koel.streming.method')) {
case 'x-sendfile':
$streamer = new XSendFileStreamer($song);
break;

View file

@ -13,7 +13,7 @@ class Request extends BaseRequest
*/
public function authorize()
{
return env('ALLOW_DOWNLOAD', true);
return config('koel.download.allow');
}
public function rules()

View file

@ -32,7 +32,7 @@ class TranscodingStreamer extends Streamer implements StreamerInterface
*/
public function stream()
{
$ffmpeg = env('FFMPEG_PATH', '/usr/local/bin/ffmpeg');
$ffmpeg = config('koel.streaming.transcoding');
abort_unless(is_executable($ffmpeg), 500, 'Transcoding requires valid ffmpeg settings.');
$bitRate = filter_var($this->bitRate, FILTER_SANITIZE_NUMBER_INT);

View file

@ -33,8 +33,8 @@ class Lastfm extends RESTfulService
public function __construct($key = null, $secret = null, Client $client = null)
{
parent::__construct(
$key ?: env('LASTFM_API_KEY'),
$secret ?: env('LASTFM_API_SECRET'),
$key ?: config('koel.lastfm.key'),
$secret ?: config('koel.lastfm.secret'),
'https://ws.audioscrobbler.com/2.0',
$client ?: new Client()
);
@ -47,7 +47,7 @@ class Lastfm extends RESTfulService
*/
public function used()
{
return env('LASTFM_API_KEY') && env('LASTFM_API_SECRET');
return config('koel.lastfm.key') && config('koel.lastfm.secret');
}
/**

View file

@ -58,7 +58,7 @@ class Media
public function sync($path = null, $tags = [], $force = false, SyncMedia $syncCommand = null)
{
if (!app()->runningInConsole()) {
set_time_limit(env('APP_MAX_SCAN_TIME', 600));
set_time_limit(config('koel.sync.timeout'));
}
$path = $path ?: Setting::get('media_path');

View file

@ -17,7 +17,7 @@ class YouTube extends RESTfulService
public function __construct($key = null, Client $client = null)
{
parent::__construct(
$key ?: env('YOUTUBE_API_KEY'),
$key ?: config('koel.youtube.key'),
null,
'https://www.googleapis.com/youtube/v3',
$client ?: new Client()
@ -31,7 +31,7 @@ class YouTube extends RESTfulService
*/
public function enabled()
{
return (bool) env('YOUTUBE_API_KEY');
return (bool) config('koel.youtube.key');
}
/**

View file

@ -146,9 +146,7 @@ return [
|
*/
'auth' => function ($app) {
return new Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter($app['auth']);
},
'auth' => 'Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter',
/*
|--------------------------------------------------------------------------
@ -159,9 +157,7 @@ return [
|
*/
'storage' => function ($app) {
return new Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter($app['cache']);
},
'storage' => 'Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter',
],

103
config/koel.php Normal file
View file

@ -0,0 +1,103 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Admin Credentials
|--------------------------------------------------------------------------
|
| When running `php artisan koel:init` the admin is set using the .env
|
*/
'admin' => [
'name' => env('ADMIN_NAME'),
'email' => env('ADMIN_EMAIL'),
'password' => env('ADMIN_PASSWORD'),
],
/*
|--------------------------------------------------------------------------
| Sync Options
|--------------------------------------------------------------------------
|
| A timeout is set when using the browser to scan the folder path
|
*/
'sync' => [
'timeout' => env('APP_MAX_SCAN_TIME', 600),
],
/*
|--------------------------------------------------------------------------
| Streaming Configurations
|--------------------------------------------------------------------------
|
| Many streaming options can be set, including, 'bitrate' with 128 set
| as the default, 'method' with php as the default and 'transcoding'
| to configure the path for FFMPEG to transcode FLAC audio files
|
*/
'streaming' => [
'bitrate' => env('OUTPUT_BIT_RATE', 128),
'method' => env('STREAMING_METHOD'),
'transcoding' => env('FFMPEG_PATH', '/usr/local/bin/ffmpeg'),
],
/*
|--------------------------------------------------------------------------
| Youtube Integration
|--------------------------------------------------------------------------
|
| Youtube integration requires an youtube API key, see wiki for more
|
*/
'youtube' => [
'key' => env('YOUTUBE_API_KEY'),
],
/*
|--------------------------------------------------------------------------
| Last.FM Integration
|--------------------------------------------------------------------------
|
| See wiki on how to integrate with Last.FM
|
*/
'lastfm' => [
'key' => env('LASTFM_API_KEY'),
'secret' => env('LASTFM_API_SECRET'),
],
/*
|--------------------------------------------------------------------------
| CDN
|--------------------------------------------------------------------------
|
|
|
*/
'cdn' => [
'url' => env('CDN_URL'),
],
/*
|--------------------------------------------------------------------------
| Downloading Music
|--------------------------------------------------------------------------
|
| Koel provides the ability to prohibit or allow [default] downloading music
|
*/
'download' => [
'allow' => env('ALLOW_DOWNLOAD', true),
],
];

View file

@ -10,15 +10,17 @@ class UserTableSeeder extends Seeder
*/
public function run()
{
if (!env('ADMIN_NAME') || !env('ADMIN_EMAIL') || !env('ADMIN_PASSWORD')) {
if (!config('koel.admin.name') ||
!config('koel.admin.email') ||
!config('koel.admin.password')) {
$this->command->error('Please fill in initial admin details in .env file first.');
abort(422);
}
User::create([
'name' => env('ADMIN_NAME'),
'email' => env('ADMIN_EMAIL'),
'password' => Hash::make(env('ADMIN_PASSWORD')),
'name' => config('koel.admin.name'),
'email' => config('koel.admin.email'),
'password' => Hash::make(config('koel.admin.password')),
'is_admin' => true,
]);

View file

@ -9,7 +9,7 @@ class ApplicationTest extends TestCase
{
public function testStaticUrlWithoutCDN()
{
putenv('CDN_URL');
config(['koel.cdn.url' => '']);
$this->assertEquals(App::staticUrl(), 'http://localhost/');
$this->assertEquals(App::staticUrl('foo.css '), 'http://localhost/foo.css');
@ -17,7 +17,7 @@ class ApplicationTest extends TestCase
public function testStaticUrlWithCDN()
{
putenv('CDN_URL=http://cdn.bar');
config(['koel.cdn.url' => 'http://cdn.bar']);
$this->assertEquals(App::staticUrl(), 'http://cdn.bar/');
$this->assertEquals(App::staticUrl('foo.css '), 'http://cdn.bar/foo.css');
@ -25,12 +25,12 @@ class ApplicationTest extends TestCase
public function testRev()
{
putenv('CDN_URL');
config(['koel.cdn.url' => '']);
$manifestFile = dirname(__FILE__).'/blobs/rev-manifest.json';
$this->assertEquals(App::rev('foo.css', $manifestFile), 'http://localhost/public/build/foo00.css');
putenv('CDN_URL=http://cdn.bar');
config(['koel.cdn.url' => 'http://cdn.bar']);
$this->assertEquals(App::rev('bar.js', $manifestFile), 'http://cdn.bar/public/build/bar00.js');
}