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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ExportToken;
|
||||
use App\Services\TrackingAnalyticsService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -11,6 +12,17 @@ class UserExportController extends Controller
|
||||
{
|
||||
public function premiumExportRequest(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'meme_media_ids' => 'nullable|string', // Accept hashid string
|
||||
'background_media_ids' => 'nullable|string', // Accept hashid string
|
||||
'caption_texts' => 'required|array',
|
||||
'caption_texts.*' => 'string',
|
||||
]);
|
||||
|
||||
// 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;
|
||||
|
||||
$user = Auth::user();
|
||||
$user->load('user_usage');
|
||||
|
||||
@@ -33,9 +45,22 @@ public function premiumExportRequest(Request $request)
|
||||
'token' => Str::uuid()->toString(),
|
||||
'is_premium' => true,
|
||||
'credits_reserved' => 1,
|
||||
'metadata' => [
|
||||
'meme_media_id' => $memeMediaId,
|
||||
'background_media_id' => $backgroundMediaId,
|
||||
'caption_texts' => $request->caption_texts,
|
||||
],
|
||||
'expires_at' => now()->addMinutes(30),
|
||||
]);
|
||||
|
||||
// Track the export
|
||||
try {
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackExport(null, $memeMediaId, $backgroundMediaId, $request->caption_texts);
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore tracking errors
|
||||
}
|
||||
|
||||
$user->user_usage->refresh();
|
||||
|
||||
return response()->json([
|
||||
@@ -92,6 +117,17 @@ public function premiumExportComplete(Request $request)
|
||||
|
||||
public function basicExportRequest(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'meme_media_ids' => 'nullable|string', // Accept hashid string
|
||||
'background_media_ids' => 'nullable|string', // Accept hashid string
|
||||
'caption_texts' => 'required|array',
|
||||
'caption_texts.*' => 'string',
|
||||
]);
|
||||
|
||||
// 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;
|
||||
|
||||
// No authentication required for basic exports
|
||||
// Create export token (expires in 30 minutes)
|
||||
$token = ExportToken::create([
|
||||
@@ -100,8 +136,21 @@ public function basicExportRequest(Request $request)
|
||||
'is_premium' => false,
|
||||
'credits_reserved' => 0, // No credits for basic exports
|
||||
'expires_at' => now()->addMinutes(30),
|
||||
'metadata' => [
|
||||
'meme_media_id' => $memeMediaId,
|
||||
'background_media_id' => $backgroundMediaId,
|
||||
'caption_texts' => $request->caption_texts,
|
||||
],
|
||||
]);
|
||||
|
||||
// Track the export
|
||||
try {
|
||||
$trackingService = app(TrackingAnalyticsService::class);
|
||||
$trackingService->trackExport(null, $memeMediaId, $backgroundMediaId, $request->caption_texts);
|
||||
} catch (\Exception $e) {
|
||||
// Silently ignore tracking errors
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => [
|
||||
'data' => [
|
||||
|
||||
Reference in New Issue
Block a user