dockerfile

This commit is contained in:
浪子
2026-03-19 19:39:14 +08:00
parent 04eccc850d
commit 62cffc6f5f
13 changed files with 578 additions and 51 deletions
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\WebAdmin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\PublishZipVersionRequest;
use App\Http\Requests\Admin\StoreCategoryRequest;
use App\Http\Requests\Admin\StorePackageRequest;
use App\Models\Category;
@@ -220,17 +221,10 @@ class DashboardController extends Controller
return redirect()->route('webadmin.packages.show', [$type, $slug])->with('success', '版本已添加:v' . $version->version);
}
public function publishVersion(Request $request, string $type, string $slug): RedirectResponse
public function publishVersion(PublishZipVersionRequest $request, string $type, string $slug): RedirectResponse
{
$package = $this->findPackage($type, $slug);
$validated = $request->validate([
'package_file' => ['required', 'file', 'mimes:zip', 'max:51200'],
'is_stable' => ['nullable', 'boolean'],
'mark_as_latest' => ['nullable', 'boolean'],
'changelog' => ['nullable', 'string'],
'published_at' => ['nullable', 'date'],
]);
$validated = $request->validated();
try {
$version = $this->publishService->publishFromZip($package, $request->file('package_file'), $validated);
@@ -3,6 +3,8 @@
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;
use ZipArchive;
class PublishZipVersionRequest extends FormRequest
{
@@ -11,14 +13,75 @@ class PublishZipVersionRequest extends FormRequest
return true;
}
protected function prepareForValidation(): void
{
$extensions = $this->input('php_extensions');
if (is_string($extensions)) {
$this->merge([
'php_extensions' => collect(preg_split('/[,\s]+/u', $extensions))
->map(fn ($item) => trim((string) $item))
->filter()
->values()
->all(),
]);
}
}
public function rules(): array
{
return [
'package_file' => ['required', 'file', 'mimes:zip', 'max:51200'],
'version' => ['nullable', 'string', 'max:32', 'regex:/^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/'],
'typecho_min' => ['nullable', 'string', 'max:16'],
'typecho_max' => ['nullable', 'string', 'max:16'],
'php_min' => ['nullable', 'string', 'max:16'],
'php_max' => ['nullable', 'string', 'max:16'],
'php_extensions' => ['nullable', 'array'],
'php_extensions.*' => ['string', 'max:32'],
'is_stable' => ['nullable', 'boolean'],
'mark_as_latest' => ['nullable', 'boolean'],
'changelog' => ['nullable', 'string'],
'published_at' => ['nullable', 'date'],
];
}
public function withValidator(Validator $validator): void
{
$validator->after(function (Validator $validator) {
$file = $this->file('package_file');
if (!$file || !$file->isValid() || $this->zipHasManifestAtRoot($file->getRealPath())) {
return;
}
if (blank((string) $this->input('version', ''))) {
$validator->errors()->add('version', 'zip 根目录没有 manifest.json 时,必须手动填写版本号。');
}
});
}
private function zipHasManifestAtRoot(string $path): bool
{
$zip = new ZipArchive();
if ($zip->open($path) !== true) {
return false;
}
try {
for ($i = 0; $i < $zip->numFiles; $i++) {
$stat = $zip->statIndex($i);
$name = trim((string) ($stat['name'] ?? ''), '/');
if ($name === 'manifest.json') {
return true;
}
}
return false;
} finally {
$zip->close();
}
}
}