fix(oembed.php + og-image.php): route oembed images through proxy
This commit is contained in:
parent
ec03d7ccef
commit
f05a1d2a8b
5 changed files with 25 additions and 21 deletions
|
@ -1,17 +1,24 @@
|
|||
<?php
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
$class = $_GET['class'] ?? null;
|
||||
$version = $_GET['v'] ?? null;
|
||||
$extension = $_GET['extension'] ?? 'png';
|
||||
$isValidId = is_string($id) && preg_match('/^[a-f0-9\-]{36}$/', $id);
|
||||
|
||||
if (!$isValidId || !$class) {
|
||||
$isValidId = is_string($id) && preg_match('/^[a-f0-9\-]{36}$/', $id);
|
||||
$isValidClass = is_string($class) && preg_match('/^w\d{2,4}$/', $class);
|
||||
|
||||
if (!$isValidId || !$isValidClass) {
|
||||
header("Location: /404", true, 302);
|
||||
exit;
|
||||
}
|
||||
|
||||
$cdnUrl = "https://cdn.coryd.dev/$id.$extension?class=$class";
|
||||
$ch = curl_init($cdnUrl);
|
||||
$cdnBase = "https://cdn.coryd.dev/og/$class";
|
||||
$cdnUrl = $version
|
||||
? "$cdnBase/$version/$id.$extension"
|
||||
: "$cdnBase/$id.$extension";
|
||||
|
||||
$ch = curl_init($cdnUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
||||
|
@ -22,19 +29,11 @@
|
|||
|
||||
curl_close($ch);
|
||||
|
||||
error_log("CDN response code: $httpCode, Content-Type: $contentType");
|
||||
|
||||
if ($httpCode !== 200 || $image === false) {
|
||||
error_log("Failed to fetch image: $cdnUrl");
|
||||
if ($httpCode !== 200 || $image === false || strpos($contentType, 'image/') !== 0) {
|
||||
error_log("Failed to fetch image: $cdnUrl ($httpCode - $contentType)");
|
||||
header("Location: /404", true, 302);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strpos($contentType, 'image/') === 0) {
|
||||
header("Content-Type: $contentType");
|
||||
echo $image;
|
||||
} else {
|
||||
error_log("Invalid content type: $contentType");
|
||||
header("Location: /404", true, 302);
|
||||
exit;
|
||||
}
|
||||
header("Content-Type: $contentType");
|
||||
echo $image;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue