language files combined, settings fixed, "new" badge integrated
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -4,20 +4,33 @@ namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Image;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
$translations = Lang::get('messages', [], $locale);
|
||||
$translations = array_merge(
|
||||
Lang::get('api', [], $locale),
|
||||
Lang::get('settings', [], $locale)
|
||||
);
|
||||
$galleryHeading = Setting::where('key', 'gallery_heading')->first()->value ?? 'Style Gallery';
|
||||
$newImageTimespanMinutes = Setting::where('key', 'new_image_timespan_minutes')->first()->value ?? 60; // Default to 60 minutes
|
||||
|
||||
$images = Image::all()->map(function ($image) use ($newImageTimespanMinutes) {
|
||||
$image->is_new = Carbon::parse($image->created_at)->diffInMinutes(Carbon::now()) <= $newImageTimespanMinutes;
|
||||
$image->path = 'storage/' . $image->path;
|
||||
return $image;
|
||||
});
|
||||
|
||||
return Inertia::render('Home', [
|
||||
'translations' => $translations,
|
||||
'galleryHeading' => $galleryHeading,
|
||||
'images' => $images,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -35,14 +35,21 @@ class HandleInertiaRequests extends Middleware
|
||||
'user' => $request->user(),
|
||||
],
|
||||
'locale' => app()->getLocale(),
|
||||
'lang' => function () {
|
||||
'translations' => function () use ($request) {
|
||||
$currentLocale = app()->getLocale(); // Store current locale
|
||||
$requestedLocale = $request->input('locale', $currentLocale);
|
||||
app()->setLocale($requestedLocale); // Set locale based on request or current
|
||||
|
||||
$lang = [
|
||||
'filament' => trans('filament'),
|
||||
'api' => trans('api'),
|
||||
'settings' => trans('settings'),
|
||||
'messages' => trans('messages'),
|
||||
// Add other translation files as needed
|
||||
];
|
||||
|
||||
dd($lang); // <-- ADDED FOR DEBUGGING
|
||||
|
||||
app()->setLocale($currentLocale); // Revert to original locale
|
||||
return $lang;
|
||||
},
|
||||
];
|
||||
|
||||
@@ -15,12 +15,16 @@ class SetLocale
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
|
||||
|
||||
if (in_array($locale, ['de'])) {
|
||||
app()->setLocale($locale);
|
||||
if (auth()->check() && auth()->user()->locale) {
|
||||
app()->setLocale(auth()->user()->locale);
|
||||
} else {
|
||||
app()->setLocale('en');
|
||||
$locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2);
|
||||
|
||||
if (in_array($locale, ['de'])) {
|
||||
app()->setLocale($locale);
|
||||
} else {
|
||||
app()->setLocale('en');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
Reference in New Issue
Block a user