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

67 lines
2.8 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;
2024-01-08 16:59:05 +00:00
use App\Services\LicenseService;
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,
2024-01-08 16:59:05 +00:00
LicenseService $licenseService,
?Authenticatable $user
2018-08-19 15:26:52 +00:00
) {
2024-01-08 16:59:05 +00:00
$licenseStatus = $licenseService->getStatus();
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),
2024-01-04 11:35:36 +00:00
'uses_last_fm' => LastfmService::used(),
'uses_spotify' => SpotifyService::enabled(),
'uses_you_tube' => YouTubeService::enabled(),
'uses_i_tunes' => $iTunesService->used(),
'allows_download' => config('koel.download.allow'),
'media_path_set' => (bool) $settingRepository->getByKey('media_path'),
2023-06-05 21:46:41 +00:00
'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)),
2024-01-08 16:59:05 +00:00
'koel_plus' => [
'active' => $licenseStatus->isValid(),
'short_key' => $licenseStatus->license?->short_key,
'customer_name' => $licenseStatus->license?->meta->customerName,
'customer_email' => $licenseStatus->license?->meta->customerEmail,
'store_url' => config('lemonsqueezy.store_url'),
],
2015-12-13 04:42:28 +00:00
]);
}
}