|
2 | 2 | import { useBase64 } from '@vueuse/core';
|
3 | 3 | import type { Ref } from 'vue';
|
4 | 4 | import { useCopy } from '@/composable/copy';
|
5 |
| -import { getExtensionFromMimeType, getMimeTypeFromBase64, useDownloadFileFromBase64Refs } from '@/composable/downloadBase64'; |
| 5 | +import { getExtensionFromMimeType, getMimeTypeFromBase64, previewImageFromBase64, useDownloadFileFromBase64Refs } from '@/composable/downloadBase64'; |
6 | 6 | import { useValidation } from '@/composable/validation';
|
7 | 7 | import { isValidBase64 } from '@/utils/base64';
|
8 | 8 |
|
@@ -35,6 +35,25 @@ watch(
|
35 | 35 | },
|
36 | 36 | );
|
37 | 37 |
|
| 38 | +function previewImage() { |
| 39 | + if (!base64InputValidation.isValid) { |
| 40 | + return; |
| 41 | + } |
| 42 | + try { |
| 43 | + const image = previewImageFromBase64(base64Input.value); |
| 44 | + image.style.maxWidth = '100%'; |
| 45 | + image.style.maxHeight = '400px'; |
| 46 | + const previewContainer = document.getElementById('previewContainer'); |
| 47 | + if (previewContainer) { |
| 48 | + previewContainer.innerHTML = ''; |
| 49 | + previewContainer.appendChild(image); |
| 50 | + } |
| 51 | + } |
| 52 | + catch (_) { |
| 53 | + // |
| 54 | + } |
| 55 | +} |
| 56 | +
|
38 | 57 | function downloadFile() {
|
39 | 58 | if (!base64InputValidation.isValid) {
|
40 | 59 | return;
|
@@ -88,7 +107,14 @@ async function onUpload(file: File) {
|
88 | 107 | mb-2
|
89 | 108 | />
|
90 | 109 |
|
91 |
| - <div flex justify-center> |
| 110 | + <div flex justify-center py-2> |
| 111 | + <div id="previewContainer" /> |
| 112 | + </div> |
| 113 | + |
| 114 | + <div flex justify-center gap-3> |
| 115 | + <c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="previewImage()"> |
| 116 | + Preview image |
| 117 | + </c-button> |
92 | 118 | <c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="downloadFile()">
|
93 | 119 | Download file
|
94 | 120 | </c-button>
|
|
0 commit comments