mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
fix: update downloadbase64
This commit is contained in:
parent
1b95877e45
commit
fbb362d544
2 changed files with 16 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
||||||
import type { Ref } from 'vue';
|
import type { MaybeRef, Ref } from 'vue';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { get } from '@vueuse/core';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getMimeTypeFromBase64,
|
getMimeTypeFromBase64,
|
||||||
|
@ -75,21 +76,11 @@ function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
||||||
}
|
}
|
||||||
|
|
||||||
function useDownloadFileFromBase64(
|
function useDownloadFileFromBase64(
|
||||||
{ source, filename, extension, fileMimeType }:
|
|
||||||
{ source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) {
|
|
||||||
return {
|
|
||||||
download() {
|
|
||||||
downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function useDownloadFileFromBase64Refs(
|
|
||||||
{ source, filename, extension }:
|
{ source, filename, extension }:
|
||||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
{ source: MaybeRef<string>; filename?: MaybeRef<string>; extension?: MaybeRef<string> }) {
|
||||||
return {
|
return {
|
||||||
download() {
|
download() {
|
||||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
downloadFromBase64({ sourceValue: get(source), filename: get(filename), extension: get(extension) });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -116,3 +107,13 @@ function previewImageFromBase64(base64String: string): HTMLImageElement {
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useDownloadFileFromBase64Refs(
|
||||||
|
{ source, filename, extension }:
|
||||||
|
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||||
|
return {
|
||||||
|
download() {
|
||||||
|
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Base64 } from 'js-base64';
|
import { Base64 } from 'js-base64';
|
||||||
import heicConvert from 'heic-convert/browser';
|
import heicConvert from 'heic-convert/browser';
|
||||||
import { useDownloadFileFromBase64Refs } from '@/composable/downloadBase64';
|
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||||
|
|
||||||
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
|
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
|
||||||
const file = ref<File | null>(null);
|
const file = ref<File | null>(null);
|
||||||
|
@ -13,7 +13,7 @@ const formats = [
|
||||||
{ value: 'jpg', label: 'JPEG' },
|
{ value: 'jpg', label: 'JPEG' },
|
||||||
{ value: 'png', label: 'PNG' },
|
{ value: 'png', label: 'PNG' },
|
||||||
];
|
];
|
||||||
const { download } = useDownloadFileFromBase64Refs(
|
const { download } = useDownloadFileFromBase64(
|
||||||
{
|
{
|
||||||
source: base64OutputImage,
|
source: base64OutputImage,
|
||||||
filename: fileName,
|
filename: fileName,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue