diff --git a/api/oembed.php b/api/oembed.php index 401ab6f..3ea287f 100644 --- a/api/oembed.php +++ b/api/oembed.php @@ -25,9 +25,11 @@ class OembedHandler extends BaseHandler if (!$relativePath) $this->sendErrorResponse('Invalid url', 400); $relativePath = '/' . ltrim($relativePath ?? '', '/'); + if ($relativePath !== '/' && str_ends_with($relativePath, '/')) $relativePath = rtrim($relativePath, '/'); $cacheKey = 'oembed:' . md5($relativePath); + if ($this->cache && $this->cache->exists($cacheKey)) { $cachedItem = json_decode($this->cache->get($cacheKey), true); $this->sendResponse($this->buildResponse( @@ -42,6 +44,7 @@ class OembedHandler extends BaseHandler $results = $this->fetchFromApi('optimized_oembed', 'url=eq.' . urlencode($relativePath)); if (!empty($results)) { $item = $results[0]; + if ($this->cache) $this->cache->setex($cacheKey, 300, json_encode($item)); $this->sendResponse($this->buildResponse( @@ -56,6 +59,7 @@ class OembedHandler extends BaseHandler $segments = explode('/', trim($relativePath, '/')); if (count($segments) === 1 && $segments[0] !== '') { $title = ucwords(str_replace('-', ' ', $segments[0])) . ' • ' . $globals['author']; + $this->sendResponse($this->buildResponse( $title, $relativePath, @@ -71,6 +75,7 @@ class OembedHandler extends BaseHandler { $safeDescription = truncateText(strip_tags(parseMarkdown($description)), 175); $html = '
' . htmlspecialchars($title) . '
'; + if ($description) $html .= '' . htmlspecialchars($safeDescription, ENT_QUOTES, 'UTF-8') . '
'; return [ @@ -89,6 +94,7 @@ class OembedHandler extends BaseHandler private function fetchGlobals(): array { $cacheKey = 'globals_data'; + if ($this->cache && $this->cache->exists($cacheKey)) return json_decode($this->cache->get($cacheKey), true); $globals = $this->fetchFromApi('optimized_globals', 'limit=1')[0] ?? [ @@ -97,6 +103,7 @@ class OembedHandler extends BaseHandler 'url' => 'https://www.coryd.dev', 'avatar' => '' ]; + if ($this->cache) $this->cache->setex($cacheKey, 3600, json_encode($globals)); return $globals; diff --git a/package-lock.json b/package-lock.json index 5e800a1..bdf78dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "coryd.dev", - "version": "5.1.3", + "version": "5.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "coryd.dev", - "version": "5.1.3", + "version": "5.1.4", "license": "MIT", "dependencies": { "html-minifier-terser": "7.2.0", @@ -1737,9 +1737,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.154", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.154.tgz", - "integrity": "sha512-G4VCFAyKbp1QJ+sWdXYIRYsPGvlV5sDACfCmoMFog3rjm1syLhI41WXm/swZypwCIWIm4IFLWzHY14joWMQ5Fw==", + "version": "1.5.155", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.155.tgz", + "integrity": "sha512-ps5KcGGmwL8VaeJlvlDlu4fORQpv3+GIcF5I3f9tUKUlJ/wsysh6HU8P5L1XWRYeXfA0oJd4PyM8ds8zTFf6Ng==", "dev": true, "license": "ISC" }, diff --git a/package.json b/package.json index 5069a01..0eb90a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "5.1.3", + "version": "5.1.4", "description": "The source for my personal site. Built using 11ty (and other tools).", "type": "module", "engines": {