SYNC: Merge pull request #3 from dbgate/feature/zip

This commit is contained in:
Jan Prochazka
2025-04-23 13:17:54 +02:00
committed by Diflow
parent 54c53f0b56
commit 8f4118a6b8
82 changed files with 3981 additions and 2814 deletions

View File

@@ -184,7 +184,7 @@ export async function exportQuickExportFile(dataName, reader, format: QuickExpor
export async function saveFileToDisk(
filePathFunc,
options: any = { formatLabel: 'HTML page', formatExtension: 'html' }
options: any = { formatLabel: 'HTML page', formatExtension: 'html', defaultFileName: null }
) {
const { formatLabel, formatExtension } = options;
const electron = getElectron();
@@ -193,7 +193,7 @@ export async function saveFileToDisk(
const filters = [{ name: formatLabel, extensions: [formatExtension] }];
const filePath = await electron.showSaveDialog({
filters,
defaultPath: `file.${formatExtension}`,
defaultPath: options.defaultFileName ?? `file.${formatExtension}`,
properties: ['showOverwriteConfirmation'],
});
if (!filePath) return;
@@ -202,7 +202,7 @@ export async function saveFileToDisk(
} else {
const resp = await apiCall('files/generate-uploads-file');
await filePathFunc(resp.filePath);
await downloadFromApi(`uploads/get?file=${resp.fileName}`, `file.${formatExtension}`);
await downloadFromApi(`uploads/get?file=${resp.fileName}`, options.defaultFileName ?? `file.${formatExtension}`);
}
}

View File

@@ -1,6 +1,6 @@
export default function formatFileSize(size) {
if (size > 1000000000) return `${Math.round(size / 10000000000) * 10} GB`;
if (size > 1000000) return `${Math.round(size / 10000000) * 10} MB`;
if (size > 1000) return `${Math.round(size / 10000) * 10} KB`;
if (size > 1000000000) return `${Math.round(size / 100000000) / 10} GB`;
if (size > 1000000) return `${Math.round(size / 100000) / 10} MB`;
if (size > 1000) return `${Math.round(size / 100) / 10} KB`;
return `${size} bytes`;
}