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.');
|
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
|
// Truncate text
|
||||||
const maxChars = 6000;
|
const maxChars = 6000;
|
||||||
const trimmedPrompt = prompt && prompt.length > maxChars
|
const trimmedPrompt = prompt && prompt.length > maxChars
|
||||||
@@ -63,9 +55,7 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText
|
|||||||
if (action === 'generatePdf') {
|
if (action === 'generatePdf') {
|
||||||
if (!data.pdf) throw new Error('Empty PDF response from server.');
|
if (!data.pdf) throw new Error('Empty PDF response from server.');
|
||||||
await incrementUsage();
|
await incrementUsage();
|
||||||
const result = { pdf: data.pdf, filename: data.filename, fromCache: false };
|
return { pdf: data.pdf, filename: data.filename, fromCache: false };
|
||||||
await setCached(cacheKey, result);
|
|
||||||
return result;
|
|
||||||
} else {
|
} else {
|
||||||
const text = data.candidates?.[0]?.content?.parts?.[0]?.text;
|
const text = data.candidates?.[0]?.content?.parts?.[0]?.text;
|
||||||
if (!text) {
|
if (!text) {
|
||||||
@@ -73,9 +63,7 @@ async function handleGeminiRequest({ apiKey, prompt, tab, action = 'generateText
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await incrementUsage();
|
await incrementUsage();
|
||||||
const result = { text, fromCache: false };
|
return { text, fromCache: false };
|
||||||
await setCached(cacheKey, result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -580,8 +580,11 @@
|
|||||||
results[tab] = text;
|
results[tab] = text;
|
||||||
|
|
||||||
// Render markdown-like output
|
// Render markdown-like output
|
||||||
|
const isArabic = /[\u0600-\u06FF]/.test(text);
|
||||||
|
const rtlAttr = isArabic ? 'dir="rtl" style="text-align: right; padding-right: 15px;"' : '';
|
||||||
|
|
||||||
pane.innerHTML = `
|
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>' : ''}
|
${response.data.fromCache ? '<div class="lja-cache-badge">⚡ Cached result</div>' : ''}
|
||||||
${renderMarkdown(text)}
|
${renderMarkdown(text)}
|
||||||
</div>
|
</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",
|
"name": "hamza/cv-generator",
|
||||||
"description": "Dynamic ATS-Optimized CV Generator",
|
"description": "Dynamic ATS-Optimized CV Generator",
|
||||||
"require": {
|
"require": {
|
||||||
"dompdf/dompdf": "^3.0"
|
"dompdf/dompdf": "^3.0",
|
||||||
|
"vlucas/phpdotenv": "^5.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,16 +22,25 @@ if (!file_exists($autoloadPath)) {
|
|||||||
require_once $autoloadPath;
|
require_once $autoloadPath;
|
||||||
use Dompdf\Dompdf;
|
use Dompdf\Dompdf;
|
||||||
use Dompdf\Options;
|
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');
|
$rawData = file_get_contents('php://input');
|
||||||
$data = json_decode($rawData, true);
|
$data = json_decode($rawData, true);
|
||||||
|
|
||||||
$action = $data['action'] ?? 'generateText';
|
$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)) {
|
if (empty($apiKey)) {
|
||||||
http_response_code(400);
|
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;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user