mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-03 21:05:45 -05:00
implement ability to set icon for extensions
This commit is contained in:
@@ -34,7 +34,11 @@ class DoctorCommand extends Command
|
||||
}
|
||||
|
||||
foreach ($icons->unknownIcons($manifest) as $icon) {
|
||||
$this->components->warn("Navigation icon \"{$icon}\" is not a lucide icon this panel ships; the default icon is shown instead.");
|
||||
$this->components->warn("Icon \"{$icon}\" is not a lucide icon this panel ships; the default icon is shown instead.");
|
||||
}
|
||||
|
||||
if (($problem = $assets->iconProblem($manifest)) !== null) {
|
||||
$this->components->warn($problem.' The extension list shows its initials instead.');
|
||||
}
|
||||
|
||||
$this->components->info("{$manifest->id} v{$manifest->version}: manifest, compatibility, autoload directories, and build passed.");
|
||||
|
||||
@@ -50,6 +50,11 @@ class PackCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$icon = $manifest->iconFile();
|
||||
if ($icon !== null && is_file($manifest->path($icon)) && $zip->locateName($icon) === false) {
|
||||
throw_unless($zip->addFile($manifest->path($icon), $icon), InvalidExtensionException::class, "Unable to add {$icon} to archive.");
|
||||
}
|
||||
|
||||
throw_unless($zip->close(), InvalidExtensionException::class, 'Unable to finish archive.');
|
||||
$opened = false;
|
||||
throw_unless(File::move($temporary, $output), InvalidExtensionException::class, 'Unable to save archive.');
|
||||
|
||||
@@ -941,9 +941,10 @@ class PterodactylOpenApiGenerator extends OpenApiGenerator
|
||||
*/
|
||||
private function normalizeRawResponseMediaTypes(array &$pathItem, OutputEndpointData $endpoint): void
|
||||
{
|
||||
if (($pathItem['operationId'] ?? null) !== 'adminExportEgg'
|
||||
&& preg_match('#^api/admin/eggs/\{[^}]+\}/export$#', $endpoint->uri) !== 1
|
||||
) {
|
||||
$isEggExport = ($pathItem['operationId'] ?? null) === 'adminExportEgg'
|
||||
|| preg_match('#^api/admin/eggs/\{[^}]+\}/export$#', $endpoint->uri) === 1;
|
||||
$isExtensionIcon = preg_match('#^api/admin/extensions/\{[^}]+\}/icon$#', $endpoint->uri) === 1;
|
||||
if (! $isEggExport && ! $isExtensionIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -952,7 +953,23 @@ class PterodactylOpenApiGenerator extends OpenApiGenerator
|
||||
}
|
||||
|
||||
foreach ($pathItem['responses'] as $status => &$response) {
|
||||
if (! str_starts_with($this->arrayKeyString($status), '2') || ! isset($response['content']['application/json'])) {
|
||||
if (! str_starts_with($this->arrayKeyString($status), '2')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isExtensionIcon) {
|
||||
$response['content'] = array_fill_keys(['image/png', 'image/jpeg', 'image/webp'], [
|
||||
'schema' => [
|
||||
'type' => 'string',
|
||||
'format' => 'binary',
|
||||
'description' => 'Icon image bytes.',
|
||||
],
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isset($response['content']['application/json'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ use Pterodactyl\Services\Extensions\ExtensionSettingsRegistry;
|
||||
#[ResponseField('provider', nullable: true)]
|
||||
#[ResponseField('ui_entry', nullable: true)]
|
||||
#[ResponseField('frontend_entry', nullable: true)]
|
||||
#[ResponseField('icon', nullable: true)]
|
||||
#[ResponseField('icon_url', nullable: true)]
|
||||
class ExtensionController extends AdminApiController
|
||||
{
|
||||
private const array EXTENSION_EXAMPLE = [
|
||||
@@ -50,6 +52,8 @@ class ExtensionController extends AdminApiController
|
||||
'description' => 'Example extension',
|
||||
'author' => 'Pterodactyl',
|
||||
'provider' => 'ExampleExtension\\Provider',
|
||||
'icon' => 'puzzle',
|
||||
'icon_url' => null,
|
||||
'has_ui' => true,
|
||||
'ui_entry' => 'dist/client.js',
|
||||
'ui_mode' => 'native',
|
||||
@@ -101,6 +105,22 @@ class ExtensionController extends AdminApiController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Endpoint('Get extension icon', 'Returns the PNG, JPEG or WebP image an extension declares as its "icon". Extensions with a lucide icon name or no icon return not found.')]
|
||||
#[ScribeResponse('', description: 'Icon image returned.')]
|
||||
public function icon(GetExtensionsRequest $request, ExtensionRepository $extensions, ExtensionAssetPublisher $assets, string $extension): Response
|
||||
{
|
||||
$manifest = $extensions->discovered()->get($extension);
|
||||
$icon = $manifest instanceof ExtensionManifest ? $assets->icon($manifest) : null;
|
||||
abort_if($icon === null, Response::HTTP_NOT_FOUND, "Extension \"{$extension}\" has no image icon.");
|
||||
|
||||
return new Response($icon['contents'], Response::HTTP_OK, [
|
||||
'Content-Type' => $icon['mime'],
|
||||
'Cache-Control' => 'private, max-age=31536000, immutable',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
'Content-Security-Policy' => "default-src 'none'; sandbox",
|
||||
]);
|
||||
}
|
||||
|
||||
#[Endpoint('Install extension', 'Installs an uploaded .pteroext or .zip extension package.')]
|
||||
#[BodyParam('package', 'file', 'Extension archive to install.', required: true)]
|
||||
#[BodyParam('enable', 'boolean', 'Enable the extension after installing it.', required: false, example: false)]
|
||||
@@ -238,6 +258,8 @@ class ExtensionController extends AdminApiController
|
||||
'description' => null,
|
||||
'author' => null,
|
||||
'provider' => null,
|
||||
'icon' => null,
|
||||
'icon_url' => null,
|
||||
'has_ui' => false,
|
||||
'ui_entry' => null,
|
||||
'ui_mode' => null,
|
||||
@@ -278,6 +300,8 @@ class ExtensionController extends AdminApiController
|
||||
'description' => $manifest->description,
|
||||
'author' => $manifest->author,
|
||||
'provider' => $manifest->provider,
|
||||
'icon' => $manifest->iconName(),
|
||||
'icon_url' => $assets->iconUrl($manifest),
|
||||
'has_ui' => $manifest->hasUi(),
|
||||
'ui_entry' => $manifest->uiEntry,
|
||||
'ui_mode' => $manifest->uiMode,
|
||||
|
||||
@@ -13,8 +13,56 @@ use Throwable;
|
||||
|
||||
class ExtensionAssetPublisher
|
||||
{
|
||||
public const int ICON_MAX_KILOBYTES = 512;
|
||||
|
||||
public const int ICON_MAX_DIMENSION = 2048;
|
||||
|
||||
private const array ICON_TYPES = ['image/png', 'image/jpeg', 'image/webp'];
|
||||
|
||||
public function __construct(private readonly ExtensionStylesheetInspector $stylesheets) {}
|
||||
|
||||
public function iconUrl(ExtensionManifest $manifest): ?string
|
||||
{
|
||||
$icon = $this->icon($manifest);
|
||||
|
||||
return $icon === null ? null : sprintf('/api/admin/extensions/%s/icon?v=%s', $manifest->id, hash('xxh3', $icon['contents']));
|
||||
}
|
||||
|
||||
/** @return array{contents: string, mime: string}|null */
|
||||
public function icon(ExtensionManifest $manifest): ?array
|
||||
{
|
||||
$path = $this->iconPath($manifest);
|
||||
if ($path === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$contents = File::get($path);
|
||||
$size = @getimagesizefromstring($contents);
|
||||
if ($size === false || ! in_array($size['mime'], self::ICON_TYPES, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($size[0] < 1 || $size[1] < 1 || $size[0] > self::ICON_MAX_DIMENSION || $size[1] > self::ICON_MAX_DIMENSION) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['contents' => $contents, 'mime' => $size['mime']];
|
||||
}
|
||||
|
||||
public function iconProblem(ExtensionManifest $manifest): ?string
|
||||
{
|
||||
$file = $manifest->iconFile();
|
||||
if ($file === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$this->iconPath($manifest) === null => sprintf('Icon "%s" is missing, outside the package or larger than %d KB.', $file, self::ICON_MAX_KILOBYTES),
|
||||
$this->icon($manifest) === null => sprintf('Icon "%s" is not a readable PNG, JPEG or WebP image of at most %d px per side.', $file, self::ICON_MAX_DIMENSION),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function entryUrl(ExtensionManifest $manifest): string
|
||||
{
|
||||
$version = $this->currentVersion($manifest->id);
|
||||
@@ -192,6 +240,24 @@ class ExtensionAssetPublisher
|
||||
return glob($this->publishedPath($identifier).DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR) ?: [];
|
||||
}
|
||||
|
||||
private function iconPath(ExtensionManifest $manifest): ?string
|
||||
{
|
||||
$file = $manifest->iconFile();
|
||||
if ($file === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$root = realpath($manifest->directory);
|
||||
$path = realpath($manifest->path(...explode('/', $file)));
|
||||
if ($root === false || $path === false || ! str_starts_with($path, $root.DIRECTORY_SEPARATOR) || ! is_file($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$bytes = filesize($path);
|
||||
|
||||
return $bytes !== false && $bytes > 0 && $bytes <= self::ICON_MAX_KILOBYTES * 1024 ? $path : null;
|
||||
}
|
||||
|
||||
private function developmentPath(string $identifier): string
|
||||
{
|
||||
return $this->publishedPath($identifier).DIRECTORY_SEPARATOR.'_development';
|
||||
|
||||
@@ -17,13 +17,13 @@ final class ExtensionIconCatalog
|
||||
public const string PATH = 'packages/sdk/icons.json';
|
||||
|
||||
/**
|
||||
* The navigation icons a manifest declares that this panel does not ship.
|
||||
* The icons a manifest declares that this panel does not ship.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function unknownIcons(ExtensionManifest $manifest): array
|
||||
{
|
||||
$declared = [];
|
||||
$declared = array_filter([$manifest->iconName()]);
|
||||
foreach ($manifest->screens as $screen) {
|
||||
if (isset($screen['nav']['icon'])) {
|
||||
$declared[] = $screen['nav']['icon'];
|
||||
|
||||
@@ -26,6 +26,8 @@ class ExtensionManifest
|
||||
/** A lucide icon name (kebab-case), such as "life-buoy" or "grid-2x2". */
|
||||
public const string ICON_REGEX = '/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/D';
|
||||
|
||||
public const string ICON_FILE_REGEX = '/^(?:[A-Za-z0-9_-][A-Za-z0-9_.-]*\/)*[A-Za-z0-9_-][A-Za-z0-9_.-]*\.(?:png|jpe?g|webp)$/D';
|
||||
|
||||
/** Identifiers that would collide with core routes/assets. */
|
||||
public const array RESERVED_IDS = ['pterodactyl', 'panel', 'core'];
|
||||
|
||||
@@ -100,6 +102,7 @@ class ExtensionManifest
|
||||
public readonly array $rootPrefixes = [],
|
||||
/** The Tailwind prefix this extension builds its utilities and theme variables with. */
|
||||
public readonly ?string $uiPrefix = null,
|
||||
public readonly ?string $icon = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -131,6 +134,7 @@ class ExtensionManifest
|
||||
requiredExtensions: $data['requires']['extensions'] ?? [],
|
||||
rootPrefixes: $data['routes']['root'] ?? [],
|
||||
uiPrefix: $data['ui']['prefix'] ?? null,
|
||||
icon: is_string($data['icon'] ?? null) ? $data['icon'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -179,6 +183,16 @@ class ExtensionManifest
|
||||
return $this->uiEntry !== null;
|
||||
}
|
||||
|
||||
public function iconName(): ?string
|
||||
{
|
||||
return $this->icon !== null && preg_match(self::ICON_REGEX, $this->icon) === 1 ? $this->icon : null;
|
||||
}
|
||||
|
||||
public function iconFile(): ?string
|
||||
{
|
||||
return $this->icon !== null && preg_match(self::ICON_FILE_REGEX, $this->icon) === 1 ? $this->icon : null;
|
||||
}
|
||||
|
||||
public function path(string ...$parts): string
|
||||
{
|
||||
return $this->directory.($parts === [] ? '' : DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts));
|
||||
|
||||
@@ -77,6 +77,9 @@ class ExtensionManifestValidator
|
||||
$provider = $data['provider'] ?? null;
|
||||
throw_if($provider !== null && $provider === '', InvalidExtensionException::class, 'Manifest "provider" must be a class name string.');
|
||||
|
||||
$icon = $data['icon'] ?? null;
|
||||
throw_if($icon !== null && preg_match(ExtensionManifest::ICON_REGEX, $icon) !== 1 && preg_match(ExtensionManifest::ICON_FILE_REGEX, $icon) !== 1, InvalidExtensionException::class, 'Manifest "icon" must be a lucide icon name such as "life-buoy", or the relative path of a .png, .jpg or .webp image inside the package.');
|
||||
|
||||
return ExtensionManifest::fromValidatedData(
|
||||
directory: $directory,
|
||||
data: $data,
|
||||
@@ -101,6 +104,7 @@ class ExtensionManifestValidator
|
||||
'description' => ['nullable', 'string'],
|
||||
'author' => ['nullable', 'string'],
|
||||
'provider' => ['nullable', 'string'],
|
||||
'icon' => ['nullable', 'string', 'max:255'],
|
||||
'autoload' => ['sometimes', 'array'],
|
||||
'requires' => ['sometimes', 'array:panel,sdk,php,extensions'],
|
||||
'requires.panel' => ['sometimes', 'string', 'max:255'],
|
||||
@@ -152,6 +156,8 @@ class ExtensionManifestValidator
|
||||
'version.string' => 'Manifest field "version" is required and must be a string.',
|
||||
'version.max' => 'Manifest field "version" must not be longer than 64 characters.',
|
||||
'provider.string' => 'Manifest "provider" must be a class name string.',
|
||||
'icon.string' => 'Manifest "icon" must be a lucide icon name or an image path string.',
|
||||
'icon.max' => 'Manifest "icon" must not be longer than 255 characters.',
|
||||
'autoload.array' => 'Manifest "autoload" must map "Vendor\\\\Prefix\\\\" to a source directory.',
|
||||
'ui.array' => 'Manifest "ui" must be an object with an "entry" path.',
|
||||
'ui.entry.required_with' => 'Manifest "ui" must be an object with an "entry" path.',
|
||||
|
||||
@@ -222,6 +222,18 @@ picker. Common names render immediately; the rest of the set is one lazily fetch
|
||||
shared by every extension. Keep importing icons you reference in code from
|
||||
`lucide-react` and pass them to `<Icon icon={…} />`.
|
||||
|
||||
The top-level `icon` is shown for the extension on the admin extensions page, in place of
|
||||
its initials. It is either a lucide icon name, as above, or the path of a PNG, JPEG or
|
||||
WebP image inside the package, such as `"icon": "icon.png"`. Images may be at most 512 KB
|
||||
and 2048 px per side, and a square image of 128 px or more looks best. The image does
|
||||
not have to sit in `dist`: it is served to administrators from the package itself, so it
|
||||
shows while the extension is disabled, and `p:extension:pack` adds it to the archive.
|
||||
`p:extension:doctor` warns about an image that is missing or unreadable.
|
||||
|
||||
```json
|
||||
{ "id": "mods", "name": "Mods", "version": "1.0.0", "icon": "icon.png" }
|
||||
```
|
||||
|
||||
## Author tooling and configuration
|
||||
|
||||
Use `p:extension:doctor <path>`, `p:extension:dev <path> --watch`, and
|
||||
|
||||
@@ -43,6 +43,22 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"icon": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
],
|
||||
"maxLength": 255,
|
||||
"anyOf": [
|
||||
{
|
||||
"pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
|
||||
},
|
||||
{
|
||||
"pattern": "^(?:[A-Za-z0-9_-][A-Za-z0-9_.-]*/)*[A-Za-z0-9_-][A-Za-z0-9_.-]*\\.(?:png|jpe?g|webp)$"
|
||||
}
|
||||
],
|
||||
"description": "Shown on the admin extensions page. A lucide icon name (https://lucide.dev/icons) such as life-buoy, or the path of a PNG, JPEG or WebP image inside the package such as icon.png (at most 512 KB and 2048 px per side). Without one the extension's initials are shown."
|
||||
},
|
||||
"provider": {
|
||||
"type": [
|
||||
"string",
|
||||
|
||||
+54
@@ -3319,6 +3319,8 @@ export type AdminListExtensionsResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3341,6 +3343,8 @@ export type AdminInstallExtensionResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3357,6 +3361,18 @@ export type AdminGetExtensionSettingsResponseBody = {
|
||||
schema: Array<AdminExtensionSettingField>;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Icon image bytes.
|
||||
*/
|
||||
export type AdminGetExtensionIcon200ImagePngResponseBody = Blob | File;
|
||||
/**
|
||||
* Icon image bytes.
|
||||
*/
|
||||
export type AdminGetExtensionIcon200ImageJpegResponseBody = Blob | File;
|
||||
/**
|
||||
* Icon image bytes.
|
||||
*/
|
||||
export type AdminGetExtensionIcon200ImageWebpResponseBody = Blob | File;
|
||||
export type AdminUpdateExtensionSettingsResponseBody = {
|
||||
data: {
|
||||
registered: boolean;
|
||||
@@ -3383,6 +3399,8 @@ export type AdminEnableExtensionResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3401,6 +3419,8 @@ export type AdminDisableExtensionResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3603,6 +3623,7 @@ export type AdminListActivityPerPageQueryParameter = number;
|
||||
*/
|
||||
export type AdminListActivityIncludeQueryParameter = string;
|
||||
export type AdminGetExtensionSettingsExtensionPathParameter = string;
|
||||
export type AdminGetExtensionIconExtensionPathParameter = string;
|
||||
export type AdminUpdateExtensionSettingsExtensionIdPathParameter = string;
|
||||
export type AdminUploadExtensionSettingFileExtensionPathParameter = string;
|
||||
export type AdminUploadExtensionSettingFileInputPathParameter = string;
|
||||
@@ -4710,6 +4731,39 @@ export type AdminGetExtensionSettingsResponses = {
|
||||
200: AdminGetExtensionSettingsResponseBody;
|
||||
};
|
||||
export type AdminGetExtensionSettingsResponse = AdminGetExtensionSettingsResponses[keyof AdminGetExtensionSettingsResponses];
|
||||
export type AdminGetExtensionIconData = {
|
||||
body?: never;
|
||||
path: {
|
||||
/**
|
||||
* The extension identifier.
|
||||
*/
|
||||
extension: AdminGetExtensionIconExtensionPathParameter;
|
||||
};
|
||||
query?: never;
|
||||
url: '/api/admin/extensions/{extension}/icon';
|
||||
};
|
||||
export type AdminGetExtensionIconErrors = {
|
||||
/**
|
||||
* Authentication credentials were missing or invalid.
|
||||
*/
|
||||
401: ErrorEnvelope;
|
||||
/**
|
||||
* The API key does not have permission to perform this action.
|
||||
*/
|
||||
403: ErrorEnvelope;
|
||||
/**
|
||||
* The requested resource could not be found.
|
||||
*/
|
||||
404: ErrorEnvelope;
|
||||
};
|
||||
export type AdminGetExtensionIconError = AdminGetExtensionIconErrors[keyof AdminGetExtensionIconErrors];
|
||||
export type AdminGetExtensionIconResponses = {
|
||||
/**
|
||||
* Icon image returned.
|
||||
*/
|
||||
200: AdminGetExtensionIcon200ImagePngResponseBody;
|
||||
};
|
||||
export type AdminGetExtensionIconResponse = AdminGetExtensionIconResponses[keyof AdminGetExtensionIconResponses];
|
||||
export type AdminUpdateExtensionSettingsData = {
|
||||
body: AdminUpdateExtensionSettingsRequest;
|
||||
path: {
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ parameters:
|
||||
ExtensionScreenMatcher: 'array{any?: list<string>, all?: list<string>}'
|
||||
ExtensionScreenCondition: 'array{eggFeatures?: ExtensionScreenMatcher, eggTags?: ExtensionScreenMatcher, match?: string, runtime?: bool}'
|
||||
ExtensionScreenDefinition: 'array{id: string, area: string, path: string, parent?: string, nav?: array{label: string, exact?: bool, params?: array<string, string>, order?: int, group?: string, badge?: string, icon?: string}, permission?: list<string>, when?: ExtensionScreenCondition}'
|
||||
ExtensionManifestInput: 'array{id: string, name: string, version: string, requires?: array{panel?: string, sdk?: string, php?: string, extensions?: array<string, string>}, description?: string|null, author?: string|null, provider?: string|null, autoload?: array<array-key, ApiValue9>, ui?: array{entry: string, mode?: string, prefix?: string, screens?: list<ExtensionScreenDefinition>, components?: list<string>}, routes?: array{root?: list<string>}, ...<string, ApiValue10>}'
|
||||
ExtensionManifestInput: 'array{id: string, name: string, version: string, requires?: array{panel?: string, sdk?: string, php?: string, extensions?: array<string, string>}, description?: string|null, author?: string|null, provider?: string|null, icon?: string|null, autoload?: array<array-key, ApiValue9>, ui?: array{entry: string, mode?: string, prefix?: string, screens?: list<ExtensionScreenDefinition>, components?: list<string>}, routes?: array{root?: list<string>}, ...<string, ApiValue10>}'
|
||||
paths:
|
||||
- app
|
||||
ignoreErrors:
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -3568,6 +3568,8 @@ export type AdminListExtensionsResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3591,6 +3593,8 @@ export type AdminInstallExtensionResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3609,6 +3613,21 @@ export type AdminGetExtensionSettingsResponseBody = {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Icon image bytes.
|
||||
*/
|
||||
export type AdminGetExtensionIcon200ImagePngResponseBody = Blob | File;
|
||||
|
||||
/**
|
||||
* Icon image bytes.
|
||||
*/
|
||||
export type AdminGetExtensionIcon200ImageJpegResponseBody = Blob | File;
|
||||
|
||||
/**
|
||||
* Icon image bytes.
|
||||
*/
|
||||
export type AdminGetExtensionIcon200ImageWebpResponseBody = Blob | File;
|
||||
|
||||
export type AdminUpdateExtensionSettingsResponseBody = {
|
||||
data: {
|
||||
registered: boolean;
|
||||
@@ -3638,6 +3657,8 @@ export type AdminEnableExtensionResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3657,6 +3678,8 @@ export type AdminDisableExtensionResponseBody = {
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
provider: string | null;
|
||||
icon: string | null;
|
||||
icon_url: string | null;
|
||||
has_ui?: boolean;
|
||||
ui_entry: string | null;
|
||||
ui_mode?: string;
|
||||
@@ -3880,6 +3903,8 @@ export type AdminListActivityIncludeQueryParameter = string;
|
||||
|
||||
export type AdminGetExtensionSettingsExtensionPathParameter = string;
|
||||
|
||||
export type AdminGetExtensionIconExtensionPathParameter = string;
|
||||
|
||||
export type AdminUpdateExtensionSettingsExtensionIdPathParameter = string;
|
||||
|
||||
export type AdminUploadExtensionSettingFileExtensionPathParameter = string;
|
||||
@@ -5370,6 +5395,44 @@ export type AdminGetExtensionSettingsResponses = {
|
||||
|
||||
export type AdminGetExtensionSettingsResponse = AdminGetExtensionSettingsResponses[keyof AdminGetExtensionSettingsResponses];
|
||||
|
||||
export type AdminGetExtensionIconData = {
|
||||
body?: never;
|
||||
path: {
|
||||
/**
|
||||
* The extension identifier.
|
||||
*/
|
||||
extension: AdminGetExtensionIconExtensionPathParameter;
|
||||
};
|
||||
query?: never;
|
||||
url: '/api/admin/extensions/{extension}/icon';
|
||||
};
|
||||
|
||||
export type AdminGetExtensionIconErrors = {
|
||||
/**
|
||||
* Authentication credentials were missing or invalid.
|
||||
*/
|
||||
401: ErrorEnvelope;
|
||||
/**
|
||||
* The API key does not have permission to perform this action.
|
||||
*/
|
||||
403: ErrorEnvelope;
|
||||
/**
|
||||
* The requested resource could not be found.
|
||||
*/
|
||||
404: ErrorEnvelope;
|
||||
};
|
||||
|
||||
export type AdminGetExtensionIconError = AdminGetExtensionIconErrors[keyof AdminGetExtensionIconErrors];
|
||||
|
||||
export type AdminGetExtensionIconResponses = {
|
||||
/**
|
||||
* Icon image returned.
|
||||
*/
|
||||
200: AdminGetExtensionIcon200ImagePngResponseBody;
|
||||
};
|
||||
|
||||
export type AdminGetExtensionIconResponse = AdminGetExtensionIconResponses[keyof AdminGetExtensionIconResponses];
|
||||
|
||||
export type AdminUpdateExtensionSettingsData = {
|
||||
body: AdminUpdateExtensionSettingsRequest;
|
||||
path: {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { AxiosError, type AxiosResponse, type InternalAxiosRequestConfig } from 'axios';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import http from '@/api/http';
|
||||
import { adminExtensionsQueryOptions } from '@/api/admin/extensions/queries';
|
||||
import ExtensionsContainer from '@/components/admin/extensions/ExtensionsContainer';
|
||||
import { adminExtensionsQueryOptions, type AdminExtension } from '@/api/admin/extensions/queries';
|
||||
import ExtensionsContainer, { ExtensionMark } from '@/components/admin/extensions/ExtensionsContainer';
|
||||
|
||||
const mocks = vi.hoisted(() => ({ notifyError: vi.fn(), toastSuccess: vi.fn() }));
|
||||
|
||||
@@ -137,3 +137,49 @@ describe('extension install dialog', () => {
|
||||
expect(within(dialog).getByRole('button', { name: 'Install' })).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
const extension = (overrides: Partial<AdminExtension>): AdminExtension =>
|
||||
({ id: 'server-tools', name: 'Server Tools', icon: null, icon_url: null, ...overrides }) as AdminExtension;
|
||||
|
||||
describe('extension mark', () => {
|
||||
afterEach(cleanup);
|
||||
|
||||
it('shows the image icon and falls back to the lucide icon, then the initials, when it fails to load', async () => {
|
||||
const { container, rerender } = render(
|
||||
<ExtensionMark
|
||||
extension={extension({ icon: 'puzzle', icon_url: '/api/admin/extensions/server-tools/icon?v=1' })}
|
||||
/>
|
||||
);
|
||||
|
||||
const image = container.querySelector('img');
|
||||
expect(image).toHaveAttribute('src', '/api/admin/extensions/server-tools/icon?v=1');
|
||||
expect(image).toHaveAttribute('alt', '');
|
||||
|
||||
fireEvent.error(image as HTMLImageElement);
|
||||
await waitFor(() => expect(container.querySelector('svg')?.getAttribute('class')).toContain('lucide-puzzle'));
|
||||
expect(container.querySelector('img')).toBeNull();
|
||||
|
||||
rerender(<ExtensionMark extension={extension({ icon_url: '/api/admin/extensions/server-tools/icon?v=1' })} />);
|
||||
expect(container.querySelector('img')).toBeNull();
|
||||
expect(container).toHaveTextContent('ST');
|
||||
|
||||
rerender(<ExtensionMark extension={extension({ icon_url: '/api/admin/extensions/server-tools/icon?v=2' })} />);
|
||||
expect(container.querySelector('img')).toHaveAttribute('src', '/api/admin/extensions/server-tools/icon?v=2');
|
||||
});
|
||||
|
||||
it('shows a lucide icon by name', async () => {
|
||||
const { container } = render(<ExtensionMark extension={extension({ icon: 'life-buoy' })} />);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(container.querySelector('svg')?.getAttribute('class')).toContain('lucide-life-buoy')
|
||||
);
|
||||
expect(container).not.toHaveTextContent('ST');
|
||||
});
|
||||
|
||||
it('shows the initials without an icon', () => {
|
||||
const { container } = render(<ExtensionMark extension={extension({})} />);
|
||||
|
||||
expect(container.querySelector('img, svg')).toBeNull();
|
||||
expect(container).toHaveTextContent('ST');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ import AdminContentBlock from '@/components/admin/AdminContentBlock';
|
||||
import Button from '@/components/elements/Button';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
import Label from '@/components/elements/Label';
|
||||
import NamedIcon from '@/components/elements/NamedIcon';
|
||||
import ListToolbar from '@/components/elements/ListToolbar';
|
||||
import { NewButton } from '@/components/elements/NewButton';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
@@ -91,15 +92,39 @@ const extensionInitials = (extension: AdminExtension): string =>
|
||||
.map((part) => part[0]?.toUpperCase() ?? '')
|
||||
.join('') || 'EX';
|
||||
|
||||
function ExtensionMark({ extension }: { extension: AdminExtension }) {
|
||||
function ExtensionMarkContent({ extension }: { extension: AdminExtension }) {
|
||||
const [failedUrl, setFailedUrl] = useState<string | null>(null);
|
||||
const iconUrl = extension.icon_url;
|
||||
|
||||
if (iconUrl && iconUrl !== failedUrl) {
|
||||
return (
|
||||
<img
|
||||
src={iconUrl}
|
||||
alt={''}
|
||||
loading={'lazy'}
|
||||
decoding={'async'}
|
||||
className={'h-full w-full object-contain'}
|
||||
onError={() => setFailedUrl(iconUrl)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (extension.icon) {
|
||||
return <NamedIcon name={extension.icon} size={20} />;
|
||||
}
|
||||
|
||||
return <>{extensionInitials(extension)}</>;
|
||||
}
|
||||
|
||||
export function ExtensionMark({ extension }: { extension: AdminExtension }) {
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
'flex h-10 w-10 shrink-0 items-center justify-center rounded-sm bg-secondary text-sm font-semibold text-secondary-foreground'
|
||||
'flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-sm bg-secondary text-sm font-semibold text-secondary-foreground'
|
||||
}
|
||||
aria-hidden={'true'}
|
||||
>
|
||||
{extensionInitials(extension)}
|
||||
<ExtensionMarkContent extension={extension} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ Route::get('/activity/filters', ActivityFilterController::class)->name('api.admi
|
||||
Route::prefix('/extensions')->name('api.admin.extensions')->group(function (): void {
|
||||
Route::get('/', [ExtensionController::class, 'index']);
|
||||
Route::get('/{extension}/settings', [ExtensionController::class, 'settings'])->name('.settings');
|
||||
Route::get('/{extension}/icon', [ExtensionController::class, 'icon'])->name('.icon');
|
||||
|
||||
Route::middleware(RequireSessionAuthentication::class)->group(function (): void {
|
||||
Route::post('/', [ExtensionController::class, 'store'])->name('.install');
|
||||
|
||||
@@ -35,7 +35,7 @@ afterEach(function (): void {
|
||||
repository()->flushDiscovery();
|
||||
File::deleteDirectory($this->baseDirectory);
|
||||
});
|
||||
dataset('extensionEndpointsDataProvider', fn (): array => [['getJson', 'api.admin.extensions'], ['postJson', 'api.admin.extensions.install'], ['getJson', 'api.admin.extensions.settings', ['extension' => 'admin-fixture']], ['patchJson', 'api.admin.extensions.settings.update', ['extension' => 'admin-fixture']], ['postJson', 'api.admin.extensions.settings.file', ['extension' => 'admin-fixture', 'input' => 'logo']], ['deleteJson', 'api.admin.extensions.settings.file.clear', ['extension' => 'admin-fixture', 'input' => 'logo']], ['postJson', 'api.admin.extensions.enable', ['extension' => 'admin-fixture']], ['postJson', 'api.admin.extensions.disable', ['extension' => 'admin-fixture']], ['delete', 'api.admin.extensions.delete', ['extension' => 'admin-fixture']]]);
|
||||
dataset('extensionEndpointsDataProvider', fn (): array => [['getJson', 'api.admin.extensions'], ['postJson', 'api.admin.extensions.install'], ['getJson', 'api.admin.extensions.settings', ['extension' => 'admin-fixture']], ['get', 'api.admin.extensions.icon', ['extension' => 'admin-fixture']], ['patchJson', 'api.admin.extensions.settings.update', ['extension' => 'admin-fixture']], ['postJson', 'api.admin.extensions.settings.file', ['extension' => 'admin-fixture', 'input' => 'logo']], ['deleteJson', 'api.admin.extensions.settings.file.clear', ['extension' => 'admin-fixture', 'input' => 'logo']], ['postJson', 'api.admin.extensions.enable', ['extension' => 'admin-fixture']], ['postJson', 'api.admin.extensions.disable', ['extension' => 'admin-fixture']], ['delete', 'api.admin.extensions.delete', ['extension' => 'admin-fixture']]]);
|
||||
test('list extensions returns discovered extensions and metadata', function (): void {
|
||||
writeExtension('admin-fixture');
|
||||
Extension::query()->create(['identifier' => 'admin-fixture', 'version' => '1.0.0', 'enabled' => true]);
|
||||
@@ -289,16 +289,75 @@ function extensionPackage(array $manifest): UploadedFile
|
||||
return new UploadedFile($path, 'bad-probe.pteroext', 'application/zip', null, true);
|
||||
}
|
||||
|
||||
function writeExtension(string $identifier): void
|
||||
/**
|
||||
* @param array<string, string> $manifest
|
||||
*/
|
||||
function writeExtension(string $identifier, array $manifest = []): string
|
||||
{
|
||||
(function () use ($identifier): void {
|
||||
return (function () use ($identifier, $manifest): string {
|
||||
$path = $this->extensionsDirectory.DIRECTORY_SEPARATOR.$identifier;
|
||||
File::ensureDirectoryExists($path);
|
||||
File::put($path.DIRECTORY_SEPARATOR.'extension.json', json_encode(['id' => $identifier, 'name' => 'Admin Fixture', 'version' => '1.0.0'], JSON_THROW_ON_ERROR));
|
||||
File::put($path.DIRECTORY_SEPARATOR.'extension.json', json_encode(['id' => $identifier, 'name' => 'Admin Fixture', 'version' => '1.0.0', ...$manifest], JSON_THROW_ON_ERROR));
|
||||
repository()->flushDiscovery();
|
||||
|
||||
return $path;
|
||||
})->call(pterodactylTestCase());
|
||||
}
|
||||
|
||||
test('lists and serves an image icon from the package of a disabled extension', function (): void {
|
||||
$path = writeExtension('admin-fixture', ['icon' => 'resources/icon.png']);
|
||||
File::ensureDirectoryExists($path.'/resources');
|
||||
File::put($path.'/resources/icon.png', png());
|
||||
|
||||
$url = $this->getJson(route('api.admin.extensions'))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.icon', null)
|
||||
->assertJsonPath('data.0.enabled', false)
|
||||
->json('data.0.icon_url');
|
||||
expect($url)->toBe('/api/admin/extensions/admin-fixture/icon?v='.hash('xxh3', png()));
|
||||
|
||||
$served = $this->get($url)->assertOk();
|
||||
expect($served->getContent())->toBe(png());
|
||||
expect($served->headers->get('Content-Type'))->toBe('image/png');
|
||||
expect($served->headers->get('X-Content-Type-Options'))->toBe('nosniff');
|
||||
expect($served->headers->get('Cache-Control'))->toContain('private')->toContain('immutable');
|
||||
expect($served->headers->get('Content-Security-Policy'))->toContain('sandbox');
|
||||
});
|
||||
|
||||
test('lists a lucide icon name without an icon url', function (): void {
|
||||
writeExtension('admin-fixture', ['icon' => 'life-buoy']);
|
||||
|
||||
$this->getJson(route('api.admin.extensions'))
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.icon', 'life-buoy')
|
||||
->assertJsonPath('data.0.icon_url', null);
|
||||
$this->getJson(route('api.admin.extensions.icon', ['extension' => 'admin-fixture']))->assertNotFound();
|
||||
});
|
||||
|
||||
test('does not serve icons that are missing, unreadable, oversized or outside the package', function (string $case): void {
|
||||
$path = writeExtension('admin-fixture', ['icon' => 'icon.png']);
|
||||
$outside = $this->baseDirectory.DIRECTORY_SEPARATOR.'outside.png';
|
||||
File::put($outside, png());
|
||||
match ($case) {
|
||||
'missing' => null,
|
||||
'not an image' => File::put($path.'/icon.png', '<?php echo 1;'),
|
||||
'svg disguised as png' => File::put($path.'/icon.png', '<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>'),
|
||||
'oversized' => File::put($path.'/icon.png', png().str_repeat("\0", 513 * 1024)),
|
||||
'link outside the package' => symlink($outside, $path.'/icon.png'),
|
||||
};
|
||||
|
||||
$this->getJson(route('api.admin.extensions'))->assertOk()->assertJsonPath('data.0.icon_url', null);
|
||||
$this->getJson(route('api.admin.extensions.icon', ['extension' => 'admin-fixture']))->assertNotFound();
|
||||
})->with(['missing', 'not an image', 'svg disguised as png', 'oversized', 'link outside the package']);
|
||||
|
||||
test('icon for an unknown extension or one without an icon returns not found', function (): void {
|
||||
writeExtension('admin-fixture');
|
||||
|
||||
$this->getJson(route('api.admin.extensions'))->assertOk()->assertJsonPath('data.0.icon', null)->assertJsonPath('data.0.icon_url', null);
|
||||
$this->getJson(route('api.admin.extensions.icon', ['extension' => 'admin-fixture']))->assertNotFound();
|
||||
$this->getJson(route('api.admin.extensions.icon', ['extension' => 'missing']))->assertNotFound();
|
||||
});
|
||||
|
||||
test('secret settings are masked by the admin endpoint and encrypted on disk', function (): void {
|
||||
$settings = registerSettings();
|
||||
$this->patchJson(route('api.admin.extensions.settings.update', ['extension' => 'admin-fixture']), ['settings' => ['api_key' => 'private-token']])
|
||||
|
||||
@@ -435,3 +435,37 @@ test('reserves every top-level route of the SPA and matches the SDK manifest sch
|
||||
// Served by a core route whose `extensions.` name the route scan skips.
|
||||
expect(ExtensionManifest::RESERVED_ROOT_PREFIXES)->toContain(ExtensionSettingFiles::ROUTE_PREFIX);
|
||||
});
|
||||
|
||||
test('accepts a lucide icon name or an image path as the icon', function (?string $icon, ?string $name, ?string $file): void {
|
||||
writeManifest(array_filter(['id' => 'icon-test', 'name' => 'Icons', 'version' => '1.0.0', 'icon' => $icon]));
|
||||
$manifest = (new ExtensionManifestValidator)->fromDirectory($this->directory);
|
||||
|
||||
expect($manifest->icon)->toBe($icon);
|
||||
expect($manifest->iconName())->toBe($name);
|
||||
expect($manifest->iconFile())->toBe($file);
|
||||
})->with([
|
||||
'none' => [null, null, null],
|
||||
'lucide name' => ['life-buoy', 'life-buoy', null],
|
||||
'root image' => ['icon.png', null, 'icon.png'],
|
||||
'nested image' => ['resources/brand/Logo_2x.webp', null, 'resources/brand/Logo_2x.webp'],
|
||||
'jpeg image' => ['icon.jpeg', null, 'icon.jpeg'],
|
||||
]);
|
||||
|
||||
test('rejects icons that are neither a lucide name nor an image inside the package', function (mixed $icon): void {
|
||||
writeManifest(['id' => 'icon-test', 'name' => 'Icons', 'version' => '1.0.0', 'icon' => $icon]);
|
||||
|
||||
expect(fn () => (new ExtensionManifestValidator)->fromDirectory($this->directory))->toThrow(InvalidExtensionException::class, 'Manifest "icon"');
|
||||
})->with([
|
||||
'uppercase name' => ['LifeBuoy'],
|
||||
'trailing newline' => ["life-buoy\n"],
|
||||
'svg image' => ['icon.svg'],
|
||||
'gif image' => ['icon.gif'],
|
||||
'absolute path' => ['/etc/icon.png'],
|
||||
'traversal' => ['../icon.png'],
|
||||
'nested traversal' => ['dist/../../icon.png'],
|
||||
'hidden file' => ['.icon.png'],
|
||||
'backslashes' => ['dist\\icon.png'],
|
||||
'url' => ['https://example.com/icon.png'],
|
||||
'not a string' => [['icon.png']],
|
||||
'too long' => [str_repeat('a', 252).'.png'],
|
||||
]);
|
||||
|
||||
@@ -40,7 +40,7 @@ test('doctor reports navigation icons the panel does not ship without failing th
|
||||
]]], JSON_THROW_ON_ERROR));
|
||||
|
||||
$this->artisan('p:extension:doctor', ['path' => $this->directory])
|
||||
->expectsOutputToContain('Navigation icon "not-an-icon" is not a lucide icon this panel ships')
|
||||
->expectsOutputToContain('Icon "not-an-icon" is not a lucide icon this panel ships')
|
||||
->doesntExpectOutputToContain('life-buoy')
|
||||
->assertSuccessful();
|
||||
});
|
||||
@@ -98,6 +98,51 @@ test('packs runtime sources and lazy assets without developer files or hidden se
|
||||
$this->artisan('p:extension:pack', ['path' => $this->directory, '--output' => $archive])->assertFailed();
|
||||
});
|
||||
|
||||
test('packs an image icon declared outside the runtime directories once', function (string $icon): void {
|
||||
File::put($this->directory.'/extension.json', json_encode(['id' => 'probe', 'name' => 'Probe', 'version' => '1.0.0', 'icon' => $icon, 'autoload' => ['Probe\\' => 'src'], 'ui' => ['entry' => 'dist/client.js']], JSON_THROW_ON_ERROR));
|
||||
File::ensureDirectoryExists(dirname($this->directory.'/'.$icon));
|
||||
File::put($this->directory.'/'.$icon, toolingPng());
|
||||
$archive = $this->directory.'/probe.pteroext';
|
||||
$this->artisan('p:extension:pack', ['path' => $this->directory, '--output' => $archive])->assertSuccessful();
|
||||
$zip = new ZipArchive;
|
||||
expect($zip->open($archive))->toBeTrue();
|
||||
try {
|
||||
expect($zip->getFromName($icon))->toBe(toolingPng());
|
||||
$names = array_map(fn (int $index): string|false => $zip->getNameIndex($index), range(0, $zip->numFiles - 1));
|
||||
expect(array_count_values(array_filter($names))[$icon])->toBe(1);
|
||||
} finally {
|
||||
$zip->close();
|
||||
}
|
||||
})->with(['icon.png', 'dist/icon.png']);
|
||||
|
||||
test('doctor warns about an image icon it cannot serve without failing the package', function (?string $contents, string $message): void {
|
||||
File::put($this->directory.'/extension.json', json_encode(['id' => 'probe', 'name' => 'Probe', 'version' => '1.0.0', 'icon' => 'icon.png', 'autoload' => ['Probe\\' => 'src'], 'ui' => ['entry' => 'dist/client.js']], JSON_THROW_ON_ERROR));
|
||||
if ($contents !== null) {
|
||||
File::put($this->directory.'/icon.png', $contents);
|
||||
}
|
||||
|
||||
$this->artisan('p:extension:doctor', ['path' => $this->directory])
|
||||
->expectsOutputToContain($message)
|
||||
->assertSuccessful();
|
||||
})->with([
|
||||
'missing' => [null, 'Icon "icon.png" is missing'],
|
||||
'not an image' => ['<?php echo 1;', 'Icon "icon.png" is not a readable PNG, JPEG or WebP image'],
|
||||
]);
|
||||
|
||||
test('doctor accepts a readable image icon', function (): void {
|
||||
File::put($this->directory.'/extension.json', json_encode(['id' => 'probe', 'name' => 'Probe', 'version' => '1.0.0', 'icon' => 'icon.png', 'autoload' => ['Probe\\' => 'src'], 'ui' => ['entry' => 'dist/client.js']], JSON_THROW_ON_ERROR));
|
||||
File::put($this->directory.'/icon.png', toolingPng());
|
||||
|
||||
$this->artisan('p:extension:doctor', ['path' => $this->directory])
|
||||
->doesntExpectOutputToContain('Icon "icon.png"')
|
||||
->assertSuccessful();
|
||||
});
|
||||
|
||||
function toolingPng(): string
|
||||
{
|
||||
return (string) base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', true);
|
||||
}
|
||||
|
||||
test('a failed development build never publishes the incomplete package', function (): void {
|
||||
Process::fake(['*' => Process::result(exitCode: 1, errorOutput: 'build failed')]);
|
||||
$installer = Mockery::mock(InstallsExtensions::class);
|
||||
|
||||
Reference in New Issue
Block a user