koel/app/Http/Controllers/API/DataController.php

48 lines
1.5 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
2015-12-27 14:06:10 +00:00
use App\Application;
2015-12-13 04:42:28 +00:00
use App\Models\Interaction;
use App\Models\Playlist;
use App\Models\Setting;
use App\Models\User;
2016-12-11 13:08:30 +00:00
use iTunes;
2016-06-05 04:37:03 +00:00
use Lastfm;
2017-01-06 03:04:08 +00:00
use MediaCache;
2016-07-30 15:32:17 +00:00
use YouTube;
2015-12-13 04:42:28 +00:00
class DataController extends Controller
{
/**
* Get a set of application data.
*
* @return \Illuminate\Http\JsonResponse
*/
public function index()
{
$playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
// We don't need full song data, just ID's
foreach ($playlists as &$playlist) {
$playlist['songs'] = array_pluck($playlist['songs'], 'id');
}
return response()->json([
2017-01-06 03:04:08 +00:00
'artists' => MediaCache::get(),
2016-09-26 06:30:00 +00:00
'settings' => auth()->user()->is_admin ? Setting::pluck('value', 'key')->all() : [],
2015-12-13 04:42:28 +00:00
'playlists' => $playlists,
'interactions' => Interaction::byCurrentUser()->get(),
'users' => auth()->user()->is_admin ? User::all() : [],
2015-12-20 12:17:35 +00:00
'currentUser' => auth()->user(),
2016-06-05 04:37:03 +00:00
'useLastfm' => Lastfm::used(),
2016-07-30 15:32:17 +00:00
'useYouTube' => YouTube::enabled(),
2016-12-11 13:08:30 +00:00
'useiTunes' => iTunes::used(),
2016-08-21 15:19:03 +00:00
'allowDownload' => config('koel.download.allow'),
'cdnUrl' => app()->staticUrl(),
2016-12-09 08:23:40 +00:00
'currentVersion' => Application::KOEL_VERSION,
'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::KOEL_VERSION,
2015-12-13 04:42:28 +00:00
]);
}
}