|
|
@@ -1,6 +1,6 @@
|
|
|
import ApiRequestService from './apiRequestService'
|
|
|
import FileUtils from '~/services/utils/fileUtils'
|
|
|
-import { FILE_TYPE, FILE_VISIBILITY } from '~/types/enum/enums'
|
|
|
+import { FILE_TYPE, FILE_VISIBILITY, IMAGE_SIZE } from '~/types/enum/enums'
|
|
|
|
|
|
/**
|
|
|
* Permet le requêtage, l'upload et la manipulation des images via l'API Opentalent
|
|
|
@@ -22,45 +22,34 @@ class ImageManager {
|
|
|
*
|
|
|
* @param id The id of the image; if null, the url to the default image is returned
|
|
|
* @param defaultImage The path of an image in the 'public' folder, default: '/images/default/picture.jpeg'
|
|
|
- * @param height Height of the image (does not apply to default image)
|
|
|
- * @param width Width of the image (does not apply to default image)
|
|
|
+ * @param size
|
|
|
*/
|
|
|
public async get(
|
|
|
id: number | null,
|
|
|
defaultImage: string | null = null,
|
|
|
- height: number = 0,
|
|
|
- width: number = 0,
|
|
|
- ): Promise<string | ArrayBuffer> {
|
|
|
+ size: IMAGE_SIZE = IMAGE_SIZE.MD
|
|
|
+ ): Promise<string> {
|
|
|
const defaultUrl = defaultImage ?? ImageManager.defaultImage
|
|
|
|
|
|
if (id === null) {
|
|
|
return defaultUrl
|
|
|
}
|
|
|
|
|
|
- const imageUrl = `api/file/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 = UrlUtils.join(url, `${height}x${width}`)
|
|
|
- }
|
|
|
+ const imageUrl = `api/image/download/${id}/${size}`
|
|
|
|
|
|
// Une image doit toujours avoir le time en options pour éviter les problèmes de cache
|
|
|
const query = [this.getCacheKey()]
|
|
|
|
|
|
- const blobPart = await this.apiRequestService.get(imageUrl, query);
|
|
|
- if (!blobPart) {
|
|
|
- console.error('Error: image ' + id + ' not found');
|
|
|
- return defaultUrl;
|
|
|
- }
|
|
|
+ const response = await this.apiRequestService.get(imageUrl, query);
|
|
|
+
|
|
|
+ const cachedImageUrl = response.toString()
|
|
|
|
|
|
- if (!(blobPart instanceof Blob) || blobPart.size === 0) {
|
|
|
- console.error('Error: image ' + id + ' is invalid');
|
|
|
+ if (!cachedImageUrl) {
|
|
|
+ console.error('Error: image ' + id + ' not found');
|
|
|
return defaultUrl;
|
|
|
}
|
|
|
|
|
|
- return await this.toBase64(blobPart)
|
|
|
+ return cachedImageUrl
|
|
|
}
|
|
|
|
|
|
public async upload(
|