implemented step 10 by Gemini

- added 4. step of wizard for style and images
This commit is contained in:
2026-06-14 08:07:23 +02:00
parent 991ff9de00
commit c11f7e4d75
5 changed files with 440 additions and 10 deletions

View File

@ -163,6 +163,14 @@ class ProjectActions
$projectData['wizard_data']['services'] = $data['services'];
$projectData['wizard_data']['smart_answers'] = $data['smart_answers'];
break;
case 4:
if (!isset($data['visuals']) || !isset($data['assets'])) {
throw new Exception("Missing visuals or assets data.", 400);
}
$projectData['wizard_data']['visuals'] = $data['visuals'];
$projectData['wizard_data']['assets'] = $data['assets'];
break;
// More steps will be added later
}
@ -172,4 +180,53 @@ class ProjectActions
return $this->storage->put($projectPath, $projectData);
}
/**
* Handles secure asset upload.
*/
public function uploadAsset(string $userId, string $projectId, array $file): array
{
// 1. Ownership check
$this->getProjectStatus($userId, $projectId);
// 2. Validation
$maxSize = 2 * 1024 * 1024; // 2MB
if ($file['size'] > $maxSize) {
throw new Exception("File is too large (max 2MB).", 400);
}
$allowedMimeTypes = ['image/jpeg', 'image/png', 'image/webp', 'image/svg+xml'];
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->file($file['tmp_name']);
if (!in_array($mimeType, $allowedMimeTypes)) {
throw new Exception("Invalid file type. Allowed: JPG, PNG, WEBP, SVG.", 400);
}
$extension = pathinfo($file['name'], PATHINFO_EXTENSION);
$allowedExtensions = ['jpg', 'jpeg', 'png', 'webp', 'svg'];
if (!in_array(strtolower($extension), $allowedExtensions)) {
throw new Exception("Invalid file extension.", 400);
}
// 3. Prepare storage
$uploadDir = __DIR__ . "/../../exports/{$projectId}/assets/images";
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
// 4. Secure filename
$filename = bin2hex(random_bytes(8)) . '.' . $extension;
$targetPath = $uploadDir . '/' . $filename;
if (!move_uploaded_file($file['tmp_name'], $targetPath)) {
throw new Exception("Failed to move uploaded file.", 500);
}
return [
'path' => "exports/{$projectId}/assets/images/{$filename}",
'filename' => $filename,
'mime_type' => $mimeType
];
}
}