chore: import MCTF services
- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
commit
13f936bee9
1222 files changed
+21280
No files matched your search
Executable
+34
@@ -0,0 +1,34 @@
|
||||
function jsonPost(body) {
|
||||
return { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) };
|
||||
}
|
||||
|
||||
function responseError(result, fallback) {
|
||||
return new Error(typeof result.detail === "string" ? result.detail : fallback);
|
||||
}
|
||||
|
||||
export async function api(path, opts = {}) {
|
||||
const response = await fetch(path, opts);
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw responseError(result, "Проверьте поля запроса.");
|
||||
return result;
|
||||
}
|
||||
|
||||
export function post(path, body) {
|
||||
return api(path, jsonPost(body));
|
||||
}
|
||||
|
||||
export async function download(path, body, fallback) {
|
||||
const response = await fetch(path, jsonPost(body));
|
||||
if (!response.ok) {
|
||||
const result = await response.json();
|
||||
throw responseError(result, "Не удалось скачать отчёт.");
|
||||
}
|
||||
const url = URL.createObjectURL(await response.blob());
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = response.headers.get("content-disposition")?.match(/filename="?([^";]+)"?/i)?.[1] || fallback;
|
||||
document.body.append(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
Reference in new issue
Block a user