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:
parent
fc4f106afb
commit
9c1568b911
7 changed files with 320 additions and 42 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue