Browse Source

fix imageManager blobToBase64 method, and minor fixes

Olivier Massot 2 years ago
parent
commit
74b3f6f259

+ 1 - 1
components/Layout/Subheader.vue

@@ -92,7 +92,7 @@ main {
 }
 
 .switch-btn {
-  border-width: 1px 1px 1px 0;
+  border-width: 1px;
   border-style: solid;
 }
 </style>

+ 3 - 3
components/Ui/Image.vue

@@ -13,7 +13,6 @@ Si la propriété 'upload' est à 'true', propose aussi un input pour uploader u
         :height="height"
         :width="width"
         aspect-ratio="1"
-        @click="refresh"
       >
         <template #placeholder>
           <v-row
@@ -53,6 +52,7 @@ import {ref, Ref} from "@vue/reactivity";
 import {useImageFetch} from "~/composables/data/useImageFetch";
 import {onUnmounted, watch, WatchStopHandle} from "@vue/runtime-core";
 import {useImageManager} from "~/composables/data/useImageManager";
+import ImageManager from "~/services/data/imageManager";
 
 const props = defineProps({
   id: {
@@ -90,7 +90,7 @@ const props = defineProps({
 const { imageManager } = useImageManager()
 const { fetch } = useImageFetch()
 
-const defaultImagePath = props.defaultImage ?? imageManager.defaultImage
+const defaultImagePath = props.defaultImage ?? ImageManager.defaultImage
 
 const openUpload: Ref<Boolean> = ref(false)
 
@@ -114,7 +114,7 @@ const reset = () => {
 }
 
 /**
- * Lorsqu'on démonte le component on supprime le watcher
+ * Lorsqu'on démonte le component, on supprime le watcher
  */
 onUnmounted(() => {
   unwatch()

+ 1 - 1
services/data/imageManager.ts

@@ -66,7 +66,7 @@ class ImageManager {
      */
     protected async toBase64(data: string) {
         const blob = ImageUtils.newBlob(data)
-        return  await ImageUtils.blobToBase64(blob) ?? ''
+        return await ImageUtils.blobToBase64(blob) ?? ''
     }
 
     /**

+ 8 - 3
services/utils/imageUtils.ts

@@ -1,3 +1,5 @@
+import SysUtils from "~/services/utils/SysUtils";
+
 /**
  * Manipulation des images
  */
@@ -18,9 +20,12 @@ class ImageUtils {
      * @param {Blob} blob
      */
     public static async blobToBase64(blob: Blob): Promise<string> {
-        // /!\ Attention: lors de tests unitaires, 'blob.text' plantera si utilisée en même temps que vi.useFakeTimers()
-        const content = Buffer.from(await blob.text()).toString('base64');
-        return `data:${blob.type};base64,${content}`
+        return new Promise((resolve, _) => {
+            const reader = new FileReader();
+            // @ts-ignore
+            reader.onloadend = () => resolve(reader.result);
+            reader.readAsDataURL(blob);
+        });
     }
 }
 export default ImageUtils