- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Themes;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Themes\UploadThemeRequest;
|
|
use App\Services\ThemeService;
|
|
use Exception;
|
|
|
|
/**
|
|
* Controller for uploading a new theme.
|
|
*/
|
|
class ThemeUploadController extends Controller
|
|
{
|
|
/**
|
|
* Handle the theme upload request.
|
|
*
|
|
* @param \App\Http\Requests\Admin\Themes\UploadThemeRequest $request
|
|
* @param \App\Services\ThemeService $themeService
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function __invoke(UploadThemeRequest $request, ThemeService $themeService)
|
|
{
|
|
try {
|
|
$result = $themeService->upload($request->file('theme_zip'));
|
|
|
|
return response()->json([
|
|
'message' => 'Theme uploaded successfully.',
|
|
'theme' => $result['metadata'],
|
|
]);
|
|
} catch (Exception $e) {
|
|
$statusCode = str_contains($e->getMessage(), 'Invalid theme') ? 422 : 500;
|
|
$message = str_contains($e->getMessage(), 'Invalid theme') ? $e->getMessage() : 'An error occurred during theme extraction: ' . $e->getMessage();
|
|
return response()->json(['message' => $message], $statusCode);
|
|
}
|
|
}
|
|
}
|