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

79 lines
3 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;
2018-08-29 06:15:11 +00:00
use App\Repositories\InteractionRepository;
use App\Repositories\PlaylistRepository;
use App\Repositories\SettingRepository;
use App\Repositories\UserRepository;
use App\Services\ApplicationInformationService;
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-29 06:15:11 +00:00
private $settingRepository;
private $playlistRepository;
private $interactionRepository;
private $userRepository;
private $applicationInformationService;
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,
2018-08-29 06:15:11 +00:00
MediaCacheService $mediaCacheService,
SettingRepository $settingRepository,
PlaylistRepository $playlistRepository,
InteractionRepository $interactionRepository,
UserRepository $userRepository,
ApplicationInformationService $applicationInformationService
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-29 06:15:11 +00:00
$this->settingRepository = $settingRepository;
$this->playlistRepository = $playlistRepository;
$this->interactionRepository = $interactionRepository;
$this->userRepository = $userRepository;
$this->applicationInformationService = $applicationInformationService;
2018-08-19 14:40:25 +00:00
}
2015-12-13 04:42:28 +00:00
/**
* Get a set of application data.
*
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() + [
2018-08-29 06:15:11 +00:00
'settings' => $request->user()->is_admin ? $this->settingRepository->getAllAsKeyValueArray() : [],
'playlists' => $this->playlistRepository->getAllByCurrentUser(),
'interactions' => $this->interactionRepository->getAllByCurrentUser(),
'users' => $request->user()->is_admin ? $this->userRepository->getAll() : [],
2017-05-02 03:23:10 +00:00
'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,
'latestVersion' => $request->user()->is_admin
? $this->applicationInformationService->getLatestVersionNumber()
: Application::KOEL_VERSION,
2015-12-13 04:42:28 +00:00
]);
}
}