fix: Enable use of self-hosted Iframely without API key

closes #6694
This commit is contained in:
Tom Moor
2024-03-21 19:58:12 -04:00
parent bd2b32f9d5
commit 1924c232fb
2 changed files with 10 additions and 5 deletions

View File

@@ -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();

View File

@@ -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([