migrate frontend

This commit is contained in:
LeeShuang
2021-12-08 23:43:52 +08:00
parent 2f72bfa946
commit 06bffd0ba5
145 changed files with 11409 additions and 0 deletions

View File

@ -0,0 +1,21 @@
const cachedResource = new Map<string, string>();
function convertResourceToDataURL(url: string, useCache = true): Promise<string> {
if (useCache && cachedResource.has(url)) {
return Promise.resolve(cachedResource.get(url) as string);
}
return new Promise(async (resolve) => {
const res = await fetch(url);
const blob = await res.blob();
var reader = new FileReader();
reader.onloadend = () => {
const base64Url = reader.result as string;
cachedResource.set(url, base64Url);
resolve(base64Url);
};
reader.readAsDataURL(blob);
});
}
export default convertResourceToDataURL;