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

84 lines
3.4 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
2020-09-13 22:04:07 +00:00
use App\Models\User;
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;
2020-12-22 20:11:22 +00:00
use App\Services\ITunesService;
2018-08-19 14:40:25 +00:00
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;
2020-09-13 22:04:07 +00:00
use Illuminate\Contracts\Auth\Authenticatable;
2015-12-13 04:42:28 +00:00
class DataController extends Controller
{
private const RECENTLY_PLAYED_EXCERPT_COUNT = 7;
2021-06-05 10:47:56 +00:00
private LastfmService $lastfmService;
private YouTubeService $youTubeService;
private ITunesService $iTunesService;
private MediaCacheService $mediaCacheService;
private SettingRepository $settingRepository;
private PlaylistRepository $playlistRepository;
private InteractionRepository $interactionRepository;
private UserRepository $userRepository;
private ApplicationInformationService $applicationInformationService;
2018-08-19 14:40:25 +00:00
2020-09-13 22:04:07 +00:00
/** @var User */
2021-06-05 10:47:56 +00:00
private ?Authenticatable $currentUser;
2020-09-13 22:04:07 +00:00
2018-08-19 14:40:25 +00:00
public function __construct(
LastfmService $lastfmService,
YouTubeService $youTubeService,
2020-12-22 20:11:22 +00:00
ITunesService $iTunesService,
2018-08-29 06:15:11 +00:00
MediaCacheService $mediaCacheService,
SettingRepository $settingRepository,
PlaylistRepository $playlistRepository,
InteractionRepository $interactionRepository,
UserRepository $userRepository,
2020-09-13 22:04:07 +00:00
ApplicationInformationService $applicationInformationService,
Authenticatable $currentUser
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;
2020-09-13 22:04:07 +00:00
$this->currentUser = $currentUser;
2018-08-19 14:40:25 +00:00
}
2020-09-13 22:04:07 +00:00
public function index()
2015-12-13 04:42:28 +00:00
{
2018-08-19 14:56:56 +00:00
return response()->json($this->mediaCacheService->get() + [
2020-09-13 22:04:07 +00:00
'settings' => $this->currentUser->is_admin ? $this->settingRepository->getAllAsKeyValueArray() : [],
2018-08-29 06:15:11 +00:00
'playlists' => $this->playlistRepository->getAllByCurrentUser(),
'interactions' => $this->interactionRepository->getAllByCurrentUser(),
'recentlyPlayed' => $this->interactionRepository->getRecentlyPlayed(
2020-09-13 22:04:07 +00:00
$this->currentUser,
self::RECENTLY_PLAYED_EXCERPT_COUNT
),
2020-09-13 22:04:07 +00:00
'users' => $this->currentUser->is_admin ? $this->userRepository->getAll() : [],
'currentUser' => $this->currentUser,
2018-08-19 14:40:25 +00:00
'useLastfm' => $this->lastfmService->used(),
'useYouTube' => $this->youTubeService->enabled(),
'useiTunes' => $this->iTunesService->used(),
2020-09-06 21:20:42 +00:00
'allowDownload' => config('koel.download.allow'),
'supportsTranscoding' => config('koel.streaming.ffmpeg_path')
&& is_executable(config('koel.streaming.ffmpeg_path')),
2020-12-22 23:01:49 +00:00
'cdnUrl' => static_url(),
'currentVersion' => koel_version(),
2020-09-13 22:04:07 +00:00
'latestVersion' => $this->currentUser->is_admin
? $this->applicationInformationService->getLatestVersionNumber()
: koel_version(),
2015-12-13 04:42:28 +00:00
]);
}
}