-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboot.php
68 lines (60 loc) · 2.64 KB
/
boot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
if (rex::isBackend() && rex::getUser()) {
// Add JavaScript to ffmpeg page
if (rex_be_controller::getCurrentPagePart(2) == 'ffmpeg') {
rex_view::addJsFile(rex_addon::get('ffmpeg')->getAssetsUrl('js/script.js'));
rex_view::addCssFile(rex_addon::get('ffmpeg')->getAssetsUrl('css/style.css'));
}
// Create session variables if needed
if (is_null(rex_session('ffmpeg_uid', 'string', null))) {
rex_set_session('ffmpeg_uid', uniqid());
}
// Sicherstellen, dass die Datenverzeichnisse existieren
$dataPath = rex_addon::get('ffmpeg')->getDataPath();
if (!file_exists($dataPath)) {
mkdir($dataPath, 0777, true);
}
// Veraltete Status- und Log-Dateien aufräumen (älter als 7 Tage)
$cleanupTime = time() - (7 * 24 * 60 * 60); // 7 Tage
// Status-Dateien aufräumen
$statusFiles = glob($dataPath . 'status_*.json');
if ($statusFiles) {
foreach ($statusFiles as $file) {
if (filemtime($file) < $cleanupTime) {
@unlink($file);
}
}
}
// Log-Dateien aufräumen
$logFiles = glob($dataPath . 'log*.txt');
if ($logFiles) {
foreach ($logFiles as $file) {
if (filemtime($file) < $cleanupTime) {
@unlink($file);
}
}
}
// Prüfen auf aktive Konvertierungen ohne Session
// Wenn ein Video gerade konvertiert wird, aber die Session abgelaufen ist,
// kann durch diese Prüfung trotzdem der Status abgefragt werden
if (rex_be_controller::getCurrentPagePart(2) == 'ffmpeg' && !rex_session('ffmpeg_conversion_id')) {
$statusFiles = glob($dataPath . 'status_*.json');
if ($statusFiles) {
foreach ($statusFiles as $file) {
// Nur Dateien prüfen, die in den letzten 30 Minuten geändert wurden
if (filemtime($file) > time() - 1800) {
$statusData = json_decode(file_get_contents($file), true);
if ($statusData && isset($statusData['status']) &&
$statusData['status'] !== 'done' && $statusData['status'] !== 'error') {
// Aktive Konvertierung gefunden, Session-Variablen wiederherstellen
if (isset($statusData['conversion_id'])) {
rex_set_session('ffmpeg_conversion_id', $statusData['conversion_id']);
rex_set_session('ffmpeg_conversion_status', $statusData['status']);
break;
}
}
}
}
}
}
}