build: switch from yarn to npm to manage js dependencies and move js contents to root

yarn v1 is being deprecated and starts to have some issues

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-11-14 17:24:42 +01:00
parent 32055122c3
commit 2e72f6faf4
595 changed files with 12078 additions and 7843 deletions

46
src/utils/image.ts Normal file
View File

@@ -0,0 +1,46 @@
import { IMedia } from "@/types/media.model";
export async function buildFileFromIMedia(
obj: IMedia | null | undefined
): Promise<File | null> {
if (!obj) return Promise.resolve(null);
const response = await fetch(obj.url);
const blob = await response.blob();
return new File([blob], obj.name);
}
export function buildFileVariable(
file: File | null,
name: string,
alt?: string
): Record<string, unknown> {
if (!file) return {};
return {
[name]: {
media: {
name: file.name,
alt: alt || file.name,
file,
},
},
};
}
export function readFileAsync(
file: File
): Promise<string | ArrayBuffer | null> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
resolve(reader.result);
};
reader.onerror = reject;
reader.readAsBinaryString(file);
});
}