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

44 lines
1.4 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\Artist;
use App\Models\Interaction;
use App\Models\Playlist;
use App\Models\Setting;
use App\Models\User;
2016-06-05 04:37:03 +00:00
use Lastfm;
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([
'artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(),
2015-12-29 01:22:38 +00:00
'settings' => Setting::lists('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(),
'allowDownload' => env('ALLOW_DOWNLOAD', true),
'cdnUrl' => app()->staticUrl(),
2015-12-27 14:06:10 +00:00
'currentVersion' => Application::VERSION,
'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION,
2015-12-13 04:42:28 +00:00
]);
}
}