| 123456789101112131415161718192021222324252627282930313233343536 |
- import ApiRequestService from "./apiRequestService";
- import ImageUtils from "~/services/utils/imageUtils";
- class ImageManager {
- private apiRequestService: ApiRequestService;
- public constructor(apiRequestService: ApiRequestService) {
- this.apiRequestService = apiRequestService
- }
- public async get(id: number, height: number = 0, width: number = 0) {
- let url = `api/download/${id}`
- // Set requested size if needed
- if (height > 0 || width > 0) {
- // @see https://thumbor.readthedocs.io/en/latest/crop_and_resize_algorithms.html
- // TODO: ajouter le support de ces options dans ap2i
- // url = Url.join(url, `${height}x${width}`)
- }
- // Une image doit toujours avoir le time en options pour éviter les problème de cache
- const query = [new Date().getTime().toString()]
- const response: any = await this.apiRequestService.get(url, query)
- if(!response.data || response.data.size === 0) {
- throw new Error('Error: image not found or invalid')
- }
- const blob = await ImageUtils.newBlob(response.data)
- return await ImageUtils.blobToBase64(blob);
- }
- }
- export default ImageManager
|