mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-21 15:26:15 -04:00
refactor(base64): split base64 text and file conversion in two tools + base64 to file
This commit is contained in:
parent
a70a0f83a1
commit
e6953d1b67
8 changed files with 117 additions and 21 deletions
|
@ -1,11 +1,17 @@
|
|||
import { extension as getExtensionFromMime } from 'mime-types';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
export function useDownloadFileFromBase64({ source, filename = 'file' }: { source: Ref<string>; filename?: string }) {
|
||||
export function useDownloadFileFromBase64({ source, filename }: { source: Ref<string>; filename?: string }) {
|
||||
return {
|
||||
download() {
|
||||
const base64 = source.value;
|
||||
const mimeType = base64.match(/data:(.*?);base64/i)?.[1] ?? 'text/plain';
|
||||
console.log({ mimeType });
|
||||
const cleanFileName = filename ?? `file.${getExtensionFromMime(mimeType)}`;
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = source.value;
|
||||
a.download = filename;
|
||||
a.download = cleanFileName;
|
||||
a.click();
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue