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
|
||||
{
|
||||
$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);
|
||||
$relativePath = $parsed['path'] ?? null;
|
||||
if (!$relativePath) $this->sendErrorResponse('Invalid url', 400);
|
||||
if ($relativePath !== '/' && str_ends_with($relativePath, '/')) $relativePath = rtrim($relativePath, '/');
|
||||
|
||||
$globals = $this->fetchGlobals();
|
||||
|
||||
$results = $this->fetchFromApi('optimized_oembed', 'url=eq.' . urlencode($relativePath));
|
||||
if (!empty($results)) {
|
||||
$item = $results[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue