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

55 lines
2.2 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Http\Controllers\API;
2022-07-29 06:47:10 +00:00
use App\Http\Controllers\Controller;
2023-06-05 21:46:41 +00:00
use App\Http\Resources\PlaylistFolderResource;
use App\Http\Resources\PlaylistResource;
use App\Http\Resources\QueueStateResource;
2023-06-05 21:46:41 +00:00
use App\Http\Resources\UserResource;
2020-09-13 22:04:07 +00:00
use App\Models\User;
2018-08-29 06:15:11 +00:00
use App\Repositories\SettingRepository;
2023-06-05 21:46:41 +00:00
use App\Repositories\SongRepository;
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;
use App\Services\QueueService;
use App\Services\SpotifyService;
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 FetchInitialDataController extends Controller
2015-12-13 04:42:28 +00:00
{
2023-06-05 21:46:41 +00:00
/** @param User $user */
public function __invoke(
ITunesService $iTunesService,
SettingRepository $settingRepository,
SongRepository $songRepository,
ApplicationInformationService $applicationInformationService,
QueueService $queueService,
?Authenticatable $user
2018-08-19 15:26:52 +00:00
) {
2023-06-05 21:46:41 +00:00
return response()->json([
'settings' => $user->is_admin ? $settingRepository->getAllAsKeyValueArray() : [],
'playlists' => PlaylistResource::collection($user->playlists),
'playlist_folders' => PlaylistFolderResource::collection($user->playlist_folders),
'current_user' => UserResource::make($user, true),
2023-06-05 21:46:41 +00:00
'use_last_fm' => LastfmService::used(),
'use_spotify' => SpotifyService::enabled(),
2023-06-05 21:46:41 +00:00
'use_you_tube' => YouTubeService::enabled(),
'use_i_tunes' => $iTunesService->used(),
2023-06-05 21:46:41 +00:00
'allow_download' => config('koel.download.allow'),
'supports_transcoding' => config('koel.streaming.ffmpeg_path')
&& is_executable(config('koel.streaming.ffmpeg_path')),
2023-06-05 21:46:41 +00:00
'cdn_url' => static_url(),
'current_version' => koel_version(),
'latest_version' => $user->is_admin
? $applicationInformationService->getLatestVersionNumber()
: koel_version(),
'song_count' => $songRepository->count(),
'song_length' => $songRepository->getTotalLength(),
'queue_state' => QueueStateResource::make($queueService->getQueueState($user)),
2015-12-13 04:42:28 +00:00
]);
}
}