fixed db download
All checks were successful
Deploy Nyla Frontend to Production / deploy (push) Successful in 49s
All checks were successful
Deploy Nyla Frontend to Production / deploy (push) Successful in 49s
This commit is contained in:
parent
554d798ae2
commit
8d24d57719
1 changed files with 22 additions and 21 deletions
|
|
@ -841,7 +841,17 @@ const MigrationTab: React.FC = () => {
|
||||||
|
|
||||||
_addExportLog(t('Export gestartet: {count} Datenbanken', { count: totalDbs }));
|
_addExportLog(t('Export gestartet: {count} Datenbanken', { count: totalDbs }));
|
||||||
|
|
||||||
const rawChunks: string[] = [];
|
let token = '';
|
||||||
|
try {
|
||||||
|
const startRes = await api.post('/api/admin/database-health/migration/export-start');
|
||||||
|
token = startRes.data.token;
|
||||||
|
} catch (err: any) {
|
||||||
|
_addExportLog(t('Fehler beim Starten des Exports: {error}', { error: String(err) }), 'error');
|
||||||
|
toast.showError(t('Export fehlgeschlagen'));
|
||||||
|
setExporting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let totalTables = 0;
|
let totalTables = 0;
|
||||||
let totalRecords = 0;
|
let totalRecords = 0;
|
||||||
let errors = 0;
|
let errors = 0;
|
||||||
|
|
@ -852,18 +862,14 @@ const MigrationTab: React.FC = () => {
|
||||||
_addExportLog(t('Exportiere {index}/{total}: {db}...', { index: i + 1, total: totalDbs, db: dbName }));
|
_addExportLog(t('Exportiere {index}/{total}: {db}...', { index: i + 1, total: totalDbs, db: dbName }));
|
||||||
try {
|
try {
|
||||||
const res = await api.get('/api/admin/database-health/migration/export-single', {
|
const res = await api.get('/api/admin/database-health/migration/export-single', {
|
||||||
params: { database: dbName },
|
params: { token, database: dbName },
|
||||||
responseType: 'text',
|
|
||||||
});
|
});
|
||||||
const parsed = JSON.parse(res.data);
|
totalTables += res.data.tableCount || 0;
|
||||||
const dbData = parsed.data;
|
totalRecords += res.data.totalRecords || 0;
|
||||||
totalTables += dbData?.tableCount || 0;
|
|
||||||
totalRecords += dbData?.totalRecords || 0;
|
|
||||||
rawChunks.push(`${JSON.stringify(dbName)}:${JSON.stringify(dbData)}`);
|
|
||||||
exportedCount++;
|
exportedCount++;
|
||||||
_addExportLog(
|
_addExportLog(
|
||||||
t('{db}: {tables} Tabellen, {records} Datensaetze', {
|
t('{db}: {tables} Tabellen, {records} Datensaetze', {
|
||||||
db: dbName, tables: dbData?.tableCount || 0, records: dbData?.totalRecords || 0,
|
db: dbName, tables: res.data.tableCount || 0, records: res.data.totalRecords || 0,
|
||||||
}),
|
}),
|
||||||
'success',
|
'success',
|
||||||
);
|
);
|
||||||
|
|
@ -885,23 +891,18 @@ const MigrationTab: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
_addExportLog(t('Erstelle Exportdatei...'));
|
_addExportLog(t('Erstelle Exportdatei...'));
|
||||||
await new Promise(r => setTimeout(r, 0));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const meta = JSON.stringify({
|
|
||||||
exportedAt: new Date().toISOString(),
|
|
||||||
version: '1.0',
|
|
||||||
databaseCount: exportedCount,
|
|
||||||
totalTables,
|
|
||||||
totalRecords,
|
|
||||||
});
|
|
||||||
const jsonStr = `{"meta":${meta},"databases":{${rawChunks.join(',')}}}`;
|
|
||||||
|
|
||||||
const ts = new Date().toISOString().replace(/:/g, '-').slice(0, 19);
|
const ts = new Date().toISOString().replace(/:/g, '-').slice(0, 19);
|
||||||
const scope = isFullExport ? 'full' : 'partial';
|
const scope = isFullExport ? 'full' : 'partial';
|
||||||
const filename = `db_backup_${instanceLabel}_${scope}_${ts}.json`;
|
const filename = `db_backup_${instanceLabel}_${scope}_${ts}.json`;
|
||||||
|
|
||||||
const blob = new Blob([jsonStr], { type: 'application/json' });
|
const res = await api.get('/api/admin/database-health/migration/export-download', {
|
||||||
|
params: { token, filename },
|
||||||
|
responseType: 'blob',
|
||||||
|
});
|
||||||
|
|
||||||
|
const blob = new Blob([res.data], { type: 'application/json' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
|
|
@ -924,7 +925,7 @@ const MigrationTab: React.FC = () => {
|
||||||
toast.showSuccess(t('Export erfolgreich'));
|
toast.showSuccess(t('Export erfolgreich'));
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
_addExportLog(t('Fehler beim Erstellen der Exportdatei: {error}', { error: String(err) }), 'error');
|
_addExportLog(t('Fehler beim Download der Exportdatei: {error}', { error: String(err) }), 'error');
|
||||||
toast.showError(t('Export fehlgeschlagen'));
|
toast.showError(t('Export fehlgeschlagen'));
|
||||||
} finally {
|
} finally {
|
||||||
setExporting(false);
|
setExporting(false);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue