mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 00:16:24 +00:00
Merge pull request #677 from KKishikawa/fix-download-with-auth-header
fix: download with auth header
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import formatFileSize from '../utility/formatFileSize';
|
import formatFileSize from '../utility/formatFileSize';
|
||||||
import getElectron from '../utility/getElectron';
|
import getElectron from '../utility/getElectron';
|
||||||
import resolveApi from '../utility/resolveApi';
|
import { downloadFromApi } from '../utility/exportFileTools';
|
||||||
import useEffect from '../utility/useEffect';
|
import useEffect from '../utility/useEffect';
|
||||||
|
|
||||||
export let runnerId;
|
export let runnerId;
|
||||||
@@ -66,9 +66,10 @@
|
|||||||
<a
|
<a
|
||||||
slot="0"
|
slot="0"
|
||||||
let:row
|
let:row
|
||||||
href={`${resolveApi()}/runners/data/${runnerId}/${row.name}`}
|
href="#"
|
||||||
target="_blank"
|
on:click={() => {
|
||||||
rel="noopener noreferrer"
|
downloadFromApi(`runners/data/${runnerId}/${row.name}`, row.name);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
download
|
download
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ScriptWriter, ScriptWriterJson } from 'dbgate-tools';
|
import { ScriptWriter, ScriptWriterJson } from 'dbgate-tools';
|
||||||
import getElectron from './getElectron';
|
import getElectron from './getElectron';
|
||||||
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
import { showSnackbar, showSnackbarInfo, showSnackbarError, closeSnackbar } from '../utility/snackbar';
|
||||||
import resolveApi from './resolveApi';
|
import resolveApi, { resolveApiHeaders } from './resolveApi';
|
||||||
import { apiCall, apiOff, apiOn } from './api';
|
import { apiCall, apiOff, apiOn } from './api';
|
||||||
import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
import { normalizeExportColumnMap } from '../impexp/createImpExpScript';
|
||||||
import { getCurrentConfig } from '../stores';
|
import { getCurrentConfig } from '../stores';
|
||||||
@@ -42,7 +42,7 @@ export async function exportSqlDump(outputFile, connection, databaseName, pureFi
|
|||||||
onOpenResult:
|
onOpenResult:
|
||||||
pureFileName && !getElectron()
|
pureFileName && !getElectron()
|
||||||
? () => {
|
? () => {
|
||||||
window.open(`${resolveApi()}/uploads/get?file=${pureFileName}`, '_blank');
|
downloadFromApi(`uploads/get?file=${pureFileName}`, 'file.sql');
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
openResultLabel: 'Download SQL file',
|
openResultLabel: 'Download SQL file',
|
||||||
@@ -112,7 +112,7 @@ export async function saveExportedFile(filters, defaultPath, extension, dataName
|
|||||||
finishedMessage: `Export ${dataName} finished`,
|
finishedMessage: `Export ${dataName} finished`,
|
||||||
afterFinish: () => {
|
afterFinish: () => {
|
||||||
if (!electron) {
|
if (!electron) {
|
||||||
window.open(`${resolveApi()}/uploads/get?file=${pureFileName}`, '_blank');
|
downloadFromApi(`uploads/get?file=${pureFileName}`, defaultPath);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -207,7 +207,7 @@ export async function saveFileToDisk(
|
|||||||
} else {
|
} else {
|
||||||
const resp = await apiCall('files/generate-uploads-file');
|
const resp = await apiCall('files/generate-uploads-file');
|
||||||
await filePathFunc(resp.filePath);
|
await filePathFunc(resp.filePath);
|
||||||
window.open(`${resolveApi()}/uploads/get?file=${resp.fileName}`, '_blank');
|
await downloadFromApi(`uploads/get?file=${resp.fileName}`, `file.${formatExtension}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,3 +220,23 @@ export function openWebLink(href) {
|
|||||||
window.open(href, '_blank');
|
window.open(href, '_blank');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function downloadFromApi(route: string, donloadName: string) {
|
||||||
|
fetch(`${resolveApi()}/${route}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: resolveApiHeaders(),
|
||||||
|
})
|
||||||
|
.then((res) => res.blob())
|
||||||
|
.then((blob) => {
|
||||||
|
const objUrl = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.download = donloadName;
|
||||||
|
a.href = objUrl;
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
setTimeout(() => {
|
||||||
|
URL.revokeObjectURL(objUrl)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user