Update
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
use App\Models\BackgroundMedia;
|
||||
use App\Models\Meme;
|
||||
use App\Models\MemeMedia;
|
||||
use App\Services\TrackingAnalyticsService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FrontMediaController extends Controller
|
||||
@@ -61,6 +62,16 @@ public function searchMemes(Request $request)
|
||||
$query = $request->input('query', '');
|
||||
$limit = 30;
|
||||
|
||||
// Track the search if there's a query
|
||||
if (! empty($query)) {
|
||||
try {
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackSearch('meme', $query);
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore tracking errors
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($query)) {
|
||||
// Return random memes if no search query
|
||||
$memes = MemeMedia::where('type', 'video')->where('sub_type', 'overlay')->take($limit)->inRandomOrder()->get();
|
||||
@@ -108,6 +119,16 @@ public function searchBackgrounds(Request $request)
|
||||
$query = $request->input('query', '');
|
||||
$limit = 30;
|
||||
|
||||
// Track the search if there's a query
|
||||
if (! empty($query)) {
|
||||
try {
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackSearch('background', $query);
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore tracking errors
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($query)) {
|
||||
// Return random backgrounds if no search query
|
||||
$backgrounds = BackgroundMedia::where('status', 'completed')->take($limit)->inRandomOrder()->get();
|
||||
@@ -134,4 +155,99 @@ public function searchBackgrounds(Request $request)
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function selectMeme(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'meme_ids' => 'required|string',
|
||||
]);
|
||||
|
||||
// Decode the hashid to get the actual database ID
|
||||
$memeMediaId = hashids_decode($request->meme_ids);
|
||||
|
||||
if ($memeMediaId) {
|
||||
// Get the meme media for the name
|
||||
$memeMedia = MemeMedia::find($memeMediaId);
|
||||
|
||||
if ($memeMedia) {
|
||||
// Track the content selection
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackContentSelection(
|
||||
'meme',
|
||||
$memeMediaId,
|
||||
$memeMedia->name,
|
||||
'browse'
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore all errors
|
||||
}
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function selectBackground(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'background_ids' => 'required|string',
|
||||
]);
|
||||
|
||||
// Decode the hashid to get the actual database ID
|
||||
$backgroundMediaId = hashids_decode($request->background_ids);
|
||||
|
||||
if ($backgroundMediaId) {
|
||||
// Get the background media for the name
|
||||
$backgroundMedia = BackgroundMedia::find($backgroundMediaId);
|
||||
|
||||
if ($backgroundMedia) {
|
||||
// Track the content selection
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackContentSelection(
|
||||
'background',
|
||||
$backgroundMediaId,
|
||||
$backgroundMedia->prompt ?? 'Background',
|
||||
'browse'
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore all errors
|
||||
}
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function saveMeme(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'meme_media_ids' => 'nullable|string',
|
||||
'background_media_ids' => 'nullable|string',
|
||||
'caption_texts' => 'required|array',
|
||||
'caption_texts.*' => 'string',
|
||||
'is_premium_export' => 'boolean',
|
||||
]);
|
||||
|
||||
// Convert hashids to actual database IDs
|
||||
$memeMediaId = $request->meme_media_ids ? hashids_decode($request->meme_media_ids) : null;
|
||||
$backgroundMediaId = $request->background_media_ids ? hashids_decode($request->background_media_ids) : null;
|
||||
|
||||
// Track the save action
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackSave(
|
||||
null, // meme_id
|
||||
$memeMediaId,
|
||||
$backgroundMediaId,
|
||||
$request->caption_texts,
|
||||
$request->is_premium_export ?? false
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore all errors
|
||||
}
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user