language files combined, settings fixed, "new" badge integrated

This commit is contained in:
2025-08-01 23:34:41 +02:00
parent b2968f203d
commit 80873877c1
44 changed files with 1319 additions and 358 deletions

View File

@@ -9,10 +9,12 @@ use App\Models\ApiProvider;
use App\Models\Style;
use App\Models\Image;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use App\Models\Setting;
class ImageController extends Controller
{
public function index()
public function index(Request $request)
{
$publicUploadsPath = public_path('storage/uploads');
@@ -34,15 +36,28 @@ class ImageController extends Controller
// Add images from disk that are not in the database
$imagesToAdd = array_diff($diskImagePaths, $dbImagePaths);
foreach ($imagesToAdd as $path) {
Image::create(['path' => $path]);
Image::create(['path' => $path, 'is_public' => true]);
}
// Remove images from database that are not on disk
$imagesToRemove = array_diff($dbImagePaths, $diskImagePaths);
Image::whereIn('path', $imagesToRemove)->delete();
// Fetch all images from the database after synchronization
$images = Image::orderBy('updated_at', 'desc')->get();
// Fetch images from the database after synchronization
$query = Image::orderBy('updated_at', 'desc');
// If user is not authenticated, filter by is_public
if (!auth()->check()) {
$query->where('is_public', true);
}
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
$images = $query->get()->map(function ($image) use ($newImageTimespanMinutes) {
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
return $image;
});
$formattedImages = [];
foreach ($images as $image) {
$formattedImages[] = [
@@ -50,6 +65,8 @@ class ImageController extends Controller
'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);
@@ -75,6 +92,7 @@ class ImageController extends Controller
$image = Image::create([
'path' => $relativePath,
'is_public' => true,
]);
return response()->json([
@@ -96,15 +114,29 @@ class ImageController extends Controller
$request->validate([
'image_id' => 'required|exists:images,id',
'style_id' => 'required|exists:styles,id',
'style_id' => 'nullable|exists:styles,id',
]);
$image = Image::find($request->image_id);
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
}])->find($request->style_id);
$style = null;
if ($request->style_id) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
}])->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) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
}])->find($defaultStyleSetting->value);
}
}
if (!$style || !$style->aiModel || $style->aiModel->apiProviders->isEmpty()) {
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);