finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!

This commit is contained in:
2025-11-13 17:42:43 +01:00
parent f59fda588b
commit b311188bc1
138 changed files with 5440 additions and 4105 deletions

View File

@@ -2,25 +2,27 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Api\Plugins\PluginLoader;
use App\Http\Controllers\Controller;
use App\Models\ApiProvider;
use App\Models\Style;
use App\Models\Image;
use App\Models\Style;
use App\Settings\GeneralSettings;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use App\Models\Setting;
class ImageController extends Controller
{
public function __construct(private GeneralSettings $settings) {}
public function index(Request $request)
{
$publicUploadsPath = public_path('storage/uploads');
// Ensure the directory exists
if (!File::exists($publicUploadsPath)) {
if (! File::exists($publicUploadsPath)) {
File::makeDirectory($publicUploadsPath, 0755, true);
}
@@ -29,7 +31,7 @@ class ImageController extends Controller
$diskImagePaths = [];
foreach ($diskFiles as $file) {
// Store path relative to public/storage/
$diskImagePaths[] = 'uploads/' . $file->getFilename();
$diskImagePaths[] = 'uploads/'.$file->getFilename();
}
$dbImagePaths = Image::pluck('path')->toArray();
@@ -48,7 +50,7 @@ class ImageController extends Controller
$query = Image::orderBy('updated_at', 'desc');
// If user is not authenticated, filter by is_public, but also include their temporary images
if (!auth()->check()) {
if (! auth()->check()) {
$query->where(function ($q) {
$q->where('is_public', true)->orWhere('is_temp', true);
});
@@ -56,10 +58,11 @@ class ImageController extends Controller
// If user is authenticated, show all their images
}
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
$newImageTimespanMinutes = $this->settings->new_image_timespan_minutes;
$images = $query->get()->map(function ($image) use ($newImageTimespanMinutes) {
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
return $image;
});
@@ -67,13 +70,14 @@ class ImageController extends Controller
foreach ($images as $image) {
$formattedImages[] = [
'image_id' => $image->id,
'path' => asset('storage/' . $image->path),
'path' => asset('storage/'.$image->path),
'name' => basename($image->path),
'is_temp' => (bool) $image->is_temp,
'is_public' => (bool) $image->is_public,
'is_new' => (bool) $image->is_new,
];
}
return response()->json($formattedImages);
}
@@ -84,16 +88,16 @@ class ImageController extends Controller
]);
$file = $request->file('image');
$fileName = uniqid() . '.' . $file->getClientOriginalExtension();
$fileName = uniqid().'.'.$file->getClientOriginalExtension();
$destinationPath = public_path('storage/uploads');
// Ensure the directory exists
if (!File::exists($destinationPath)) {
if (! File::exists($destinationPath)) {
File::makeDirectory($destinationPath, 0755, true);
}
$file->move($destinationPath, $fileName);
$relativePath = 'uploads/' . $fileName; // Path relative to public/storage/
$relativePath = 'uploads/'.$fileName; // Path relative to public/storage/
$image = Image::create([
'path' => $relativePath,
@@ -103,7 +107,7 @@ class ImageController extends Controller
return response()->json([
'message' => __('api.image_uploaded_successfully'),
'image_id' => $image->id,
'path' => asset('storage/' . $relativePath),
'path' => asset('storage/'.$relativePath),
]);
}
@@ -113,9 +117,9 @@ class ImageController extends Controller
\Illuminate\Support\Facades\Log::info('styleChangeRequest called', [
'image_id' => $request->image_id,
'style_id' => $request->style_id,
'all_params' => $request->all()
'all_params' => $request->all(),
]);
// Same-origin check
$appUrl = config('app.url');
$referer = $request->headers->get('referer');
@@ -123,8 +127,9 @@ class ImageController extends Controller
if ($referer && parse_url($referer, PHP_URL_HOST) !== parse_url($appUrl, PHP_URL_HOST)) {
\Illuminate\Support\Facades\Log::warning('Unauthorized styleChangeRequest', [
'referer' => $referer,
'app_url' => $appUrl
'app_url' => $appUrl,
]);
return response()->json(['error' => 'Unauthorized: Request must originate from the same domain.'], 403);
}
@@ -142,39 +147,41 @@ class ImageController extends Controller
}])->find($request->style_id);
} else {
// Attempt to get default style from settings
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
if ($defaultStyleSetting && $defaultStyleSetting->value) {
$defaultStyleId = $this->settings->default_style_id;
if ($defaultStyleId) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($defaultStyleSetting->value);
}])->find($defaultStyleId);
}
}
if (!$style || !$style->aiModel || !$style->aiModel->primaryApiProvider) {
if (! $style || ! $style->aiModel || ! $style->aiModel->primaryApiProvider) {
\Illuminate\Support\Facades\Log::warning('Style or provider not found', [
'style' => $style ? $style->toArray() : null,
'ai_model' => $style && $style->aiModel ? $style->aiModel->toArray() : null
'ai_model' => $style && $style->aiModel ? $style->aiModel->toArray() : null,
]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
try {
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
if (!$apiProvider) {
if (! $apiProvider) {
\Illuminate\Support\Facades\Log::error('No API provider found for style', [
'style_id' => $style->id,
'ai_model_id' => $style->aiModel->id
'ai_model_id' => $style->aiModel->id,
]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
\Illuminate\Support\Facades\Log::info('Selected API provider for style change', [
'api_provider_id' => $apiProvider->id,
'api_provider_name' => $apiProvider->name,
'plugin' => $apiProvider->plugin
'plugin' => $apiProvider->plugin,
]);
$plugin = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
$result = $plugin->processImageStyleChange($image, $style);
@@ -187,9 +194,9 @@ class ImageController extends Controller
// Return the prompt_id for WebSocket tracking
\Illuminate\Support\Facades\Log::info('Style change request completed', [
'prompt_id' => $result['prompt_id'],
'image_uuid' => $image->uuid
'image_uuid' => $image->uuid,
]);
return response()->json([
'message' => 'Style change request sent.',
'prompt_id' => $result['prompt_id'],
@@ -199,8 +206,9 @@ class ImageController extends Controller
} catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error('Error in styleChangeRequest', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
'trace' => $e->getTraceAsString(),
]);
return response()->json(['error' => $e->getMessage()], 500);
}
}
@@ -213,7 +221,7 @@ class ImageController extends Controller
$image = Image::find($request->image_id);
if (!$image) {
if (! $image) {
return response()->json(['error' => __('api.image_not_found')], 404);
}
@@ -227,8 +235,9 @@ class ImageController extends Controller
{
try {
// Delete from the public/storage directory
File::delete(public_path('storage/' . $image->path));
File::delete(public_path('storage/'.$image->path));
$image->delete();
return response()->json(['message' => __('api.image_deleted_successfully')]);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
@@ -245,13 +254,14 @@ class ImageController extends Controller
$image = Image::find($request->image_id);
$apiProvider = ApiProvider::where('name', $request->api_provider_name)->first();
if (!$image || !$apiProvider) {
if (! $image || ! $apiProvider) {
return response()->json(['error' => __('api.image_or_provider_not_found')], 404);
}
try {
$plugin = PluginLoader::getPlugin($apiProvider->name);
$status = $plugin->getStatus($image->uuid); // Annahme: Image Model hat eine UUID
return response()->json($status);
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
@@ -267,8 +277,9 @@ class ImageController extends Controller
$query->with('primaryApiProvider');
}])->where('comfyui_prompt_id', $promptId)->first();
if (!$image) {
if (! $image) {
Log::warning('fetchStyledImage: Image not found for prompt_id.', ['prompt_id' => $promptId]);
return response()->json(['error' => __('api.image_not_found')], 404);
}
@@ -276,22 +287,25 @@ class ImageController extends Controller
// Get the style and API provider associated with the image
$style = $image->style;
if (!$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) {
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]);
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
if (!$apiProvider) {
if (! $apiProvider) {
Log::warning('fetchStyledImage: No API Provider found for AI Model.', ['ai_model_id' => $style->aiModel->id]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
Log::info('fetchStyledImage: API Provider found.', ['api_provider_id' => $apiProvider->id, 'api_provider_name' => $apiProvider->name]);
@@ -303,17 +317,18 @@ class ImageController extends Controller
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);
$newImageName = 'styled_'.uniqid().'.png';
$newImagePathRelative = 'uploads/'.$newImageName;
$newImageFullPath = public_path('storage/'.$newImagePathRelative);
if (!File::exists(public_path('storage/uploads'))) {
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')]);
}
@@ -334,12 +349,13 @@ class ImageController extends Controller
'message' => 'Styled image fetched successfully',
'styled_image' => [
'id' => $newImage->id,
'path' => asset('storage/' . $newImage->path),
'path' => asset('storage/'.$newImage->path),
'is_temp' => $newImage->is_temp,
],
]);
} catch (\Exception $e) {
Log::error('Error in fetchStyledImage: ' . $e->getMessage(), ['exception' => $e]);
Log::error('Error in fetchStyledImage: '.$e->getMessage(), ['exception' => $e]);
return response()->json(['error' => $e->getMessage()], 500);
}
}
@@ -348,15 +364,15 @@ class ImageController extends Controller
{
$styleId = $request->query('style_id');
$imageUuid = $request->query('image_uuid');
$apiProvider = null;
// If style_id is provided, get the API provider for that style
if ($styleId) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($styleId);
if ($style && $style->aiModel) {
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
@@ -367,7 +383,7 @@ class ImageController extends Controller
$image = Image::with(['style.aiModel' => function ($query) {
$query->with('primaryApiProvider');
}])->where('uuid', $imageUuid)->first();
if ($image && $image->style && $image->style->aiModel) {
// Use the primary API provider for this AI model
$apiProvider = $image->style->aiModel->primaryApiProvider;
@@ -376,25 +392,25 @@ class ImageController extends Controller
// Fallback to the old behavior if no style_id or image_uuid is provided
else {
// Try to get a default style if none is provided
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
if ($defaultStyleSetting && $defaultStyleSetting->value) {
$defaultStyleId = $this->settings->default_style_id;
if ($defaultStyleId) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($defaultStyleSetting->value);
}])->find($defaultStyleId);
if ($style && $style->aiModel) {
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
}
}
// If still no API provider, use the first available ComfyUI provider
if (!$apiProvider) {
if (! $apiProvider) {
$apiProvider = ApiProvider::where('plugin', 'ComfyUi')->where('enabled', true)->first();
}
}
if (!$apiProvider) {
if (! $apiProvider) {
return response()->json(['error' => 'No enabled ComfyUI API provider found.'], 404);
}

View File

@@ -4,11 +4,12 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Style;
use App\Models\Setting;
use Illuminate\Http\Request;
use App\Settings\GeneralSettings;
class StyleController extends Controller
{
public function __construct(private GeneralSettings $settings) {}
public function index()
{
$styles = Style::with(['aiModel.primaryApiProvider'])
@@ -31,15 +32,15 @@ class StyleController extends Controller
public function getImageRefreshInterval()
{
$interval = Setting::where('key', 'image_refresh_interval')->first();
return response()->json(['interval' => $interval ? (int)$interval->value / 1000 : 5]);
return response()->json([
'interval' => $this->settings->image_refresh_interval / 1000,
]);
}
public function getMaxNumberOfCopies()
{
$maxCopies = Setting::where('key', 'max_number_of_copies')->first();
return response()->json(['max_copies' => $maxCopies ? (int)$maxCopies->value : 10]); // Default to 10 if not set
return response()->json([
'max_copies' => $this->settings->max_number_of_copies,
]);
}
}
}