mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 00:10:07 +00:00
* Fix rest proxy not working with files * Fix some credits * Add tests * Fix test * Remove some usage of any * Fix mime matching * Fix formatting issues
10 lines
387 B
TypeScript
10 lines
387 B
TypeScript
import { encode } from "./base64.ts";
|
|
|
|
/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */
|
|
export async function urlToBase64(url: string) {
|
|
const buffer = await fetch(url).then((res) => res.arrayBuffer());
|
|
const imageStr = encode(buffer);
|
|
const type = url.substring(url.lastIndexOf(".") + 1);
|
|
return `data:image/${type};base64,${imageStr}`;
|
|
}
|