Initial commit: Runware-powered content generator foundation

Laravel app with a cost-tracked Runware.ai integration (image, video,
text generation), a hard monthly EUR budget cap with live USD/EUR FX
conversion, and a locally-maintained model/pricing table since
Runware's model-search API doesn't expose pricing.
This commit is contained in:
2026-09-23 15:59:05 +03:00
commit 79320950e7
78 changed files with 14452 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}
@@ -0,0 +1,59 @@
<?php
namespace App\Http\Controllers;
use App\Exceptions\BudgetExceededException;
use App\Models\Generation;
use App\Models\RunwareModel;
use App\Services\Runware\BudgetGuard;
use App\Services\Runware\GenerationService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class GenerationController extends Controller
{
public function index(BudgetGuard $budget): View
{
return view('generations.index', [
'generations' => Generation::query()->latest()->paginate(20),
'models' => RunwareModel::query()->where('active', true)->orderBy('modality')->orderBy('price_usd')->get()->groupBy('modality'),
'capEur' => $budget->capEur(),
'spentEur' => $budget->spentEurThisMonth(),
'remainingEur' => $budget->remainingEur(),
'warnThresholdReached' => $budget->warnThresholdReached(),
]);
}
public function store(Request $request, GenerationService $generations): RedirectResponse
{
$data = $request->validate([
'type' => ['required', 'in:image,video,text'],
'prompt' => ['required', 'string', 'max:4000'],
'model' => ['nullable', 'string'],
'width' => ['nullable', 'integer', 'min:64', 'max:2048'],
'height' => ['nullable', 'integer', 'min:64', 'max:2048'],
'duration' => ['nullable', 'integer', 'min:1', 'max:30'],
]);
$params = array_filter([
'width' => $data['width'] ?? null,
'height' => $data['height'] ?? null,
'duration' => $data['duration'] ?? null,
], fn ($v) => $v !== null);
try {
match ($data['type']) {
'image' => $generations->createImage($data['prompt'], $params, $data['model'] ?? null),
'text' => $generations->createText($data['prompt'], $params, $data['model'] ?? null),
'video' => $generations->queueVideo($data['prompt'], $params, $data['model'] ?? null),
};
} catch (BudgetExceededException $e) {
return back()->withErrors(['budget' => $e->getMessage()])->withInput();
} catch (\Throwable $e) {
return back()->withErrors(['generation' => 'Generation failed: '.$e->getMessage()])->withInput();
}
return redirect()->route('generations.index');
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Http\Controllers;
use App\Models\RunwareModel;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class RunwareModelController extends Controller
{
public function index(): View
{
return view('runware-models.index', [
'models' => RunwareModel::query()->orderBy('modality')->orderBy('price_usd')->get(),
]);
}
public function store(Request $request): RedirectResponse
{
$data = $request->validate([
'modality' => ['required', 'in:image,video,text'],
'air_id' => ['required', 'string', 'max:255'],
'label' => ['required', 'string', 'max:255'],
'unit' => ['required', 'in:per_image,per_second,per_million_tokens'],
'price_usd' => ['required', 'numeric', 'min:0'],
]);
RunwareModel::create($data);
RunwareModel::recomputeDefault($data['modality']);
return redirect()->route('runware-models.index');
}
public function update(Request $request, RunwareModel $runwareModel): RedirectResponse
{
$data = $request->validate([
'active' => ['required', 'boolean'],
]);
$runwareModel->update($data);
RunwareModel::recomputeDefault($runwareModel->modality);
return redirect()->route('runware-models.index');
}
public function destroy(RunwareModel $runwareModel): RedirectResponse
{
$modality = $runwareModel->modality;
$runwareModel->delete();
RunwareModel::recomputeDefault($modality);
return redirect()->route('runware-models.index');
}
}