Prepare front to edit events
This commit is contained in:
24
js/src/utils/image.ts
Normal file
24
js/src/utils/image.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { IPicture } from '@/types/picture.model';
|
||||
|
||||
export async function buildFileFromIPicture(obj: IPicture | null) {
|
||||
if (!obj) return null;
|
||||
|
||||
const response = await fetch(obj.url);
|
||||
const blob = await response.blob();
|
||||
|
||||
return new File([blob], obj.name);
|
||||
}
|
||||
|
||||
export function buildFileVariable<T>(file: File | null, name: string, alt?: string) {
|
||||
if (!file) return {};
|
||||
|
||||
return {
|
||||
[name]: {
|
||||
picture: {
|
||||
name: file.name,
|
||||
alt: alt || file.name,
|
||||
file,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
5
js/src/utils/object.ts
Normal file
5
js/src/utils/object.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function buildObjectCollection<T, U>(collection: T[] | undefined, builder: (new (p: T) => U)) {
|
||||
if (!collection || Array.isArray(collection) === false) return [];
|
||||
|
||||
return collection.map(v => new builder(v));
|
||||
}
|
||||
Reference in New Issue
Block a user