[Plugin] Basic, non-functional implementation

This commit is contained in:
Beef 2023-01-03 00:18:19 +00:00
parent d0f4e87475
commit 7465e42354
6 changed files with 157 additions and 0 deletions

24
src/lib/plugins.ts Normal file
View file

@ -0,0 +1,24 @@
import { Indexable, PluginManifest, Plugin } from "@types";
export const plugins: Indexable<Plugin> = {};
export async function fetchPlugin(url: string) {
if (!url.endsWith("/")) url += "/";
if (plugins[url]) throw new Error(`That plugin is already installed!`);
let pluginManifest: PluginManifest;
try {
pluginManifest = await (await fetch(new URL("manifest.json", url), { cache: "no-store" })).json();
} catch {
throw new Error(`Failed to fetch manifest for ${url}`);
}
plugins[url] = {
id: url.split("://")[1],
manifest: pluginManifest,
enabled: true,
js: "",
};
}