feat: pipe external urls through iframely
This commit is contained in:
5
plugins/iframely/plugin.json
Normal file
5
plugins/iframely/plugin.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "Iframely",
|
||||
"description": "Integrate Iframely to enable unfurling of arbitrary urls",
|
||||
"requiredEnvVars": ["IFRAMELY_URL", "IFRAMELY_API_KEY"]
|
||||
}
|
||||
3
plugins/iframely/server/.babelrc
Normal file
3
plugins/iframely/server/.babelrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../../server/.babelrc"
|
||||
}
|
||||
24
plugins/iframely/server/iframely.ts
Normal file
24
plugins/iframely/server/iframely.ts
Normal 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;
|
||||
3
plugins/iframely/server/unfurl.ts
Normal file
3
plugins/iframely/server/unfurl.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import Iframely from "./iframely";
|
||||
|
||||
export const unfurl = async (url: string) => Iframely.get(url);
|
||||
Reference in New Issue
Block a user