koel/app/Http/Controllers/API/DataController.php
2017-04-24 00:01:02 +08:00

53 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\API;
use App\Application;
use App\Models\Interaction;
use App\Models\Artist;
use App\Models\Album;
use App\Models\Song;
use App\Models\Playlist;
use App\Models\Setting;
use App\Models\User;
use iTunes;
use Lastfm;
use MediaCache;
use YouTube;
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([
'artists' => Artist::orderBy('name')->get(),
'songs' => Song::all(),
'albums' => Album::orderBy('name')->get(),
'settings' => auth()->user()->is_admin ? Setting::pluck('value', 'key')->all() : [],
'playlists' => $playlists,
'interactions' => Interaction::byCurrentUser()->get(),
'users' => auth()->user()->is_admin ? User::all() : [],
'currentUser' => auth()->user(),
'useLastfm' => Lastfm::used(),
'useYouTube' => YouTube::enabled(),
'useiTunes' => iTunes::used(),
'allowDownload' => config('koel.download.allow'),
'supportsTranscoding' => config('koel.streaming.ffmpeg_path') && is_executable(config('koel.streaming.ffmpeg_path')),
'cdnUrl' => app()->staticUrl(),
'currentVersion' => Application::KOEL_VERSION,
'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::KOEL_VERSION,
]);
}
}