upgrade to laravel 12 done

This commit is contained in:
2025-08-03 21:33:05 +02:00
parent 83aba4c1a8
commit b4456bcabb
41 changed files with 3368 additions and 1455 deletions

View File

@@ -9,6 +9,7 @@ use App\Models\ApiProvider;
use App\Models\Style;
use App\Models\Image;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use App\Models\Setting;
@@ -75,7 +76,7 @@ class ImageController extends Controller
public function upload(Request $request)
{
$request->validate([
'image' => 'required|image|max:10240', // Max 10MB
'image' => 'required|image|mimes:jpeg,png,bmp,gif,webp|max:10240', // Max 10MB
]);
$file = $request->file('image');
@@ -156,34 +157,16 @@ class ImageController extends Controller
$style->parameters
);
$base64Image = $result['base64Data'];
$decodedImage = base64_decode(preg_replace('#^data:image/\w+;base64, #i', '', $base64Image));
$newImageName = 'styled_' . uniqid() . '.png'; // Assuming PNG for now
$newImagePathRelative = 'uploads/' . $newImageName; // Path relative to public/storage/
$newImageFullPath = public_path('storage/' . $newImagePathRelative); // Full path to save
// Ensure the directory exists
if (!File::exists(public_path('storage/uploads'))) {
File::makeDirectory(public_path('storage/uploads'), 0755, true);
}
File::put($newImageFullPath, $decodedImage); // Save using File facade
$newImage = Image::create([
'path' => $newImagePathRelative, // Store relative path
'original_image_id' => $image->id, // Link to original image
'style_id' => $style->id, // Link to applied style
'is_temp' => true, // Mark as temporary until user keeps it
]);
// Update the image model with the ComfyUI prompt_id and style_id
$image->comfyui_prompt_id = $result['prompt_id'];
$image->style_id = $style->id;
$image->save();
// Return the prompt_id for WebSocket tracking
return response()->json([
'message' => 'Style change successful',
'styled_image' => [
'id' => $newImage->id,
'path' => asset('storage/' . $newImage->path),
'is_temp' => $newImage->is_temp,
],
'message' => 'Style change request sent.',
'prompt_id' => $result['prompt_id'],
'image_uuid' => $image->uuid, // Pass image UUID for frontend tracking
]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
@@ -243,26 +226,99 @@ class ImageController extends Controller
}
}
public function getProgress(Request $request)
public function fetchStyledImage(string $promptId)
{
$request->validate([
'image_id' => 'required|exists:images,id',
'api_provider_name' => 'required|string',
]);
$image = Image::find($request->image_id);
$apiProvider = ApiProvider::where('name', $request->api_provider_name)->first();
if (!$image || !$apiProvider) {
return response()->json(['error' => __('api.image_or_provider_not_found')], 404);
}
Log::info('fetchStyledImage called.', ['prompt_id' => $promptId]);
try {
$plugin = PluginLoader::getPlugin($apiProvider->name);
$progress = $plugin->getProgress($image->uuid); // Annahme: Image Model hat eine UUID
return response()->json($progress);
// Find the image associated with the prompt_id, eagerly loading relationships
$image = Image::with(['style.aiModel.apiProviders' => function ($query) {
$query->where('enabled', true);
}])->where('comfyui_prompt_id', $promptId)->first();
if (!$image) {
Log::warning('fetchStyledImage: Image not found for prompt_id.', ['prompt_id' => $promptId]);
return response()->json(['error' => __('api.image_not_found')], 404);
}
Log::info('fetchStyledImage: Image found.', ['image_id' => $image->id, 'image_uuid' => $image->uuid, 'comfyui_prompt_id' => $image->comfyui_prompt_id]);
// Get the style and API provider associated with the image
$style = $image->style;
if (!$style) {
Log::warning('fetchStyledImage: Style not found for image.', ['image_id' => $image->id]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
Log::info('fetchStyledImage: Style found.', ['style_id' => $style->id, 'style_name' => $style->title]);
if (!$style->aiModel) {
Log::warning('fetchStyledImage: AI Model not found for style.', ['style_id' => $style->id]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
Log::info('fetchStyledImage: AI Model found.', ['ai_model_id' => $style->aiModel->id, 'ai_model_name' => $style->aiModel->name]);
if ($style->aiModel->apiProviders->isEmpty()) {
Log::warning('fetchStyledImage: No enabled API Providers found for AI Model.', ['ai_model_id' => $style->aiModel->id]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
$apiProvider = $style->aiModel->apiProviders->first();
Log::info('fetchStyledImage: API Provider found.', ['api_provider_id' => $apiProvider->id, 'api_provider_name' => $apiProvider->name]);
Log::info('Fetching base64 image from plugin.', ['prompt_id' => $promptId, 'api_provider' => $apiProvider->name]);
// Use the plugin to get the final image data (e.g., from ComfyUI's history/view)
$plugin = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
$base64Image = $plugin->waitForResult($promptId); // Re-purpose waitForResult for final fetch
if (empty($base64Image)) {
Log::error('Received empty base64 image from plugin.', ['prompt_id' => $promptId]);
return response()->json(['error' => 'Received empty image data.'], 500);
}
Log::info('Base64 image received. Decoding and saving.');
$decodedImage = base64_decode(preg_replace('#^data:image/\w+;base64, #i', '', $base64Image));
$newImageName = 'styled_' . uniqid() . '.png';
$newImagePathRelative = 'uploads/' . $newImageName;
$newImageFullPath = public_path('storage/' . $newImagePathRelative);
if (!File::exists(public_path('storage/uploads'))) {
File::makeDirectory(public_path('storage/uploads'), 0755, true);
Log::info('Created uploads directory.', ['path' => public_path('storage/uploads')]);
}
File::put($newImageFullPath, $decodedImage); // Save using File facade
Log::info('Image saved to disk.', ['path' => $newImageFullPath]);
$newImage = Image::create([
'path' => $newImagePathRelative, // Store relative path
'original_image_id' => $image->id,
'style_id' => $style->id,
'is_temp' => true,
]);
Log::info('New image record created in database.', ['image_id' => $newImage->id, 'path' => $newImage->path]);
return response()->json([
'message' => 'Styled image fetched successfully',
'styled_image' => [
'id' => $newImage->id,
'path' => asset('storage/' . $newImage->path),
'is_temp' => $newImage->is_temp,
],
]);
} catch (\Exception $e) {
Log::error('Error in fetchStyledImage: ' . $e->getMessage(), ['exception' => $e]);
return response()->json(['error' => $e->getMessage()], 500);
}
}
}
public function getComfyUiUrl()
{
$apiProvider = ApiProvider::where('plugin', 'comfyui')->where('enabled', true)->first();
if (!$apiProvider) {
return response()->json(['error' => 'No enabled ComfyUI API provider found.'], 404);
}
return response()->json(['comfyui_url' => rtrim($apiProvider->api_url, '/')]);
}
}