3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

feat: download data exports directly from the server without a JS download step

This commit is contained in:
Dragory 2021-11-03 01:14:41 +02:00
parent fc4f106afb
commit 9c1568b911
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
7 changed files with 320 additions and 42 deletions

View file

@ -66,3 +66,31 @@ export function post(resource: string, params: QueryParamObject = {}) {
},
});
}
type FormPostOpts = {
target?: string;
};
export function formPost(resource: string, body: Record<any, any> = {}, opts: FormPostOpts = {}) {
body["X-Api-Key"] = RootStore.state.auth.apiKey;
const form = document.createElement("form");
form.action = `${apiUrl}/${resource}`;
form.method = "POST";
form.enctype = "multipart/form-data";
if (opts.target != null) {
form.target = opts.target;
}
for (const [key, value] of Object.entries(body)) {
const input = document.createElement("input");
input.type = "hidden";
input.name = key;
input.value = value;
form.appendChild(input);
}
document.body.appendChild(form);
form.submit();
setTimeout(() => {
document.body.removeChild(form);
}, 1);
}