diff --git a/background.js b/background.js index 55a5a01..16cf762 100644 --- a/background.js +++ b/background.js @@ -24,14 +24,6 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText throw new Error('Daily limit reached (1,000 requests). Resets at midnight PT.'); } - // Check cache (keyed by tab + prompt hash) - const cacheStr = prompt || jobDescription; - const cacheKey = `cache_${tab}_${action}_${hashString(cacheStr)}`; - const cached = await getCached(cacheKey); - if (cached) { - return cached; // returns either text object or pdf object - } - // Truncate text const maxChars = 6000; const trimmedPrompt = prompt && prompt.length > maxChars @@ -63,9 +55,7 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText if (action === 'generatePdf') { if (!data.pdf) throw new Error('Empty PDF response from server.'); await incrementUsage(); - const result = { pdf: data.pdf, filename: data.filename, fromCache: false }; - await setCached(cacheKey, result); - return result; + return { pdf: data.pdf, filename: data.filename, fromCache: false }; } else { const text = data.candidates?.[0]?.content?.parts?.[0]?.text; if (!text) { @@ -73,9 +63,7 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText continue; } await incrementUsage(); - const result = { text, fromCache: false }; - await setCached(cacheKey, result); - return result; + return { text, fromCache: false }; } } diff --git a/content.js b/content.js index cb9094c..38c09f5 100644 --- a/content.js +++ b/content.js @@ -580,8 +580,11 @@ results[tab] = text; // Render markdown-like output + const isArabic = /[\u0600-\u06FF]/.test(text); + const rtlAttr = isArabic ? 'dir="rtl" style="text-align: right; padding-right: 15px;"' : ''; + pane.innerHTML = ` -
+
${response.data.fromCache ? '
⚡ Cached result
' : ''} ${renderMarkdown(text)}
diff --git a/server/.env.example b/server/.env.example new file mode 100644 index 0000000..1cedebe --- /dev/null +++ b/server/.env.example @@ -0,0 +1 @@ +GEMINI_API_KEY="your_api_key_here" diff --git a/server/composer.json b/server/composer.json index 868bd57..844fa20 100644 --- a/server/composer.json +++ b/server/composer.json @@ -2,6 +2,7 @@ "name": "hamza/cv-generator", "description": "Dynamic ATS-Optimized CV Generator", "require": { - "dompdf/dompdf": "^3.0" + "dompdf/dompdf": "^3.0", + "vlucas/phpdotenv": "^5.6" } } diff --git a/server/generate_cv.php b/server/generate_cv.php index 20c844a..b3d5d47 100644 --- a/server/generate_cv.php +++ b/server/generate_cv.php @@ -22,16 +22,25 @@ if (!file_exists($autoloadPath)) { require_once $autoloadPath; use Dompdf\Dompdf; use Dompdf\Options; +use Dotenv\Dotenv; + +// Load .env if it exists +if (file_exists(__DIR__ . '/.env')) { + $dotenv = Dotenv::createImmutable(__DIR__); + $dotenv->load(); +} $rawData = file_get_contents('php://input'); $data = json_decode($rawData, true); $action = $data['action'] ?? 'generateText'; -$apiKey = $data['apiKey'] ?? ''; + +// Prioritize API key from .env over frontend payload +$apiKey = $_ENV['GEMINI_API_KEY'] ?? getenv('GEMINI_API_KEY') ?: ($data['apiKey'] ?? ''); if (empty($apiKey)) { http_response_code(400); - echo json_encode(["error" => "Missing apiKey"]); + echo json_encode(["error" => "Missing apiKey. Please set GEMINI_API_KEY in .env or pass it in request."]); exit; }