fix(oembed.php): generic response for root request
This commit is contained in:
parent
df63ad1799
commit
dd8369af04
3 changed files with 17 additions and 6 deletions
|
@ -10,15 +10,26 @@ class OembedHandler extends BaseHandler
|
||||||
public function handleRequest(): void
|
public function handleRequest(): void
|
||||||
{
|
{
|
||||||
$requestUrl = $_GET['url'] ?? null;
|
$requestUrl = $_GET['url'] ?? null;
|
||||||
if (!$requestUrl) $this->sendErrorResponse('Missing url parameter', 400);
|
$globals = $this->fetchGlobals();
|
||||||
|
|
||||||
|
if (!$requestUrl) {
|
||||||
|
$this->sendResponse([
|
||||||
|
'version' => '1.0',
|
||||||
|
'type' => 'link',
|
||||||
|
'title' => $globals['site_name'],
|
||||||
|
'author_name' => $globals['author'],
|
||||||
|
'provider_name' => $globals['site_name'],
|
||||||
|
'provider_url' => $globals['url'],
|
||||||
|
'thumbnail_url' => $globals['url'] . '/og/w800' . $globals['avatar'],
|
||||||
|
'html' => '<a href="' . $globals['url'] . '">' . $globals['site_name'] . '</a>',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$parsed = parse_url($requestUrl);
|
$parsed = parse_url($requestUrl);
|
||||||
$relativePath = $parsed['path'] ?? null;
|
$relativePath = $parsed['path'] ?? null;
|
||||||
if (!$relativePath) $this->sendErrorResponse('Invalid url', 400);
|
if (!$relativePath) $this->sendErrorResponse('Invalid url', 400);
|
||||||
if ($relativePath !== '/' && str_ends_with($relativePath, '/')) $relativePath = rtrim($relativePath, '/');
|
if ($relativePath !== '/' && str_ends_with($relativePath, '/')) $relativePath = rtrim($relativePath, '/');
|
||||||
|
|
||||||
$globals = $this->fetchGlobals();
|
|
||||||
|
|
||||||
$results = $this->fetchFromApi('optimized_oembed', 'url=eq.' . urlencode($relativePath));
|
$results = $this->fetchFromApi('optimized_oembed', 'url=eq.' . urlencode($relativePath));
|
||||||
if (!empty($results)) {
|
if (!empty($results)) {
|
||||||
$item = $results[0];
|
$item = $results[0];
|
||||||
|
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "4.0.1",
|
"version": "4.0.2",
|
||||||
"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.1",
|
"version": "4.0.2",
|
||||||
"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": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue