Wire admin studio SSR and search infrastructure

This commit is contained in:
2026-05-01 11:46:06 +02:00
parent 257b0dbef6
commit 18cea8b0f0
329 changed files with 197465 additions and 2741 deletions

View File

@@ -17,6 +17,7 @@ use App\Models\ArtworkReaction;
use App\Models\ContentType;
use App\Models\GroupRelease;
use App\Models\GroupReleaseContributor;
use App\Models\HomepageAnnouncement;
use App\Observers\ArtworkAwardObserver;
use App\Observers\ArtworkCommentObserver;
use App\Observers\ArtworkFeatureObserver;
@@ -26,12 +27,15 @@ use App\Observers\ArtworkReactionObserver;
use App\Observers\ContentTypeObserver;
use App\Observers\GroupReleaseContributorObserver;
use App\Observers\GroupReleaseObserver;
use App\Observers\HomepageAnnouncementObserver;
use App\Services\Upload\Contracts\UploadDraftServiceInterface;
use App\Services\Upload\UploadDraftService;
use App\Services\ContentTypes\ContentTypeSlugResolver;
use App\Services\Worlds\WorldService;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
@@ -120,6 +124,7 @@ class AppServiceProvider extends ServiceProvider
ContentType::observe(ContentTypeObserver::class);
GroupRelease::observe(GroupReleaseObserver::class);
GroupReleaseContributor::observe(GroupReleaseContributorObserver::class);
HomepageAnnouncement::observe(HomepageAnnouncementObserver::class);
// ── OAuth / SocialiteProviders ──────────────────────────────────────
Event::listen(
@@ -157,6 +162,7 @@ class AppServiceProvider extends ServiceProvider
$displayName = null;
$userId = null;
$toolbarContentTypes = collect();
$toolbarActiveCampaign = null;
$request = request();
$canReadSessionAuth = $request instanceof \Illuminate\Http\Request
&& $request->hasSession()
@@ -173,39 +179,78 @@ class AppServiceProvider extends ServiceProvider
$toolbarContentTypes = collect();
}
try {
$toolbarActiveCampaign = $this->app
->make(WorldService::class)
->navigationCampaign();
} catch (\Throwable $e) {
$toolbarActiveCampaign = null;
}
if ($authUser) {
$authUser->loadMissing('profile');
$userId = (int) $authUser->id;
try {
$uploadCount = DB::table('artworks')->where('user_id', $userId)->count();
$ttl = (int) config('toolbar.cache_ttl_seconds', 30);
$stats = Cache::remember("toolbar:{$userId}", $ttl, function () use ($userId) {
$toolbarStats = DB::table('users')
->select('id')
->selectSub(
DB::table('artworks')
->selectRaw('COUNT(*)')
->whereColumn('user_id', 'users.id'),
'upload_count'
)
->selectSub(
DB::table('artwork_favourites')
->selectRaw('COUNT(*)')
->whereColumn('user_id', 'users.id'),
'fav_count'
)
->selectSub(
DB::table('notifications')
->selectRaw('COUNT(*)')
->whereColumn('user_id', 'users.id')
->whereNull('read_at'),
'notice_count'
)
->where('id', $userId)
->first();
$uploadCount = (int) ($toolbarStats->upload_count ?? 0);
$favCount = (int) ($toolbarStats->fav_count ?? 0);
$noticeCount = (int) ($toolbarStats->notice_count ?? 0);
$msgCount = (int) DB::table('conversation_participants as cp')
->join('messages as m', 'm.conversation_id', '=', 'cp.conversation_id')
->where('cp.user_id', $userId)
->whereNull('cp.left_at')
->whereNull('m.deleted_at')
->where('m.sender_id', '!=', $userId)
->where(function ($q) {
$q->whereNull('cp.last_read_at')
->orWhereColumn('m.created_at', '>', 'cp.last_read_at');
})
->count();
return [
'upload_count' => $uploadCount,
'fav_count' => $favCount,
'notice_count' => $noticeCount,
'msg_count' => $msgCount,
];
});
$uploadCount = (int) ($stats['upload_count'] ?? 0);
$favCount = (int) ($stats['fav_count'] ?? 0);
$noticeCount = (int) ($stats['notice_count'] ?? 0);
$msgCount = (int) ($stats['msg_count'] ?? 0);
} catch (\Throwable $e) {
$uploadCount = 0;
}
try {
$favCount = DB::table('artwork_favourites')->where('user_id', $userId)->count();
} catch (\Throwable $e) {
$favCount = 0;
}
try {
$msgCount = (int) DB::table('conversation_participants as cp')
->join('messages as m', 'm.conversation_id', '=', 'cp.conversation_id')
->where('cp.user_id', $userId)
->whereNull('cp.left_at')
->whereNull('m.deleted_at')
->where('m.sender_id', '!=', $userId)
->where(function ($q) {
$q->whereNull('cp.last_read_at')
->orWhereColumn('m.created_at', '>', 'cp.last_read_at');
})
->count();
} catch (\Throwable $e) {
$msgCount = 0;
}
try {
$noticeCount = DB::table('notifications')->where('user_id', $userId)->whereNull('read_at')->count();
} catch (\Throwable $e) {
$noticeCount = 0;
}
@@ -216,17 +261,11 @@ class AppServiceProvider extends ServiceProvider
$receivedCommentsCount = 0;
}
try {
$profile = DB::table('user_profiles')->where('user_id', $userId)->first();
$avatarHash = $profile->avatar_hash ?? null;
} catch (\Throwable $e) {
$avatarHash = null;
}
$avatarHash = $authUser->profile?->avatar_hash;
$displayName = $authUser->name ?: ($authUser->username ?? '');
}
$view->with(compact('userId','uploadCount', 'favCount', 'msgCount', 'noticeCount', 'receivedCommentsCount', 'avatarHash', 'displayName', 'toolbarContentTypes'));
$view->with(compact('userId','uploadCount', 'favCount', 'msgCount', 'noticeCount', 'receivedCommentsCount', 'avatarHash', 'displayName', 'toolbarContentTypes', 'toolbarActiveCampaign'));
});
// Replace the framework HandleCors with our ConditionalCors so the