Auto-deploy: 2026-05-17 01:43:14
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = `
|
||||
<div class="lja-result ${response.data.fromCache ? 'lja-cached' : ''}">
|
||||
<div class="lja-result ${response.data.fromCache ? 'lja-cached' : ''}" ${rtlAttr}>
|
||||
${response.data.fromCache ? '<div class="lja-cache-badge">⚡ Cached result</div>' : ''}
|
||||
${renderMarkdown(text)}
|
||||
</div>
|
||||
|
||||
1
server/.env.example
Normal file
1
server/.env.example
Normal file
@@ -0,0 +1 @@
|
||||
GEMINI_API_KEY="your_api_key_here"
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user