Proxy.php hinzugefügt

This commit is contained in:
2026-07-17 20:11:18 +00:00
parent 7f0aaf81ec
commit 348e4dc21b
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* Fuyuzakura Cloud Proxy + Cache
*/
header('Access-Control-Allow-Origin: Domainname'); // Hier sollte immer nur ein Domainname stehen und am besten auch der, von dem ausgeführt wird
header('Access-Control-Allow-Methods: GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
// Preflight abfangen
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
$cacheFile = 'faq_cache.json'; // Hier kann auch ein andere Name stehen; wir haben uns für faq_cache entscheiden, sie muss nur genauso heißen wie in der Nextcloud
$cacheTime = 900; // 15 Minuten
$targetUrl ='NextcloudUlr mit download!';
$response = false;
if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < $cacheTime)) {
$response = file_get_contents($cacheFile);
}
if ($response === false) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $targetUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
$response = curl_exec($ch);
$curlError = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response !== false && $httpCode >= 200 && $httpCode < 300) {
file_put_contents($cacheFile, $response);
} else {
header('HTTP/1.1 500 Internal Server Error');
header('Content-Type: application/json; charset=utf-8');
echo json_encode([
'error' => 'Konnte Daten nicht von der Cloud laden.',
'http_status' => $httpCode,
'curl_error' => $curlError ? $curlError : 'Kein spezifischer cURL-Fehler. Cloud antwortete nicht mit HTTP 200.'
]);
exit;
}
}
header('Content-Type: application/json; charset=utf-8');
echo $response;