Commit 055dd94f authored by Mahmoud Aglan's avatar Mahmoud Aglan

coco

parent b98c1c14
......@@ -558,7 +558,9 @@ class TutorialController extends Controller
public function exportPdf(Request $request): Response
{
set_time_limit(480);
set_time_limit(1800);
$dlToken = $_GET['dl'] ?? '';
$screenshotsPath = realpath(__DIR__ . '/../../../../public/assets/tutorials/screenshots');
$viewsPath = realpath(__DIR__ . '/../Views');
......@@ -605,6 +607,10 @@ class TutorialController extends Controller
$pdfContent = file_get_contents($tmpOutput);
@unlink($tmpOutput);
if ($dlToken) {
setcookie('book_download', $dlToken, time() + 120, '/');
}
$response = new Response();
return $response->html($pdfContent, 200)->withHeaders([
'Content-Type' => 'application/pdf',
......@@ -615,6 +621,10 @@ class TutorialController extends Controller
@unlink($tmpOutput);
}
if ($dlToken) {
setcookie('book_download', $dlToken, time() + 120, '/');
}
$response = new Response();
return $response->html($html, 200)->withHeaders([
'Content-Type' => 'text/html; charset=utf-8',
......
......@@ -127,14 +127,20 @@
<script>
var exportSteps = [
{ pct: 5, label: 'تحضير البيانات...' },
{ pct: 15, label: 'تجميع شروحات العضوية...' },
{ pct: 30, label: 'تجميع شروحات الأنشطة الرياضية...' },
{ pct: 45, label: 'تجميع شروحات الخزنة...' },
{ pct: 55, label: 'تجميع باقي الأقسام...' },
{ pct: 70, label: 'تضمين لقطات الشاشة...' },
{ pct: 85, label: 'توليد ملف PDF...' },
{ pct: 92, label: 'تجهيز التحميل...' },
{ pct: 12, label: 'تجميع شروحات العضوية...' },
{ pct: 20, label: 'تجميع شروحات الأنشطة الرياضية...' },
{ pct: 28, label: 'تجميع شروحات الخزنة...' },
{ pct: 35, label: 'تجميع باقي الأقسام...' },
{ pct: 45, label: 'تضمين لقطات الشاشة...' },
{ pct: 55, label: 'توليد ملف PDF...' },
{ pct: 65, label: 'معالجة الصفحات...' },
{ pct: 72, label: 'تنسيق المحتوى...' },
{ pct: 80, label: 'ضغط الملف...' },
{ pct: 88, label: 'المراجعة النهائية...' },
{ pct: 94, label: 'جاري الانتهاء...' },
];
var stepTimer = null;
var cookieTimer = null;
function startExport() {
document.getElementById('beforeExport').style.display = 'none';
......@@ -155,42 +161,47 @@ function startExport() {
progressStep.textContent = step.label;
stepIndex++;
if (stepIndex < exportSteps.length) {
setTimeout(animateStep, 8000);
stepTimer = setTimeout(animateStep, 90000);
}
}
animateStep();
fetch('/tutorials/export-pdf')
.then(function(response) {
if (!response.ok) throw new Error('HTTP ' + response.status);
return response.blob();
})
.then(function(blob) {
// Use hidden iframe — browsers don't timeout iframe downloads
var token = Date.now().toString();
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.setAttribute('id', 'exportFrame');
iframe.src = '/tutorials/export-pdf?dl=' + token;
document.body.appendChild(iframe);
// Poll for download cookie (set by server when response is sent)
cookieTimer = setInterval(function() {
if (document.cookie.indexOf('book_download=' + token) !== -1) {
clearInterval(cookieTimer);
clearTimeout(stepTimer);
// Clear the cookie
document.cookie = 'book_download=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
progressBar.style.width = '100%';
progressLabel.textContent = '100%';
progressStep.textContent = 'اكتمل!';
var filename = 'Book-of-the-ERP.pdf';
if (blob.type && blob.type.indexOf('html') !== -1) {
filename = 'Book-of-the-ERP.html';
}
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}, 100);
setTimeout(function() { finishExport(true); }, 600);
})
.catch(function(err) {
document.getElementById('errorMessage').textContent = 'فشل التصدير: ' + err.message;
progressStep.textContent = 'اكتمل! تم التحميل ✓';
setTimeout(function() { finishExport(true); }, 1500);
// Clean up iframe
var f = document.getElementById('exportFrame');
if (f) setTimeout(function() { f.remove(); }, 5000);
}
}, 2000);
// Safety timeout: 25 minutes max
setTimeout(function() {
if (document.getElementById('duringExport').style.display !== 'none') {
clearInterval(cookieTimer);
clearTimeout(stepTimer);
document.getElementById('errorMessage').textContent = 'انتهت المهلة. قد يكون الملف قد تم تحميله — تحقق من مجلد التنزيلات.';
finishExport(false);
});
var f = document.getElementById('exportFrame');
if (f) f.remove();
}
}, 1500000);
}
function finishExport(success) {
......@@ -208,6 +219,8 @@ function resetExport() {
document.getElementById('afterExport').style.display = 'none';
document.getElementById('errorExport').style.display = 'none';
document.getElementById('progressBar').style.width = '0%';
clearInterval(cookieTimer);
clearTimeout(stepTimer);
}
document.addEventListener('DOMContentLoaded', function() {
......
......@@ -3,7 +3,7 @@
DocumentRoot /var/www/html/public
# Allow long-running requests (PDF generation)
TimeOut 480
TimeOut 1800
<Directory /var/www/html/public>
Options -Indexes +FollowSymLinks
......
......@@ -3,7 +3,7 @@
upload_max_filesize = 20M
post_max_size = 25M
memory_limit = 1024M
max_execution_time = 480
max_execution_time = 1800
max_input_time = 240
max_input_vars = 5000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment