Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions app/Actions/InstallUpdate/CheckUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,24 @@ public function getCode(): UpdateStatus
}
// @codeCoverageIgnoreEnd
}

/**
* Return the latest known release version from the remote update feed.
*
* @codeCoverageIgnore
*/
public function getLatestVersion(): ?string
{
return $this->file_version->remote_version?->toString();
}

/**
* Return the current installed file version.
*
* @codeCoverageIgnore
*/
public function getCurrentVersion(): string
{
return $this->file_version->getVersion()->toString();
}
}
29 changes: 29 additions & 0 deletions app/DTO/AdminStatsOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\DTO;

/**
* Immutable value object returned by AdminStatsService.
*/
class AdminStatsOverview
{
public function __construct(
public readonly int $photos_count,
public readonly int $albums_count,
public readonly int $users_count,
public readonly int $storage_bytes,
public readonly int $queued_jobs,
public readonly int $failed_jobs_24h,
public readonly ?string $last_successful_job_at,
public readonly string $cached_at,
/** @var string[] */
public readonly array $errors,
) {
}
}
29 changes: 29 additions & 0 deletions app/Http/Controllers/Admin/AdminDashboardController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Controllers\Admin;

use App\Http\Requests\Admin\AdminStatsRequest;
use App\Http\Resources\Models\AdminStatsResource;
use App\Services\AdminStatsService;
use Illuminate\Routing\Controller;

class AdminDashboardController extends Controller
{
public function __construct(private AdminStatsService $service)
{
}

public function stats(AdminStatsRequest $request): AdminStatsResource
{
$force = $request->boolean('force');
$overview = $this->service->getOverview($force);

return AdminStatsResource::fromOverview($overview);
}
}
40 changes: 40 additions & 0 deletions app/Http/Controllers/Admin/AdminUpdateStatusController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Controllers\Admin;

use App\Actions\InstallUpdate\CheckUpdate;
use App\Assets\Features;
use App\Http\Requests\Admin\AdminUpdateStatusRequest;
use App\Http\Resources\Models\AdminUpdateStatusResource;
use Illuminate\Routing\Controller;

class AdminUpdateStatusController extends Controller
{
public function __construct(private CheckUpdate $check_update)
{
}

/**
* Return update status information for the current installation.
*/
public function show(AdminUpdateStatusRequest $_request): AdminUpdateStatusResource
{
if (Features::inactive('update-check')) {
return AdminUpdateStatusResource::disabled();
}

$update_status = $this->check_update->getCode();

return AdminUpdateStatusResource::fromUpdateStatus(
$update_status,
$this->check_update->getCurrentVersion(),
$this->check_update->getLatestVersion(),
);
}
}
33 changes: 33 additions & 0 deletions app/Http/Requests/Admin/AdminStatsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Requests\Admin;

use App\Http\Requests\BaseApiRequest;
use App\Models\Configs;
use App\Policies\SettingsPolicy;
use Illuminate\Support\Facades\Gate;

class AdminStatsRequest extends BaseApiRequest
{
public function authorize(): bool
{
return Gate::check(SettingsPolicy::CAN_EDIT, [Configs::class]);
}

public function rules(): array
{
return [
'force' => 'sometimes|boolean',
];
}

protected function processValidatedValues(array $values, array $files): void
{
}
}
22 changes: 22 additions & 0 deletions app/Http/Requests/Admin/AdminUpdateStatusRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Requests\Admin;

use App\Http\Requests\AbstractEmptyRequest;
use App\Models\Configs;
use App\Policies\SettingsPolicy;
use Illuminate\Support\Facades\Gate;

class AdminUpdateStatusRequest extends AbstractEmptyRequest
{
public function authorize(): bool
{
return Gate::check(SettingsPolicy::CAN_EDIT, [Configs::class]);
}
}
3 changes: 3 additions & 0 deletions app/Http/Resources/GalleryConfigs/InitConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class InitConfig extends Data
public AlbumHeaderSize $album_header_size;
public bool $is_album_header_landing_title_enabled;

public bool $use_admin_dashboard;

public function __construct()
{
// Debug mode
Expand Down Expand Up @@ -251,6 +253,7 @@ public function __construct()
$this->is_album_enhanced_display_enabled = request()->configs()->getValueAsBool('album_enhanced_display_enabled');
$this->album_header_size = request()->configs()->getValueAsEnum('album_header_size', AlbumHeaderSize::class);
$this->is_album_header_landing_title_enabled = request()->configs()->getValueAsBool('album_header_landing_title_enabled');
$this->use_admin_dashboard = request()->configs()->getValueAsBool('use_admin_dashboard');

$this->set_supporter_properties();
}
Expand Down
44 changes: 44 additions & 0 deletions app/Http/Resources/Models/AdminStatsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Resources\Models;

use App\DTO\AdminStatsOverview;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript()]
class AdminStatsResource extends Data
{
public int $photos_count;
public int $albums_count;
public int $users_count;
public int $storage_bytes;
public int $queued_jobs;
public int $failed_jobs_24h;
public ?string $last_successful_job_at;
public string $cached_at;
/** @var string[] */
public array $errors;

public static function fromOverview(AdminStatsOverview $o): self
{
$resource = new self();
$resource->photos_count = $o->photos_count;
$resource->albums_count = $o->albums_count;
$resource->users_count = $o->users_count;
$resource->storage_bytes = $o->storage_bytes;
$resource->queued_jobs = $o->queued_jobs;
$resource->failed_jobs_24h = $o->failed_jobs_24h;
$resource->last_successful_job_at = $o->last_successful_job_at;
$resource->cached_at = $o->cached_at;
$resource->errors = $o->errors;

return $resource;
}
}
48 changes: 48 additions & 0 deletions app/Http/Resources/Models/AdminUpdateStatusResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Http\Resources\Models;

use App\Enum\UpdateStatus;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

#[TypeScript()]
class AdminUpdateStatusResource extends Data
{
public function __construct(
public bool $enabled,
public ?int $update_status,
public bool $has_update,
public ?string $current_version,
public ?string $latest_version,
) {
}

public static function disabled(): self
{
return new self(
enabled: false,
update_status: null,
has_update: false,
current_version: null,
latest_version: null,
);
}

public static function fromUpdateStatus(UpdateStatus $update_status, string $current_version, string $latest_version): self
{
return new self(
enabled: true,
update_status: $update_status->value,
has_update: $update_status === UpdateStatus::NOT_UP_TO_DATE,
current_version: $current_version,
latest_version: $latest_version,
);
}
}
2 changes: 2 additions & 0 deletions app/Metadata/Cache/RouteCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public function __construct()
'api/v2/Users::count' => new RouteCacheConfig(tag: CacheTag::USERS, user_dependant: true),
'api/v2/Version' => false,
'api/v2/ChangeLogs' => false,
'api/v2/Admin/Stats' => false,
'api/v2/Admin/UpdateStatus' => false,

'api/v2/Import' => new RouteCacheConfig(tag: CacheTag::SETTINGS, user_dependant: true),
'api/v2/Import::browse' => false, // This will return a different result each time depending on the directory requested.
Expand Down
Loading
Loading