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

51 lines
1.7 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;
2017-04-24 06:38:41 +00:00
use App\Models\Interaction;
2015-12-13 04:42:28 +00:00
use App\Models\Playlist;
use App\Models\Setting;
use App\Models\User;
2016-12-11 13:08:30 +00:00
use iTunes;
2017-05-02 03:23:10 +00:00
use Illuminate\Http\Request;
2016-06-05 04:37:03 +00:00
use Lastfm;
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.
*
2017-05-02 03:23:10 +00:00
* @param Request $request
*
2015-12-13 04:42:28 +00:00
* @return \Illuminate\Http\JsonResponse
*/
2017-05-02 03:23:10 +00:00
public function index(Request $request)
2015-12-13 04:42:28 +00:00
{
$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(MediaCache::get() + [
2017-05-02 03:23:10 +00:00
'settings' => $request->user()->is_admin ? Setting::pluck('value', 'key')->all() : [],
2015-12-13 04:42:28 +00:00
'playlists' => $playlists,
'interactions' => Interaction::byCurrentUser()->get(),
2017-05-02 03:23:10 +00:00
'users' => $request->user()->is_admin ? User::all() : [],
'currentUser' => $request->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'),
'supportsTranscoding' => config('koel.streaming.ffmpeg_path') && is_executable(config('koel.streaming.ffmpeg_path')),
'cdnUrl' => app()->staticUrl(),
2016-12-09 08:23:40 +00:00
'currentVersion' => Application::KOEL_VERSION,
2017-05-02 03:23:10 +00:00
'latestVersion' => $request->user()->is_admin ? app()->getLatestVersion() : Application::KOEL_VERSION,
2015-12-13 04:42:28 +00:00
]);
}
}