This commit is contained in:
ct
2025-07-16 12:38:06 +08:00
parent d4b69df538
commit d4c5fb5589
25 changed files with 249 additions and 86 deletions

View File

@@ -21,4 +21,4 @@ protected static function getFacadeAccessor(): string
{
return 'tracking-analytics';
}
}
}

View File

@@ -59,7 +59,7 @@ public function background(Request $request)
public function searchMemes(Request $request)
{
$query = $request->input('query', '');
$limit = $request->input('limit', 30);
$limit = 30;
if (empty($query)) {
// Return random memes if no search query
@@ -106,7 +106,7 @@ public function searchMemes(Request $request)
public function searchBackgrounds(Request $request)
{
$query = $request->input('query', '');
$limit = $request->input('limit', 30);
$limit = 30;
if (empty($query)) {
// Return random backgrounds if no search query

View File

@@ -89,4 +89,64 @@ public function premiumExportComplete(Request $request)
],
]);
}
public function basicExportRequest(Request $request)
{
// No authentication required for basic exports
// Create export token (expires in 30 minutes)
$token = ExportToken::create([
'user_id' => null, // Anonymous user
'token' => Str::uuid()->toString(),
'is_premium' => false,
'credits_reserved' => 0, // No credits for basic exports
'expires_at' => now()->addMinutes(30),
]);
return response()->json([
'success' => [
'data' => [
'export_token' => $token->token,
],
],
]);
}
public function basicExportComplete(Request $request)
{
$request->validate([
'export_token' => 'required|string',
]);
// Find the token (no user requirement)
$token = ExportToken::where('token', $request->export_token)
->whereNull('user_id') // Only anonymous tokens
->first();
if (! $token) {
return response()->json([
'error' => [
'message' => 'Invalid export token.',
],
]);
}
if (! $token->isValid()) {
return response()->json([
'error' => [
'message' => 'Export token has expired or already been used.',
],
]);
}
// Mark token as used
$token->markAsUsed();
return response()->json([
'success' => [
'data' => [
'message' => 'Export completed successfully.',
],
],
]);
}
}

View File

@@ -52,7 +52,7 @@ public function handle(): void
'content_id' => $this->contentId,
'error' => $e->getMessage(),
]);
throw $e;
}
}
@@ -66,4 +66,4 @@ public function failed(\Throwable $exception): void
'exception' => $exception->getMessage(),
]);
}
}
}

View File

@@ -57,7 +57,7 @@ public function handle(): int
'export_format' => $this->exportFormat,
'error' => $e->getMessage(),
]);
throw $e;
}
}
@@ -71,4 +71,4 @@ public function failed(\Throwable $exception): void
'exception' => $exception->getMessage(),
]);
}
}
}

View File

@@ -48,7 +48,7 @@ public function handle(): void
'search_query' => $this->searchQuery,
'error' => $e->getMessage(),
]);
throw $e;
}
}
@@ -62,4 +62,4 @@ public function failed(\Throwable $exception): void
'exception' => $exception->getMessage(),
]);
}
}
}

View File

@@ -28,7 +28,7 @@ public function handle(): void
{
try {
$trackingExport = TrackingExport::findOrFail($this->trackingExportId);
$updateData = [
'export_status' => $this->status,
];
@@ -50,7 +50,7 @@ public function handle(): void
'status' => $this->status,
'error' => $e->getMessage(),
]);
throw $e;
}
}
@@ -63,4 +63,4 @@ public function failed(\Throwable $exception): void
'exception' => $exception->getMessage(),
]);
}
}
}

View File

@@ -30,6 +30,11 @@ public function user(): BelongsTo
return $this->belongsTo(User::class);
}
public function isAnonymous(): bool
{
return is_null($this->user_id);
}
public function isExpired(): bool
{
return $this->expires_at->isPast();

View File

@@ -2,9 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
class TrackingContentSelection extends Model
{
@@ -41,11 +40,11 @@ public function content()
if ($this->content_type === 'meme') {
return $this->belongsTo(MemeMedia::class, 'content_id');
}
if ($this->content_type === 'background') {
return $this->belongsTo(BackgroundMedia::class, 'content_id');
}
return null;
}
}
}

View File

@@ -2,8 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class TrackingExport extends Model
@@ -88,4 +88,4 @@ public function scopeProcessing($query)
{
return $query->where('export_status', 'processing');
}
}
}

View File

@@ -2,8 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TrackingSearch extends Model
{
@@ -30,4 +30,4 @@ class TrackingSearch extends Model
protected $attributes = [
'platform' => 'web',
];
}
}

View File

@@ -15,7 +15,7 @@ class AppServiceProvider extends ServiceProvider
public function register(): void
{
$this->app->singleton('tracking-analytics', function ($app) {
return new TrackingAnalyticsService();
return new TrackingAnalyticsService;
});
}

View File

@@ -2,9 +2,9 @@
namespace App\Services;
use App\Jobs\TrackSearchJob;
use App\Jobs\TrackContentSelectionJob;
use App\Jobs\TrackExportJob;
use App\Jobs\TrackSearchJob;
use App\Jobs\UpdateExportStatusJob;
use Carbon\Carbon;
@@ -118,7 +118,7 @@ public function updateExportStatus(
public function getDeviceContext(): array
{
$request = request();
return [
'user_agent' => $request->userAgent(),
'ip_address' => $request->ip(),
@@ -132,15 +132,15 @@ public function getDeviceContext(): array
public function generateDeviceId(): string
{
$request = request();
// Generate a consistent device ID based on session or create new one
if ($request->session()->has('device_id')) {
return $request->session()->get('device_id');
}
$deviceId = str()->uuid()->toString();
$request->session()->put('device_id', $deviceId);
return $deviceId;
}
@@ -151,7 +151,7 @@ public function quickTrackSearch(string $searchType, string $searchQuery, ?array
{
$context = $this->getDeviceContext();
$deviceId = $this->generateDeviceId();
$this->trackSearch(
$deviceId,
$searchType,
@@ -168,7 +168,7 @@ public function quickTrackContentSelection(string $contentType, int $contentId,
{
$context = $this->getDeviceContext();
$deviceId = $this->generateDeviceId();
$this->trackContentSelection(
$deviceId,
$contentType,
@@ -187,7 +187,7 @@ public function quickTrackExport(?int $memeId, ?int $memeMediaId, ?int $backgrou
{
$context = $this->getDeviceContext();
$deviceId = $this->generateDeviceId();
return $this->trackExport(
$deviceId,
$memeId,
@@ -202,4 +202,4 @@ public function quickTrackExport(?int $memeId, ?int $memeMediaId, ?int $backgrou
$context['platform']
);
}
}
}