Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from AzuraCast:main #121

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ protected function viewRecord(object $record, ServerRequest $request): object
{
$original = parent::viewRecord($record, $request);

$return = new ApiStorageLocation();
$return->fromParentObject($original);

$return = ApiStorageLocation::fromParent($original);
$return->storageQuotaBytes = (string)($record->getStorageQuotaBytes() ?? '');
$return->storageUsedBytes = (string)$record->getStorageUsedBytes();
$return->storageUsedPercent = $record->getStorageUsePercentage();
Expand Down
25 changes: 21 additions & 4 deletions backend/src/Controller/Api/Admin/Updates/GetUpdatesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,33 @@

use App\Container\SettingsAwareTrait;
use App\Controller\SingleActionInterface;
use App\Entity\Api\Admin\UpdateDetails;
use App\Http\Response;
use App\Http\ServerRequest;
use App\OpenApi;
use App\Service\AzuraCastCentral;
use GuzzleHttp\Exception\TransferException;
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;

/*
* TODO API
*/
#[OA\Get(
path: '/admin/updates',
operationId: 'getUpdateStatus',
description: 'Show information about this installation and its update status.',
tags: ['Administration: General'],
responses: [
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(
ref: UpdateDetails::class
)
),
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
new OA\Response(ref: OpenApi::REF_RESPONSE_GENERIC_ERROR, response: 500),
]
)]
final class GetUpdatesAction implements SingleActionInterface
{
use SettingsAwareTrait;
Expand All @@ -40,7 +57,7 @@ public function __invoke(
$settings->updateUpdateLastRun();
$this->writeSettings($settings);

return $response->withJson($updates);
return $response->withJson(UpdateDetails::fromParent($updates));
}

throw new RuntimeException('Error parsing update data response from AzuraCast central.');
Expand Down
16 changes: 13 additions & 3 deletions backend/src/Controller/Api/Admin/Updates/PutUpdatesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
use App\Entity\Api\Status;
use App\Http\Response;
use App\Http\ServerRequest;
use App\OpenApi;
use App\Service\WebUpdater;
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;

/*
* TODO API
*/
#[OA\Put(
path: '/admin/updates',
operationId: 'putWebUpdate',
description: 'Attempts to trigger a web-based update.',
tags: ['Administration: General'],
responses: [
new OA\Response(ref: OpenApi::REF_RESPONSE_SUCCESS, response: 200),
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
new OA\Response(ref: OpenApi::REF_RESPONSE_GENERIC_ERROR, response: 500),
]
)]
final class PutUpdatesAction implements SingleActionInterface
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,34 @@

use App\CallableEventDispatcherInterface;
use App\Controller\SingleActionInterface;
use App\Entity\Api\Notification;
use App\Event;
use App\Http\Response;
use App\Http\ServerRequest;
use App\OpenApi;
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;

/*
* TODO API
*/
#[OA\Get(
path: '/dashboard/notifications',
operationId: 'getNotifications',
description: 'Show all notifications your current account should see.',
tags: ['Miscellaneous'],
responses: [
new OA\Response(
response: 200,
description: 'Success',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(
ref: Notification::class
)
)
),
new OA\Response(ref: OpenApi::REF_RESPONSE_ACCESS_DENIED, response: 403),
new OA\Response(ref: OpenApi::REF_RESPONSE_GENERIC_ERROR, response: 500),
]
)]
final class NotificationsAction implements SingleActionInterface
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ static function (Station $station) use ($acl) {

$paginator->setPostprocessor(
function (NowPlaying $np) use ($router, $listenersEnabled, $acl) {
$row = new Dashboard();
$row->fromParentObject($np);

$row = Dashboard::fromParent($np);
$row->links = [
'public' => $router->named('public:index', ['station_id' => $np->station->shortcode]),
'manage' => $router->named('stations:index:index', ['station_id' => $np->station->id]),
Expand Down
4 changes: 1 addition & 3 deletions backend/src/Controller/Api/Stations/QueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ protected function viewRecord(object $record, ServerRequest $request): StationQu

$row = $this->queueApiGenerator->__invoke($record);

$apiResponse = new StationQueueDetailed();
$apiResponse->fromParentObject($row);

$apiResponse = StationQueueDetailed::fromParent($row);
$apiResponse->sent_to_autodj = $record->getSentToAutodj();
$apiResponse->is_played = $record->getIsPlayed();
$apiResponse->autodj_custom_uri = $record->getAutodjCustomUri();
Expand Down
3 changes: 1 addition & 2 deletions backend/src/Controller/Api/Stations/RemotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ protected function viewRecord(object $record, ServerRequest $request): ApiStatio
{
$returnArray = $this->toArray($record);

$return = new ApiStationRemote();
$return->fromParentObject($returnArray);
$return = ApiStationRemote::fromParent($returnArray);

$isInternal = $request->isInternal();
$router = $request->getRouter();
Expand Down
47 changes: 47 additions & 0 deletions backend/src/Entity/Api/Admin/UpdateDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace App\Entity\Api\Admin;

use App\Traits\LoadFromParentObject;
use OpenApi\Attributes as OA;

#[OA\Schema(
schema: 'Api_Admin_UpdateDetails',
type: 'object'
)]
final readonly class UpdateDetails
{
use LoadFromParentObject;

public function __construct(
#[OA\Property(
description: 'The stable-equivalent branch your installation currently appears to be on.',
example: '0.20.3'
)]
public string $current_release,
#[OA\Property(
description: 'The current latest stable release of the software.',
example: '0.20.4'
)]
public string $latest_release,
#[OA\Property(
description: 'If you are on the Rolling Release, whether your installation needs to be updated.',
)]
public bool $needs_rolling_update = false,
#[OA\Property(
description: 'Whether a newer stable release is available than the version you are currently using.',
)]
public bool $needs_release_update = false,
#[OA\Property(
description: 'If you are on the Rolling Release, the number of updates released since your version.',
)]
public int $rolling_updates_available = 0,
#[OA\Property(
description: 'Whether you can seamlessly move from the Rolling Release channel to Stable without issues.',
)]
public bool $can_switch_to_stable = false
) {
}
}
32 changes: 22 additions & 10 deletions backend/src/Entity/Api/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@

