fix(oembed.php + og-image.php): route oembed images through proxy
This commit is contained in:
parent
ec03d7ccef
commit
df63ad1799
5 changed files with 17 additions and 18 deletions
|
@ -29,7 +29,7 @@ class OembedHandler extends BaseHandler
|
||||||
'author_name' => $globals['author'],
|
'author_name' => $globals['author'],
|
||||||
'provider_name' => $globals['site_name'],
|
'provider_name' => $globals['site_name'],
|
||||||
'provider_url' => $globals['url'],
|
'provider_url' => $globals['url'],
|
||||||
'thumbnail_url' => $globals['url'] . $item['image_url'],
|
'thumbnail_url' => $globals['url'] . '/og/w800' . $item['image_url'],
|
||||||
'html' => '<a href="' . htmlspecialchars($item['url']) . '">' . htmlspecialchars($item['title']) . '</a>',
|
'html' => '<a href="' . htmlspecialchars($item['url']) . '">' . htmlspecialchars($item['title']) . '</a>',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class OembedHandler extends BaseHandler
|
||||||
'author_name' => $globals['author'],
|
'author_name' => $globals['author'],
|
||||||
'provider_name' => $globals['site_name'],
|
'provider_name' => $globals['site_name'],
|
||||||
'provider_url' => $globals['url'],
|
'provider_url' => $globals['url'],
|
||||||
'thumbnail_url' => $globals['url'] . $globals['avatar'],
|
'thumbnail_url' => $globals['url'] . '/og/w800' . $globals['avatar'],
|
||||||
'html' => '<a href="' . htmlspecialchars($relativePath) . '">' . htmlspecialchars($title) . '</a>',
|
'html' => '<a href="' . htmlspecialchars($relativePath) . '">' . htmlspecialchars($title) . '</a>',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$id = $_GET['id'] ?? null;
|
$id = $_GET['id'] ?? null;
|
||||||
$class = $_GET['class'] ?? null;
|
$class = $_GET['class'] ?? null;
|
||||||
$extension = $_GET['extension'] ?? 'png';
|
$extension = $_GET['extension'] ?? 'png';
|
||||||
$isValidId = is_string($id) && preg_match('/^[a-f0-9\-]{36}$/', $id);
|
$isValidId = is_string($id) && preg_match('/^[a-f0-9\-]{36}$/', $id);
|
||||||
|
$isValidClass = is_string($class) && preg_match('/^w\d{2,4}$/', $class);
|
||||||
|
|
||||||
if (!$isValidId || !$class) {
|
if (!$isValidId || !$isValidClass) {
|
||||||
header("Location: /404", true, 302);
|
header("Location: /404", true, 302);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -22,19 +24,11 @@
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
error_log("CDN response code: $httpCode, Content-Type: $contentType");
|
if ($httpCode !== 200 || $image === false || strpos($contentType, 'image/') !== 0) {
|
||||||
|
error_log("Failed to fetch image: $cdnUrl ($httpCode - $contentType)");
|
||||||
if ($httpCode !== 200 || $image === false) {
|
|
||||||
error_log("Failed to fetch image: $cdnUrl");
|
|
||||||
header("Location: /404", true, 302);
|
header("Location: /404", true, 302);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($contentType, 'image/') === 0) {
|
header("Content-Type: $contentType");
|
||||||
header("Content-Type: $contentType");
|
echo $image;
|
||||||
echo $image;
|
|
||||||
} else {
|
|
||||||
error_log("Invalid content type: $contentType");
|
|
||||||
header("Location: /404", true, 302);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"html-minifier-terser": "7.2.0",
|
"html-minifier-terser": "7.2.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -48,6 +48,11 @@ RewriteRule ^music/genres/([^/]+)/?$ music/genres/index.php [L]
|
||||||
RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/index.php [L]
|
RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/index.php [L]
|
||||||
|
|
||||||
## open graph assets
|
## open graph assets
|
||||||
|
|
||||||
|
# w/out version
|
||||||
|
RewriteRule ^og/([a-z0-9\-]+)/([a-f0-9\-]+)\.([a-z0-9]+)$ /api/og-image.php?id=$2&class=$1&extension=$3 [L]
|
||||||
|
|
||||||
|
# w/version
|
||||||
RewriteRule ^og/([a-z0-9\-]+)/([\d\.]+)/([a-f0-9\-]+)\.([a-z0-9]+)$ /api/og-image.php?id=$3&class=$1&v=$2&extension=$4 [L]
|
RewriteRule ^og/([a-z0-9\-]+)/([\d\.]+)/([a-f0-9\-]+)\.([a-z0-9]+)$ /api/og-image.php?id=$3&class=$1&v=$2&extension=$4 [L]
|
||||||
|
|
||||||
## oembed
|
## oembed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue