Auto-deploy: 2026-05-18 03:06:29

This commit is contained in:
Hamza-Ayed
2026-05-18 03:06:29 +03:00
parent 470580ba05
commit 29dac58464
4 changed files with 238 additions and 0 deletions

View File

@@ -215,3 +215,58 @@ if ($action === 'generateComment') {
echo json_encode(["success" => true, "comment" => $commentText]);
exit;
}
// ==========================================
// ACTION 4: Repurpose Post Generator
// ==========================================
if ($action === 'repurposePost') {
$postText = substr($data['postText'] ?? '', 0, 3000);
if (empty($postText)) {
http_response_code(400);
echo json_encode(["error" => "postText is required."]);
exit;
}
$promptFile = __DIR__ . '/prompts/repurpose_prompt.txt';
if (!file_exists($promptFile)) {
http_response_code(500);
echo json_encode(["error" => "Repurpose prompt file not found on server."]);
exit;
}
$promptTemplate = file_get_contents($promptFile);
$prompt = str_replace('{{POST_TEXT}}', $postText, $promptTemplate);
$payload = json_encode([
"contents" => [["parts" => [["text" => $prompt]]]],
"generationConfig" => ["temperature" => 0.75, "maxOutputTokens" => 800]
]);
$ch = curl_init($geminiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
http_response_code(500);
echo json_encode(["error" => "Gemini API Error", "details" => json_decode($response)]);
exit;
}
$responseData = json_decode($response, true);
$resultText = trim($responseData['candidates'][0]['content']['parts'][0]['text'] ?? '');
if (empty($resultText)) {
http_response_code(500);
echo json_encode(["error" => "Empty result from AI."]);
exit;
}
echo json_encode(["success" => true, "result" => $resultText]);
exit;
}