mirror of
https://gh.wpcy.net/https://github.com/fairpm/aspirecloud.git
synced 2026-06-22 02:42:19 +08:00
33 lines
935 B
PHP
33 lines
935 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\API\WpOrg\Downloads;
|
|
|
|
use App\Enums\AssetType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Downloads\DownloadService;
|
|
use App\Utils\Regex;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class DownloadPluginController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly DownloadService $downloadService,
|
|
) {}
|
|
|
|
public function __invoke(Request $request, string $file): Response
|
|
{
|
|
$matches = Regex::match('/^([a-zA-Z0-9-]+)\.(.+)\.zip$/', $file);
|
|
if (!$matches) {
|
|
return response()->json(['error' => "Invalid filename", 'filename' => $file], 400);
|
|
}
|
|
|
|
return $this->downloadService->download(
|
|
request: $request,
|
|
type: AssetType::PLUGIN,
|
|
slug: $matches[1],
|
|
file: $file,
|
|
);
|
|
}
|
|
}
|