mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-03-21 17:16:34 +03:00
optimizations
This commit is contained in:
@@ -1,11 +1,28 @@
|
||||
export const saveFile = (json: unknown, filename: string, extension: string) => {
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(json, null, 2)], {
|
||||
type: 'text/plain'
|
||||
})
|
||||
);
|
||||
anchor.download = 'emsesp_' + filename + extension;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(anchor.href);
|
||||
export const saveFile = (
|
||||
json: unknown,
|
||||
filename: string,
|
||||
extension: string
|
||||
): void => {
|
||||
try {
|
||||
const blob = new Blob([JSON.stringify(json, null, 2)], {
|
||||
type: 'application/json'
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = url;
|
||||
anchor.download = `emsesp_${filename}${extension}`;
|
||||
|
||||
// Trigger download
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
|
||||
// Delay revocation to ensure download starts properly
|
||||
setTimeout(() => {
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('Failed to save file:', error);
|
||||
throw new Error(`Unable to save file: ${filename}${extension}`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user