namespace App\Entity\Api;

final class Notification
{
public string $title;

public string $body;

public string $type;
use App\Enums\FlashLevels;
use OpenApi\Attributes as OA;

public ?string $actionLabel;

public ?string $actionUrl;
#[OA\Schema(
schema: 'Api_Notification',
required: ['*'],
type: 'object'
)]
final readonly class Notification
{
public function __construct(
#[OA\Property]
public string $title,
#[OA\Property]
public string $body,
#[OA\Property]
public FlashLevels $type,
#[OA\Property]
public ?string $actionLabel = null,
#[OA\Property]
public ?string $actionUrl = null
) {
}
}
3 changes: 1 addition & 2 deletions backend/src/Entity/ApiGenerator/NowPlayingApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public function __invoke(
isNowPlaying: true
);

$apiCurrentSong = new CurrentSong();
$apiCurrentSong->fromParentObject($apiSongHistory);
$apiCurrentSong = CurrentSong::fromParent($apiSongHistory);
$np->now_playing = $apiCurrentSong;

$np->song_history = $this->songHistoryApiGenerator->fromArray(
Expand Down
3 changes: 1 addition & 2 deletions backend/src/Entity/ApiGenerator/SongHistoryApiGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public function detailed(
?UriInterface $baseUri = null
): DetailedSongHistory {
$apiHistory = ($this)($record, $baseUri);
$response = new DetailedSongHistory();
$response->fromParentObject($apiHistory);
$response = DetailedSongHistory::fromParent($apiHistory);
$response->listeners_start = (int)$record->getListenersStart();
$response->listeners_end = (int)$record->getListenersEnd();
$response->delta_total = $record->getDeltaTotal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

declare(strict_types=1);

namespace App\Session;
namespace App\Enums;

use OpenApi\Attributes as OA;

#[OA\Schema(type: 'string')]
enum FlashLevels: string
{
case Success = 'success';
Expand Down
1 change: 1 addition & 0 deletions backend/src/Event/GetNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

final class GetNotifications extends Event
{
/** @var Notification[] */
private array $notifications = [];

public function __construct(
Expand Down
25 changes: 13 additions & 12 deletions backend/src/Notification/Check/BaseUrlCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use App\Container\SettingsAwareTrait;
use App\Entity\Api\Notification;
use App\Enums\FlashLevels;
use App\Enums\GlobalPermissions;
use App\Event\GetNotifications;
use App\Session\FlashLevels;

final class BaseUrlCheck
{
Expand Down Expand Up @@ -47,18 +47,19 @@ public function __invoke(GetNotifications $event): void
);
// phpcs:enable Generic.Files.LineLength

$notification = new Notification();
$notification->title = sprintf(
__('Your "Base URL" setting (%s) does not match the URL you are currently using (%s).'),
(string)$baseUriWithoutRequest,
(string)$baseUriWithRequest
$event->addNotification(
new Notification(
sprintf(
__('Your "Base URL" setting (%s) does not match the URL you are currently using (%s).'),
(string)$baseUriWithoutRequest,
(string)$baseUriWithRequest
),
implode(' ', $notificationBodyParts),
FlashLevels::Warning,
__('System Settings'),
$router->named('admin:settings:index')
)
);
$notification->body = implode(' ', $notificationBodyParts);
$notification->type = FlashLevels::Warning->value;
$notification->actionLabel = __('System Settings');
$notification->actionUrl = $router->named('admin:settings:index');

$event->addNotification($notification);
}
}
}
24 changes: 12 additions & 12 deletions backend/src/Notification/Check/DonateAdvisorCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use App\Container\EnvironmentAwareTrait;
use App\Entity\Api\Notification;
use App\Enums\FlashLevels;
use App\Event\GetNotifications;
use App\Exception\Http\RateLimitExceededException;
use App\Session\FlashLevels;

final class DonateAdvisorCheck
{
Expand All @@ -29,17 +29,17 @@ public function __invoke(GetNotifications $event): void
return;
}

$notification = new Notification();
$notification->title = __('AzuraCast is free and open-source software.');
$notification->body = __(
'If you are enjoying AzuraCast, please consider donating to support our work. We depend ' .
'on donations to build new features, fix bugs, and keep AzuraCast modern, accessible and free.',
$event->addNotification(
new Notification(
__('AzuraCast is free and open-source software.'),
__(
'If you are enjoying AzuraCast, please consider donating to support our work. We depend ' .
'on donations to build new features, fix bugs, and keep AzuraCast modern, accessible and free.',
),
FlashLevels::Info,
__('Donate to AzuraCast'),
'https://donate.azuracast.com/'
)
);
$notification->type = FlashLevels::Info->value;

$notification->actionLabel = __('Donate to AzuraCast');
$notification->actionUrl = 'https://donate.azuracast.com/';

$event->addNotification($notification);
}
}
Loading