Vorlesen und Leichte Sprache mit KI-Vorschlag (0.34.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 9m24s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 9m15s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m10s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m8s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 9m24s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 9m15s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m10s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m8s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fc2505297b
commit
856a5c30af
210 changed files with 1447 additions and 521 deletions
55
app/Http/Controllers/EasyLanguageController.php
Normal file
55
app/Http/Controllers/EasyLanguageController.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Accessibility\EasyLanguage;
|
||||
use App\Ai\AiAssistant;
|
||||
use App\Support\Audit;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Leichte Sprache pflegen – von Hand oder mit einem Vorschlag des KI-Assistenten.
|
||||
*/
|
||||
class EasyLanguageController extends Controller
|
||||
{
|
||||
public function update(Request $request, string $type, int $id, EasyLanguage $easy): RedirectResponse
|
||||
{
|
||||
$this->editable($request, $type, $id, $easy);
|
||||
$data = $request->validate(['html' => ['nullable', 'string', 'max:200000'], 'ai_assisted' => ['boolean']]);
|
||||
|
||||
$saved = $easy->save($type, $id, $data['html'] ?? null, $request->user(), (bool) ($data['ai_assisted'] ?? false));
|
||||
Audit::log($saved ? 'easy_language.saved' : 'easy_language.removed', ['type' => $type, 'id' => $id]);
|
||||
|
||||
return back()->with('status', $saved ? 'Leichte Sprache gespeichert.' : 'Leichte Sprache entfernt.');
|
||||
}
|
||||
|
||||
public function suggest(Request $request, string $type, int $id, EasyLanguage $easy, AiAssistant $ai): JsonResponse
|
||||
{
|
||||
$subject = $this->editable($request, $type, $id, $easy);
|
||||
|
||||
try {
|
||||
$html = app(RichText::class)->toSafeHtml($ai->easyLanguage($subject['title'], ($subject['text'])()));
|
||||
} catch (RuntimeException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
Audit::log('ai.easy_language', ['type' => $type, 'id' => $id, 'model' => $ai->model()]);
|
||||
|
||||
return response()->json(['html' => $html]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{can_view: bool, can_edit: bool, title: string, text: callable(): string}
|
||||
*/
|
||||
private function editable(Request $request, string $type, int $id, EasyLanguage $easy): array
|
||||
{
|
||||
$subject = $easy->resolve($type, $id, $request->user());
|
||||
abort_unless($subject !== null && $subject['can_edit'], 403);
|
||||
|
||||
return $subject;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue