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;
|
2018-08-30 05:37:03 +00:00
|
|
|
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
|
|
|
|
{
|
2018-10-20 21:46:12 +00:00
|
|
|
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,
|
2018-08-30 05:37:03 +00:00
|
|
|
UserRepository $userRepository,
|
2020-09-13 22:04:07 +00:00
|
|
|
ApplicationInformationService $applicationInformationService,
|
2021-10-11 14:23:00 +00:00
|
|
|
?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;
|
2018-08-30 05:37:03 +00:00
|
|
|
$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(),
|
2018-10-20 21:46:12 +00:00
|
|
|
'recentlyPlayed' => $this->interactionRepository->getRecentlyPlayed(
|
2020-09-13 22:04:07 +00:00
|
|
|
$this->currentUser,
|
2018-10-20 21:46:12 +00:00
|
|
|
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'),
|
2017-12-09 18:34:27 +00:00
|
|
|
'supportsTranscoding' => config('koel.streaming.ffmpeg_path')
|
|
|
|
&& is_executable(config('koel.streaming.ffmpeg_path')),
|
2020-12-22 23:01:49 +00:00
|
|
|
'cdnUrl' => static_url(),
|
2021-01-10 22:17:37 +00:00
|
|
|
'currentVersion' => koel_version(),
|
2020-09-13 22:04:07 +00:00
|
|
|
'latestVersion' => $this->currentUser->is_admin
|
2018-08-30 05:37:03 +00:00
|
|
|
? $this->applicationInformationService->getLatestVersionNumber()
|
2021-01-10 22:17:37 +00:00
|
|
|
: koel_version(),
|
2015-12-13 04:42:28 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|