feat: use downloadBlob util (#186)
* feat: use downloadBlob util * chore: lint * fix: revert saveCalAsPng * feat: refactor downloadBlob * chore: remove comments * chore: lint and remove extra async * refactor: cleanup --------- Co-authored-by: Razboy20 <razboy20@gmail.com>
This commit is contained in:
@@ -8,7 +8,10 @@ const MIMEType = {
|
||||
IMAGE: 'image/*',
|
||||
AUDIO: 'audio/*',
|
||||
VIDEO: 'video/*',
|
||||
CALENDAR: 'text/calendar',
|
||||
ANY: '*/*',
|
||||
} as const satisfies Record<string, string>;
|
||||
|
||||
export type MIMETypeKey = keyof typeof MIMEType;
|
||||
|
||||
export default MIMEType;
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import type { MIMETypeKey } from '../types/MIMEType';
|
||||
import MIMEType from '../types/MIMEType';
|
||||
|
||||
/**
|
||||
* Downloads a blob as a file.
|
||||
* @param {Blob} blob - The blob to download.
|
||||
* @param {string} fileName - The name of the file to be downloaded.
|
||||
* @returns {Promise<void>} - A promise that resolves when the download is complete.
|
||||
* Downloads a blob by creating a temporary URL and triggering a download.
|
||||
* @param blobPart The blob data to be downloaded.
|
||||
* @param type The MIME type of the blob.
|
||||
* @param fileName The name of the file to be downloaded.
|
||||
* @returns A promise that resolves when the download is successful, or rejects with an error if the download fails.
|
||||
*/
|
||||
export default function downloadBlob(blob: Blob, fileName: string): Promise<void> {
|
||||
export function downloadBlob(blobPart: BlobPart, type: MIMETypeKey, fileName: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const blob: Blob = new Blob([blobPart], { type: MIMEType[type] });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user