feat: pipe external urls through iframely

This commit is contained in:
Apoorv Mishra
2023-07-23 08:16:38 +05:30
parent 15c8a4867f
commit 43a91626b2
9 changed files with 98 additions and 13 deletions

View File

@@ -0,0 +1,5 @@
{
"name": "Iframely",
"description": "Integrate Iframely to enable unfurling of arbitrary urls",
"requiredEnvVars": ["IFRAMELY_URL", "IFRAMELY_API_KEY"]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "../../../server/.babelrc"
}

View File

@@ -0,0 +1,24 @@
import fetch from "fetch-with-proxy";
import env from "@server/env";
import { InvalidRequestError } from "@server/errors";
class Iframely {
private static apiUrl = `${env.IFRAMELY_URL}/api`;
private static apiKey = env.IFRAMELY_API_KEY;
public static async get(url: string, type = "oembed") {
try {
const res = await fetch(
`${this.apiUrl}/${type}?url=${encodeURIComponent(url)}&api_key=${
this.apiKey
}`
);
const data = await res.json();
return data;
} catch (err) {
throw InvalidRequestError(err);
}
}
}
export default Iframely;

View File

@@ -0,0 +1,3 @@
import Iframely from "./iframely";
export const unfurl = async (url: string) => Iframely.get(url);