runware.ai connection test funktioniert, drucken dialog implementiert

This commit is contained in:
2025-08-08 10:11:56 +02:00
parent ad893b48a7
commit cfceaed08f
12 changed files with 305 additions and 82 deletions

View File

@@ -35,4 +35,11 @@ class StyleController extends Controller
return response()->json(['interval' => $interval ? (int)$interval->value / 1000 : 5]);
}
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
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class PrintController extends Controller
{
public function printImage(Request $request)
{
$request->validate([
'image_path' => 'required|string',
'quantity' => 'required|integer|min:1',
]);
$imagePath = public_path(str_replace(url('/'), '', $request->input('image_path')));
$quantity = $request->input('quantity');
if (!file_exists($imagePath)) {
Log::error("PrintController: Image file not found at {$imagePath}");
return response()->json(['error' => 'Image file not found.'], 404);
}
// IMPORTANT: Replace this command with one that works in your environment.
// Examples:
// Linux/macOS: $command = ['lpr', '-#', $quantity, $imagePath];
// Windows (assuming a shared printer named 'MyNetworkPrinter'):
// $command = ['print', '/d:\\MyNetworkPrinter', $imagePath];
// You might need to install additional software or configure your system
// to enable command-line printing.
// For a more robust solution, consider a dedicated print server application
// or a commercial print API.
$command = ['echo', "Simulating print of {$quantity} copies of {$imagePath}"]; // Placeholder
try {
$process = new Process($command);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
Log::info("PrintController: Successfully sent print command for {$imagePath} (x{$quantity})");
return response()->json(['message' => 'Print command sent successfully.']);
} catch (ProcessFailedException $exception) {
Log::error("PrintController: Print command failed. Error: " . $exception->getMessage());
return response()->json(['error' => 'Failed to send print command.', 'details' => $exception->getMessage()], 500);
}
}
}