Update
This commit is contained in:
@@ -152,7 +152,6 @@ public static function generateMemeByKeyword($keyword)
|
||||
return $meme;
|
||||
}
|
||||
|
||||
|
||||
public static function generateMemeOutputByKeyword($keyword, $category = null)
|
||||
{
|
||||
|
||||
@@ -203,7 +202,7 @@ public static function generateMemeOutputByKeyword($keyword, $category = null)
|
||||
$meme_output = (object) [
|
||||
'success' => false,
|
||||
'attempts' => $attempt, // Optional: track how many attempts were made
|
||||
'error' => 'Failed to generate valid meme after ' . $retries . ' attempts',
|
||||
'error' => 'Failed to generate valid meme after '.$retries.' attempts',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -216,13 +215,13 @@ public static function generateMemeOutputByCategory(Category $category)
|
||||
$random_keyword = Str::lower($category->name);
|
||||
|
||||
if (! is_null($category->parent_id)) {
|
||||
$random_keyword = $category->parent->name . ' - ' . $random_keyword;
|
||||
$random_keyword = $category->parent->name.' - '.$random_keyword;
|
||||
}
|
||||
|
||||
if (! is_null($category->meme_angles)) {
|
||||
$random_keyword .= ' - ' . collect($category->meme_angles)->random();
|
||||
$random_keyword .= ' - '.collect($category->meme_angles)->random();
|
||||
} elseif (! is_null($category->keywords)) {
|
||||
$random_keyword .= ' - ' . collect($category->keywords)->random();
|
||||
$random_keyword .= ' - '.collect($category->keywords)->random();
|
||||
}
|
||||
|
||||
return self::generateMemeOutputByKeyword($random_keyword, $category);
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class FrontPagesController extends Controller
|
||||
{
|
||||
@@ -12,16 +11,16 @@ public function privacy()
|
||||
{
|
||||
$markdownPath = resource_path('markdown/privacy.md');
|
||||
$markdownContent = file_get_contents($markdownPath);
|
||||
|
||||
|
||||
// Parse markdown to HTML using Laravel's built-in Str::markdown helper
|
||||
$htmlContent = Str::markdown($markdownContent);
|
||||
|
||||
|
||||
// Style the HTML with Tailwind classes
|
||||
$styledContent = $this->styleHtmlContent($htmlContent);
|
||||
|
||||
|
||||
return Inertia::render('FrontPages/Privacy', [
|
||||
'content' => $styledContent,
|
||||
'title' => 'Privacy Policy'
|
||||
'title' => 'Privacy Policy',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -29,16 +28,16 @@ public function terms()
|
||||
{
|
||||
$markdownPath = resource_path('markdown/terms.md');
|
||||
$markdownContent = file_get_contents($markdownPath);
|
||||
|
||||
|
||||
// Parse markdown to HTML using Laravel's built-in Str::markdown helper
|
||||
$htmlContent = Str::markdown($markdownContent);
|
||||
|
||||
|
||||
// Style the HTML with Tailwind classes
|
||||
$styledContent = $this->styleHtmlContent($htmlContent);
|
||||
|
||||
|
||||
return Inertia::render('FrontPages/Terms', [
|
||||
'content' => $styledContent,
|
||||
'title' => 'Terms & Conditions'
|
||||
'title' => 'Terms & Conditions',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -59,7 +58,7 @@ private function styleHtmlContent($html)
|
||||
$html = preg_replace('/<blockquote([^>]*)>/', '<blockquote$1 class="border-l-4 border-gray-300 dark:border-gray-600 pl-4 py-2 my-4 bg-gray-50 dark:bg-gray-800">', $html);
|
||||
$html = preg_replace('/<code([^>]*)>/', '<code$1 class="bg-gray-100 dark:bg-gray-800 px-2 py-1 rounded text-sm font-mono text-gray-800 dark:text-gray-200">', $html);
|
||||
$html = preg_replace('/<pre([^>]*)>/', '<pre$1 class="bg-gray-100 dark:bg-gray-800 p-4 rounded-lg overflow-x-auto mb-4">', $html);
|
||||
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ private function getMockGoogleUser()
|
||||
// Create a mock user object that mimics Socialite's user structure
|
||||
return new class
|
||||
{
|
||||
public $email = 'memeaigen.com@gmail.com';
|
||||
public $email = 'memefa.st@gmail.com';
|
||||
|
||||
public $id = 'xxx';
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
use App\Helpers\FirstParty\Credits\CreditsService;
|
||||
use App\Jobs\GenerateMemeJob;
|
||||
use App\Models\UserMemeGeneration;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Category;
|
||||
use App\Models\UserMemeGeneration;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -24,7 +24,7 @@ public function generateMeme(Request $request)
|
||||
->where('user_id', $user->id)
|
||||
->whereIn('status', ['pending', 'processing'])
|
||||
->first();
|
||||
|
||||
|
||||
if ($activeGeneration) {
|
||||
return response()->json([
|
||||
'error' => [
|
||||
@@ -34,7 +34,7 @@ public function generateMeme(Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
if (!CreditsService::canSpend($user->id, 2)) {
|
||||
if (! CreditsService::canSpend($user->id, 2)) {
|
||||
return response()->json([
|
||||
'error' => [
|
||||
'message' => 'You do not have enough credits to generate a meme. Please purchase credits from the Store.',
|
||||
@@ -45,7 +45,7 @@ public function generateMeme(Request $request)
|
||||
CreditsService::spend($user->id, 2);
|
||||
|
||||
$jobId = Str::uuid()->toString();
|
||||
|
||||
|
||||
// Create database record
|
||||
$generation = UserMemeGeneration::create([
|
||||
'user_id' => $user->id,
|
||||
@@ -55,11 +55,11 @@ public function generateMeme(Request $request)
|
||||
'credits_to_be_charged' => 2,
|
||||
'credits_are_processed' => false,
|
||||
]);
|
||||
|
||||
|
||||
// Set active job in cache
|
||||
Cache::put("user_active_job_{$user->id}", $jobId, 300);
|
||||
Cache::put("meme_job_status_{$jobId}", 'pending', 300);
|
||||
|
||||
|
||||
$job = new GenerateMemeJob($user->id, $request->prompt, $jobId);
|
||||
dispatch($job);
|
||||
|
||||
@@ -76,8 +76,8 @@ public function generateMeme(Request $request)
|
||||
public function checkMemeJobStatus(Request $request)
|
||||
{
|
||||
$jobId = $request->job_id;
|
||||
|
||||
if (!$jobId) {
|
||||
|
||||
if (! $jobId) {
|
||||
return response()->json([
|
||||
'error' => [
|
||||
'message' => 'Job ID is required.',
|
||||
@@ -86,8 +86,8 @@ public function checkMemeJobStatus(Request $request)
|
||||
}
|
||||
|
||||
$status = Cache::get("meme_job_status_{$jobId}");
|
||||
|
||||
if (!$status) {
|
||||
|
||||
if (! $status) {
|
||||
return response()->json([
|
||||
'error' => [
|
||||
'message' => 'Job not found or expired.',
|
||||
@@ -122,10 +122,10 @@ public function checkMemeJobStatus(Request $request)
|
||||
public function getActiveJob()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
|
||||
$activeJobId = Cache::get("user_active_job_{$user->id}");
|
||||
|
||||
if (!$activeJobId) {
|
||||
|
||||
if (! $activeJobId) {
|
||||
return response()->json([
|
||||
'success' => [
|
||||
'data' => null,
|
||||
@@ -138,9 +138,10 @@ public function getActiveJob()
|
||||
->with('meme.meme_media', 'meme.background_media')
|
||||
->first();
|
||||
|
||||
if (!$generation) {
|
||||
if (! $generation) {
|
||||
// Clean up stale cache
|
||||
Cache::forget("user_active_job_{$user->id}");
|
||||
|
||||
return response()->json([
|
||||
'success' => [
|
||||
'data' => null,
|
||||
@@ -163,7 +164,7 @@ public function getActiveJob()
|
||||
if ($generation->status === 'completed' && $generation->meme) {
|
||||
$meme = $generation->meme;
|
||||
$meme_media = $generation->meme->meme_media;
|
||||
|
||||
|
||||
$response['success']['data']['result'] = [
|
||||
'generate' => [
|
||||
'info' => $meme,
|
||||
@@ -180,7 +181,7 @@ public function getActiveJob()
|
||||
public function getMemeHistory()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
|
||||
$generations = UserMemeGeneration::where('user_id', $user->id)
|
||||
->with('meme.meme_media', 'meme.background_media')
|
||||
->orderBy('created_at', 'desc')
|
||||
@@ -228,9 +229,9 @@ public function aiHints()
|
||||
return response()->json([
|
||||
'success' => [
|
||||
'data' => [
|
||||
'keywords' => []
|
||||
]
|
||||
]
|
||||
'keywords' => [],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -241,9 +242,9 @@ public function aiHints()
|
||||
return response()->json([
|
||||
'success' => [
|
||||
'data' => [
|
||||
'keywords' => $keywords
|
||||
]
|
||||
]
|
||||
'keywords' => $keywords,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
use App\Helpers\FirstParty\Credits\CreditsService;
|
||||
use App\Helpers\FirstParty\Meme\MemeGenerator;
|
||||
use App\Models\User;
|
||||
use App\Models\UserMemeGeneration;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@@ -19,10 +18,13 @@ class GenerateMemeJob implements ShouldQueue
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 30;
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
protected $userId;
|
||||
|
||||
protected $prompt;
|
||||
|
||||
protected $jobId;
|
||||
|
||||
public function __construct(int $userId, string $prompt, ?string $jobId)
|
||||
@@ -37,7 +39,7 @@ public function handle(): void
|
||||
{
|
||||
$userGeneration = UserMemeGeneration::where('job_id', $this->jobId)->first();
|
||||
|
||||
if (!$userGeneration) {
|
||||
if (! $userGeneration) {
|
||||
throw new \Exception("User generation record not found for job {$this->jobId}");
|
||||
}
|
||||
|
||||
@@ -72,7 +74,7 @@ public function handle(): void
|
||||
Cache::forget("user_active_job_{$this->userId}");
|
||||
} catch (\Exception $e) {
|
||||
// Handle failure with credit refund
|
||||
if (!$userGeneration->credits_are_processed) {
|
||||
if (! $userGeneration->credits_are_processed) {
|
||||
if ($userGeneration->credits_to_be_charged > 0) {
|
||||
CreditsService::depositAlacarte(
|
||||
$userGeneration->user_id,
|
||||
@@ -101,7 +103,7 @@ public function failed(\Throwable $exception): void
|
||||
{
|
||||
$userGeneration = UserMemeGeneration::where('job_id', $this->jobId)->first();
|
||||
|
||||
if ($userGeneration && !$userGeneration->credits_are_processed) {
|
||||
if ($userGeneration && ! $userGeneration->credits_are_processed) {
|
||||
if ($userGeneration->credits_to_be_charged > 0) {
|
||||
CreditsService::depositAlacarte(
|
||||
$userGeneration->user_id,
|
||||
|
||||
@@ -31,4 +31,4 @@ public function meme(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Meme::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user