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

63 lines
2.1 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;
2018-08-19 14:40:25 +00:00
use App\Services\iTunesService;
use App\Services\LastfmService;
2018-08-19 14:56:56 +00:00
use App\Services\MediaCacheService;
2018-08-19 14:40:25 +00:00
use App\Services\YouTubeService;
2017-06-04 01:30:45 +00:00
use Illuminate\Http\JsonResponse;
2017-05-02 03:23:10 +00:00
use Illuminate\Http\Request;
2015-12-13 04:42:28 +00:00
class DataController extends Controller
{
2018-08-19 14:40:25 +00:00
private $lastfmService;
private $youTubeService;
private $iTunesService;
2018-08-19 14:56:56 +00:00
private $mediaCacheService;
2018-08-19 14:40:25 +00:00
public function __construct(
LastfmService $lastfmService,
YouTubeService $youTubeService,
2018-08-19 14:56:56 +00:00
iTunesService $iTunesService,
MediaCacheService $mediaCacheService
2018-08-19 15:26:52 +00:00
) {
2018-08-19 14:40:25 +00:00
$this->lastfmService = $lastfmService;
$this->youTubeService = $youTubeService;
$this->iTunesService = $iTunesService;
2018-08-19 14:56:56 +00:00
$this->mediaCacheService = $mediaCacheService;
2018-08-19 14:40:25 +00:00
}
2015-12-13 04:42:28 +00:00
/**
* Get a set of application data.
*
2017-05-02 03:23:10 +00:00
* @param Request $request
*
2017-06-04 01:30:45 +00:00
* @return JsonResponse
2015-12-13 04:42:28 +00:00
*/
2017-05-02 03:23:10 +00:00
public function index(Request $request)
2015-12-13 04:42:28 +00:00
{
2018-08-19 14:56:56 +00:00
return response()->json($this->mediaCacheService->get() + [
2017-05-02 03:23:10 +00:00
'settings' => $request->user()->is_admin ? Setting::pluck('value', 'key')->all() : [],
'playlists' => Playlist::byCurrentUser()->orderBy('name')->get()->toArray(),
2015-12-13 04:42:28 +00:00
'interactions' => Interaction::byCurrentUser()->get(),
2017-05-02 03:23:10 +00:00
'users' => $request->user()->is_admin ? User::all() : [],
'currentUser' => $request->user(),
2018-08-19 14:40:25 +00:00
'useLastfm' => $this->lastfmService->used(),
'useYouTube' => $this->youTubeService->enabled(),
'useiTunes' => $this->iTunesService->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
]);
}
}