Skip to content

Commit

Permalink
feat: rewrite icon urls
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckadams committed Jan 18, 2025
1 parent 99be478 commit f6bd762
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/Enums/AssetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum AssetType: string
case THEME = 'theme';
case PLUGIN_SCREENSHOT = 'plugin-screenshot';
case PLUGIN_BANNER = 'plugin-banner';
case PLUGIN_GP_ICON = 'plugin-gp-icon'; // geopattern-icon only -- other icons are treated as screenshots
case THEME_SCREENSHOT = 'theme-screenshot';

public function isZip(): bool
Expand All @@ -18,6 +19,9 @@ public function isZip(): bool

public function isAsset(): bool
{
return in_array($this, [self::PLUGIN_SCREENSHOT, self::PLUGIN_BANNER, self::THEME_SCREENSHOT]);
return in_array(
$this,
[self::PLUGIN_SCREENSHOT, self::PLUGIN_BANNER, self::PLUGIN_GP_ICON, self::THEME_SCREENSHOT],
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Controllers\API\WpOrg\Downloads;

use App\Enums\AssetType;
use App\Services\Downloads\DownloadService;
use Symfony\Component\HttpFoundation\Response;

class DownloadPluginIconController
{
public function __construct(private readonly DownloadService $downloadService) {}

public function __invoke(string $slug, string $revision, string $file): Response
{
$type = AssetType::PLUGIN_GP_ICON;
return $this->downloadService->download(type: $type, slug: $slug, file: $file, revision: $revision);
}
}
3 changes: 2 additions & 1 deletion app/Jobs/DownloadAssetJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function generateLocalPath(): string
AssetType::PLUGIN => "plugins/{$this->slug}",
AssetType::THEME => "themes/{$this->slug}",
AssetType::PLUGIN_SCREENSHOT,
AssetType::PLUGIN_BANNER => "assets/{$this->slug}",
AssetType::PLUGIN_BANNER => "assets/plugin/{$this->slug}",
AssetType::PLUGIN_GP_ICON => "gp-icon/plugin/{$this->slug}",
AssetType::THEME_SCREENSHOT => "assets/theme/{$this->slug}/{$this->revision}",
};

Expand Down
518 changes: 516 additions & 2 deletions app/Models/WpOrg/Plugin.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/Services/Downloads/DownloadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static function buildUpstreamUrl(AssetType $type, string $slug, string $f
AssetType::THEME => 'https://downloads.wordpress.org/theme/',
AssetType::PLUGIN_SCREENSHOT,
AssetType::PLUGIN_BANNER => "https://ps.w.org/$slug/assets/",
AssetType::PLUGIN_GP_ICON => "https://s.w.org/plugins/geopattern-icon/",
AssetType::THEME_SCREENSHOT => "https://ts.w.org/wp-content/themes/$slug/",
};

Expand Down
6 changes: 6 additions & 0 deletions routes/inc/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Http\Controllers\API\WpOrg\Downloads\DownloadCoreController;
use App\Http\Controllers\API\WpOrg\Downloads\DownloadPluginAssetController;
use App\Http\Controllers\API\WpOrg\Downloads\DownloadPluginController;
use App\Http\Controllers\API\WpOrg\Downloads\DownloadPluginIconController;
use App\Http\Controllers\API\WpOrg\Downloads\DownloadThemeController;
use App\Http\Controllers\API\WpOrg\Downloads\DownloadThemeScreenshotController;
use Illuminate\Routing\Router;
Expand Down Expand Up @@ -37,6 +38,11 @@
->where(['slug' => '[a-zA-Z0-9-]+', 'file' => '.+'])
->name('download.plugin.asset');

$router
->get('/download/gp-icon/plugin/{slug}/{revision}/{file}', DownloadPluginIconController::class)
->where(['slug' => '[a-zA-Z0-9-]+', 'file' => '.+'])
->name('download.plugin.gp-icon');

$router
->get('/download/assets/theme/{slug}/{revision}/{file}', DownloadThemeScreenshotController::class)
->where(['slug' => '[a-zA-Z0-9-]+', 'file' => '.+'])
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Sync/SyncPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@
->and($plugin->commercial_support_url)->toBeEmpty()
->and($plugin->donate_link)->toBeEmpty()
->and($plugin->banners)->toBeEmpty()
->and($plugin->icons)->toBe(['default' => 'https://s.w.org/plugins/geopattern-icon/0-errors.svg'])
->and($plugin->preview_link)->toBeEmpty();

// test URL rewrites
expect($plugin->download_link)
->toBe('https://api.aspiredev.org/download/plugin/0-errors.0.2.zip')
->and($plugin->icons)->toBe(
['default' => 'https://api.aspiredev.org/download/gp-icon/plugin/0-errors/head/0-errors.svg'],
)
->and($plugin->versions)->toBe([
'0.1' => 'https://api.aspiredev.org/download/plugin/0-errors.0.1.zip',
'0.2' => 'https://api.aspiredev.org/download/plugin/0-errors.0.2.zip',
Expand Down

0 comments on commit f6bd762

Please sign in to comment.