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;
|
2018-08-30 05:37:03 +00:00
|
|
|
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;
|
2018-08-30 05:37:03 +00:00
|
|
|
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,
|
2018-08-30 05:37:03 +00:00
|
|
|
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;
|
2018-08-30 05:37:03 +00:00
|
|
|
$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'),
|
2017-12-09 18:34:27 +00:00
|
|
|
'supportsTranscoding' => config('koel.streaming.ffmpeg_path')
|
|
|
|
&& is_executable(config('koel.streaming.ffmpeg_path')),
|
2016-01-28 05:35:51 +00:00
|
|
|
'cdnUrl' => app()->staticUrl(),
|
2016-12-09 08:23:40 +00:00
|
|
|
'currentVersion' => Application::KOEL_VERSION,
|
2018-08-30 05:37:03 +00:00
|
|
|
'latestVersion' => $request->user()->is_admin
|
|
|
|
? $this->applicationInformationService->getLatestVersionNumber()
|
|
|
|
: Application::KOEL_VERSION,
|
2015-12-13 04:42:28 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|