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;
|
2024-01-01 11:40:21 +00:00
|
|
|
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;
|
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;
|
2024-01-08 16:59:05 +00:00
|
|
|
use App\Services\LicenseService;
|
2024-01-01 11:40:21 +00:00
|
|
|
use App\Services\QueueService;
|
2023-12-27 11:49:28 +00:00
|
|
|
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
|
|
|
|
2024-01-02 12:07:37 +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 */
|
2024-01-02 12:07:37 +00:00
|
|
|
public function __invoke(
|
|
|
|
ITunesService $iTunesService,
|
|
|
|
SettingRepository $settingRepository,
|
|
|
|
SongRepository $songRepository,
|
|
|
|
ApplicationInformationService $applicationInformationService,
|
|
|
|
QueueService $queueService,
|
2024-01-08 16:59:05 +00:00
|
|
|
LicenseService $licenseService,
|
2024-01-02 12:07:37 +00:00
|
|
|
?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([
|
2024-01-02 12:07:37 +00:00
|
|
|
'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')
|
2017-12-09 18:34:27 +00:00
|
|
|
&& is_executable(config('koel.streaming.ffmpeg_path')),
|
2023-06-05 21:46:41 +00:00
|
|
|
'cdn_url' => static_url(),
|
|
|
|
'current_version' => koel_version(),
|
2024-01-02 12:07:37 +00:00
|
|
|
'latest_version' => $user->is_admin
|
|
|
|
? $applicationInformationService->getLatestVersionNumber()
|
2021-01-10 22:17:37 +00:00
|
|
|
: koel_version(),
|
2024-01-02 12:07:37 +00:00
|
|
|
'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
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|