From 1924c232fbea4327f27e103a3c32f69d2e36e149 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 21 Mar 2024 19:58:12 -0400 Subject: [PATCH] fix: Enable use of self-hosted Iframely without API key closes #6694 --- plugins/iframely/server/iframely.ts | 12 ++++++++---- plugins/iframely/server/index.ts | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/iframely/server/iframely.ts b/plugins/iframely/server/iframely.ts index bcba36122..c0247df64 100644 --- a/plugins/iframely/server/iframely.ts +++ b/plugins/iframely/server/iframely.ts @@ -4,14 +4,18 @@ import fetch from "@server/utils/fetch"; import env from "./env"; class Iframely { - private static apiUrl = `${env.IFRAMELY_URL}/api`; - private static apiKey = env.IFRAMELY_API_KEY; + public static defaultUrl = "https://iframe.ly"; public static async fetch(url: string, type = "oembed") { + const isDefaultHost = env.IFRAMELY_URL === this.defaultUrl; + + // Cloud Iframely requires /api path, while self-hosted does not. + const apiUrl = isDefaultHost ? `${env.IFRAMELY_URL}/api` : env.IFRAMELY_URL; + try { const res = await fetch( - `${this.apiUrl}/${type}?url=${encodeURIComponent(url)}&api_key=${ - this.apiKey + `${apiUrl}/${type}?url=${encodeURIComponent(url)}&api_key=${ + env.IFRAMELY_API_KEY }` ); return res.json(); diff --git a/plugins/iframely/server/index.ts b/plugins/iframely/server/index.ts index 15f5a0b3d..d9bb0a449 100644 --- a/plugins/iframely/server/index.ts +++ b/plugins/iframely/server/index.ts @@ -7,7 +7,8 @@ import { import env from "./env"; import Iframely from "./iframely"; -const enabled = !!env.IFRAMELY_API_KEY && !!env.IFRAMELY_URL; +const isDefaultHost = env.IFRAMELY_URL === Iframely.defaultUrl; +const enabled = (isDefaultHost && !!env.IFRAMELY_API_KEY) || !!env.IFRAMELY_URL; if (enabled) { PluginManager.add([