@inweb/client 25.2.2 → 25.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +70 -70
- package/dist/client.js +12369 -11952
- package/dist/client.js.map +1 -1
- package/dist/client.min.js +1 -1
- package/dist/client.module.js +714 -235
- package/dist/client.module.js.map +1 -1
- package/lib/Api/Assembly.d.ts +338 -338
- package/lib/Api/ClashTest.d.ts +175 -175
- package/lib/Api/Client.d.ts +451 -451
- package/lib/Api/ClientEvents.d.ts +28 -28
- package/lib/Api/File.d.ts +567 -567
- package/lib/Api/HttpClient.d.ts +12 -12
- package/lib/Api/IAssembly.d.ts +13 -13
- package/lib/Api/IFile.d.ts +45 -45
- package/lib/Api/IHttpClient.d.ts +10 -10
- package/lib/Api/IUser.d.ts +10 -10
- package/lib/Api/Job.d.ts +141 -141
- package/lib/Api/Member.d.ts +84 -84
- package/lib/Api/Model.d.ts +146 -146
- package/lib/Api/Permission.d.ts +92 -92
- package/lib/Api/Project.d.ts +246 -246
- package/lib/Api/Role.d.ts +81 -81
- package/lib/Api/User.d.ts +196 -196
- package/lib/Api/impl/FetchError.d.ts +17 -17
- package/lib/Api/impl/Utils.d.ts +32 -32
- package/lib/Api/impl/http.d.ts +66 -66
- package/lib/ConvetMath.d.ts +28 -28
- package/lib/Viewer/CanvasEvents.d.ts +1 -1
- package/lib/Viewer/Commands/ApplyModelTransform.d.ts +1 -1
- package/lib/Viewer/Commands/ClearMarkup.d.ts +1 -1
- package/lib/Viewer/Commands/ClearSlices.d.ts +1 -1
- package/lib/Viewer/Commands/CreatePreview.d.ts +1 -1
- package/lib/Viewer/Commands/Explode.d.ts +1 -1
- package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +1 -1
- package/lib/Viewer/Commands/GetModels.d.ts +1 -1
- package/lib/Viewer/Commands/GetSelected.d.ts +1 -1
- package/lib/Viewer/Commands/HideSelected.d.ts +1 -1
- package/lib/Viewer/Commands/IsolateSelected.d.ts +1 -1
- package/lib/Viewer/Commands/RegenerateAll.d.ts +1 -1
- package/lib/Viewer/Commands/ResetView.d.ts +1 -1
- package/lib/Viewer/Commands/SelectModel.d.ts +1 -1
- package/lib/Viewer/Commands/SetActiveDragger.d.ts +1 -1
- package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +1 -1
- package/lib/Viewer/Commands/SetMarkupColor.d.ts +1 -1
- package/lib/Viewer/Commands/SetSelected.d.ts +1 -1
- package/lib/Viewer/Commands/ShowAll.d.ts +1 -1
- package/lib/Viewer/Commands/Unselect.d.ts +1 -1
- package/lib/Viewer/Commands/ZoomToExtents.d.ts +1 -1
- package/lib/Viewer/Commands/ZoomToObjects.d.ts +1 -1
- package/lib/Viewer/Commands/ZoomToSelected.d.ts +1 -1
- package/lib/Viewer/Commands.d.ts +2 -2
- package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +21 -21
- package/lib/Viewer/Draggers/Actions/PanAction.d.ts +17 -17
- package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +7 -7
- package/lib/Viewer/Draggers/Common/Geometry.d.ts +114 -114
- package/lib/Viewer/Draggers/Common/GestureManager.d.ts +40 -40
- package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +53 -53
- package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +29 -29
- package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +30 -30
- package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +19 -19
- package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +23 -23
- package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +26 -26
- package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +7 -7
- package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +7 -7
- package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +7 -7
- package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +14 -14
- package/lib/Viewer/Draggers/OdPanDragger.d.ts +11 -11
- package/lib/Viewer/Draggers/OdZoomDragger.d.ts +11 -11
- package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +10 -10
- package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +18 -18
- package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +13 -13
- package/lib/Viewer/Draggers/OdaLineDragger.d.ts +14 -14
- package/lib/Viewer/Draggers/OdaTextDragger.d.ts +15 -15
- package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +29 -29
- package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +18 -18
- package/lib/Viewer/EventEmitter2.d.ts +53 -53
- package/lib/Viewer/ICommands.d.ts +24 -24
- package/lib/Viewer/IEventEmitter2.d.ts +12 -12
- package/lib/Viewer/IViewer.d.ts +28 -26
- package/lib/Viewer/Loaders/BaseLoader.d.ts +10 -10
- package/lib/Viewer/Loaders/LoaderFactory.d.ts +10 -9
- package/lib/Viewer/Loaders/TCSLoader.d.ts +4 -4
- package/lib/Viewer/Loaders/UpdaterController.d.ts +14 -14
- package/lib/Viewer/Loaders/VsfXLoader.d.ts +4 -4
- package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +4 -4
- package/lib/Viewer/Loaders/VsfXStreamingLoader.d.ts +5 -0
- package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +21 -11
- package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +15 -0
- package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +4 -4
- package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +14 -14
- package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +14 -14
- package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +18 -10
- package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +11 -11
- package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +14 -14
- package/lib/Viewer/Markup/Api/IMarkupText.d.ts +12 -12
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +46 -31
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaCloud.d.ts +36 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -39
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -35
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +35 -31
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -37
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -36
- package/lib/Viewer/Markup/IMarkup.d.ts +38 -37
- package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +71 -62
- package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +18 -18
- package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +33 -32
- package/lib/Viewer/Markup/MarkupFactory.d.ts +6 -6
- package/lib/Viewer/Options.d.ts +238 -227
- package/lib/Viewer/OptionsEvents.d.ts +25 -25
- package/lib/Viewer/Viewer.d.ts +358 -352
- package/lib/Viewer/ViewerCommands.d.ts +22 -22
- package/lib/Viewer/ViewerEvents.d.ts +600 -600
- package/lib/Viewer/utils.d.ts +3 -3
- package/lib/index.d.ts +23 -23
- package/package.json +38 -32
- package/src/Api/Assembly.ts +678 -678
- package/src/Api/ClashTest.ts +290 -290
- package/src/Api/Client.ts +816 -816
- package/src/Api/ClientEvents.ts +31 -31
- package/src/Api/File.ts +962 -962
- package/src/Api/HttpClient.ts +73 -73
- package/src/Api/IAssembly.ts +37 -37
- package/src/Api/IFile.ts +74 -74
- package/src/Api/IHttpClient.ts +50 -50
- package/src/Api/IUser.ts +33 -33
- package/src/Api/Job.ts +253 -253
- package/src/Api/Member.ts +161 -161
- package/src/Api/Model.ts +259 -259
- package/src/Api/Permission.ts +173 -173
- package/src/Api/Project.ts +479 -479
- package/src/Api/Role.ts +158 -158
- package/src/Api/User.ts +357 -357
- package/src/Api/impl/FetchError.ts +48 -48
- package/src/Api/impl/Utils.ts +367 -367
- package/src/Api/impl/http.ts +92 -92
- package/src/ConvetMath.ts +372 -372
- package/src/Viewer/CanvasEvents.ts +41 -41
- package/src/Viewer/Commands/ApplyModelTransform.ts +70 -70
- package/src/Viewer/Commands/ClearMarkup.ts +28 -28
- package/src/Viewer/Commands/ClearSlices.ts +27 -27
- package/src/Viewer/Commands/CreatePreview.ts +33 -33
- package/src/Viewer/Commands/Explode.ts +38 -38
- package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -36
- package/src/Viewer/Commands/GetModels.ts +43 -43
- package/src/Viewer/Commands/GetSelected.ts +58 -58
- package/src/Viewer/Commands/HideSelected.ts +37 -37
- package/src/Viewer/Commands/IsolateSelected.ts +37 -37
- package/src/Viewer/Commands/RegenerateAll.ts +37 -37
- package/src/Viewer/Commands/ResetView.ts +43 -43
- package/src/Viewer/Commands/SelectModel.ts +52 -52
- package/src/Viewer/Commands/SetActiveDragger.ts +29 -29
- package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -50
- package/src/Viewer/Commands/SetMarkupColor.ts +29 -29
- package/src/Viewer/Commands/SetSelected.ts +47 -47
- package/src/Viewer/Commands/ShowAll.ts +37 -37
- package/src/Viewer/Commands/Unselect.ts +37 -37
- package/src/Viewer/Commands/ZoomToExtents.ts +43 -43
- package/src/Viewer/Commands/ZoomToObjects.ts +47 -47
- package/src/Viewer/Commands/ZoomToSelected.ts +39 -39
- package/src/Viewer/Commands.ts +81 -81
- package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -250
- package/src/Viewer/Draggers/Actions/PanAction.ts +102 -102
- package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -45
- package/src/Viewer/Draggers/Common/Geometry.ts +152 -152
- package/src/Viewer/Draggers/Common/GestureManager.ts +263 -263
- package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -270
- package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -146
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -248
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -182
- package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -166
- package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -182
- package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -53
- package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -53
- package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -53
- package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -70
- package/src/Viewer/Draggers/OdPanDragger.ts +62 -62
- package/src/Viewer/Draggers/OdZoomDragger.ts +59 -59
- package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -103
- package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -123
- package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -75
- package/src/Viewer/Draggers/OdaLineDragger.ts +80 -80
- package/src/Viewer/Draggers/OdaTextDragger.ts +118 -118
- package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -278
- package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -184
- package/src/Viewer/EventEmitter2.ts +116 -116
- package/src/Viewer/ICommands.ts +53 -53
- package/src/Viewer/IEventEmitter2.ts +36 -36
- package/src/Viewer/IViewer.ts +58 -55
- package/src/Viewer/Loaders/BaseLoader.ts +40 -40
- package/src/Viewer/Loaders/LoaderFactory.ts +47 -44
- package/src/Viewer/Loaders/TCSLoader.ts +82 -82
- package/src/Viewer/Loaders/UpdaterController.ts +36 -36
- package/src/Viewer/Loaders/VsfXLoader.ts +65 -87
- package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -208
- package/src/Viewer/Loaders/VsfXStreamingLoader.ts +87 -0
- package/src/Viewer/Markup/Api/IMarkupArrow.ts +12 -15
- package/src/Viewer/Markup/Api/IMarkupCloud.ts +15 -0
- package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -4
- package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -15
- package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -15
- package/src/Viewer/Markup/Api/IMarkupLine.ts +20 -10
- package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -15
- package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -15
- package/src/Viewer/Markup/Api/IMarkupText.ts +12 -12
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +117 -119
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +208 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +118 -113
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +123 -121
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +130 -99
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +119 -113
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +110 -104
- package/src/Viewer/Markup/IMarkup.ts +40 -39
- package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +1144 -872
- package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -39
- package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +231 -273
- package/src/Viewer/Markup/MarkupFactory.ts +32 -32
- package/src/Viewer/Options.ts +522 -502
- package/src/Viewer/OptionsEvents.ts +28 -28
- package/src/Viewer/Viewer.ts +1191 -1109
- package/src/Viewer/ViewerCommands.ts +45 -45
- package/src/Viewer/ViewerEvents.ts +700 -700
- package/src/Viewer/utils.ts +74 -74
- package/src/index.ts +48 -48
package/src/Api/impl/Utils.ts
CHANGED
|
@@ -1,367 +1,367 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
|
|
3
|
-
// All rights reserved.
|
|
4
|
-
//
|
|
5
|
-
// This software and its documentation and related materials are owned by
|
|
6
|
-
// the Alliance. The software may only be incorporated into application
|
|
7
|
-
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
-
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
-
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
-
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
-
// protected by copyright law and international treaty provisions. Application
|
|
12
|
-
// programs incorporating this software must include the following statement
|
|
13
|
-
// with their copyright notices:
|
|
14
|
-
//
|
|
15
|
-
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
-
// license agreement with Open Design Alliance.
|
|
17
|
-
// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
|
|
18
|
-
// All rights reserved.
|
|
19
|
-
//
|
|
20
|
-
// By use of this software, its documentation or related materials, you
|
|
21
|
-
// acknowledge and accept the above terms.
|
|
22
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
-
|
|
24
|
-
import { FetchError } from "./FetchError";
|
|
25
|
-
import { statusText } from "./http";
|
|
26
|
-
|
|
27
|
-
export function json(request: any): any {
|
|
28
|
-
return request.then((response) => response.json());
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function text(request: any): any {
|
|
32
|
-
return request.then((response) => response.text());
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function arrayBuffer(request: any): any {
|
|
36
|
-
return request.then((response) => response.arrayBuffer());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function error400(text: string, _default = "400") {
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse(text).description;
|
|
42
|
-
} catch {
|
|
43
|
-
return _default;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function handleXMLHttpError(xhr: any): Promise<any> {
|
|
48
|
-
if (xhr.status === 0) {
|
|
49
|
-
return Promise.reject(new FetchError(0, "Network error"));
|
|
50
|
-
}
|
|
51
|
-
if (xhr.status < 200 || xhr.status > 299) {
|
|
52
|
-
switch (xhr.status) {
|
|
53
|
-
case 400: {
|
|
54
|
-
console.error(xhr.responseText);
|
|
55
|
-
return Promise.reject(new FetchError(400, error400(xhr.responseText)));
|
|
56
|
-
}
|
|
57
|
-
case 500: {
|
|
58
|
-
console.error(error400(xhr.responseText, xhr.responseText));
|
|
59
|
-
return Promise.reject(new FetchError(500));
|
|
60
|
-
}
|
|
61
|
-
default: {
|
|
62
|
-
return Promise.reject(new FetchError(xhr.status));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return Promise.resolve(xhr);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function handleFetchError(response: Response): Promise<Response> {
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
switch (response.status) {
|
|
72
|
-
case 400: {
|
|
73
|
-
return response.text().then((text) => {
|
|
74
|
-
console.error(text);
|
|
75
|
-
return Promise.reject(new FetchError(400, error400(text)));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
case 500: {
|
|
79
|
-
return response.text().then((text) => {
|
|
80
|
-
console.error(error400(text, text));
|
|
81
|
-
return Promise.reject(new FetchError(500));
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
default:
|
|
85
|
-
return Promise.reject(new FetchError(response.status, statusText(response.status)));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return Promise.resolve(response);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function $init(
|
|
92
|
-
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
93
|
-
headers?: HeadersInit,
|
|
94
|
-
body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null,
|
|
95
|
-
signal?: AbortSignal
|
|
96
|
-
): RequestInit {
|
|
97
|
-
headers = { ...headers };
|
|
98
|
-
headers["Content-Type"] = "application/json";
|
|
99
|
-
|
|
100
|
-
if (method === "POST" || method === "PUT") {
|
|
101
|
-
if (body instanceof FormData) {
|
|
102
|
-
delete headers["Content-Type"];
|
|
103
|
-
} else if (body instanceof File || body instanceof Blob) {
|
|
104
|
-
const formData = new FormData();
|
|
105
|
-
formData.append("file", body);
|
|
106
|
-
return $init(method, headers, formData, signal);
|
|
107
|
-
} else if (body instanceof ArrayBuffer) {
|
|
108
|
-
const blob = new Blob([body]);
|
|
109
|
-
return $init(method, headers, blob, signal);
|
|
110
|
-
} else if (body && typeof body === "object") {
|
|
111
|
-
body = JSON.stringify(body);
|
|
112
|
-
} else if (typeof body === "string") {
|
|
113
|
-
headers["Content-Type"] = "text/plain";
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const result = { method, headers } as RequestInit;
|
|
118
|
-
|
|
119
|
-
// body with type "object", converted to type "string" in the code above
|
|
120
|
-
if (
|
|
121
|
-
body &&
|
|
122
|
-
(body instanceof ArrayBuffer ||
|
|
123
|
-
body instanceof Blob ||
|
|
124
|
-
body instanceof globalThis.File ||
|
|
125
|
-
body instanceof FormData ||
|
|
126
|
-
typeof body === "string")
|
|
127
|
-
) {
|
|
128
|
-
result.body = body;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (signal) result.signal = signal;
|
|
132
|
-
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function $fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
137
|
-
return fetch(url, init).then((response) => handleFetchError(response));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function $get(url: RequestInfo | URL, headers?: HeadersInit, signal?: AbortSignal): Promise<Response> {
|
|
141
|
-
return $fetch(url, $init("GET", headers, null, signal));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function $put(
|
|
145
|
-
url: RequestInfo | URL,
|
|
146
|
-
headers?: HeadersInit,
|
|
147
|
-
body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
|
|
148
|
-
) {
|
|
149
|
-
return $fetch(url, $init("PUT", headers, body));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function $post(
|
|
153
|
-
url: RequestInfo | URL,
|
|
154
|
-
headers?: HeadersInit,
|
|
155
|
-
body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
|
|
156
|
-
) {
|
|
157
|
-
return $fetch(url, $init("POST", headers, body));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function $delete(url: RequestInfo | URL, headers?: HeadersInit) {
|
|
161
|
-
return $fetch(url, $init("DELETE", headers));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function streamProgress(stream: ReadableStream<Uint8Array>, onprogress: (progress: number) => void) {
|
|
165
|
-
const reader = stream.getReader();
|
|
166
|
-
let current = 0;
|
|
167
|
-
|
|
168
|
-
function calc(ev) {
|
|
169
|
-
if (!ev.done) {
|
|
170
|
-
reader.read().then(calc).catch(console.error);
|
|
171
|
-
}
|
|
172
|
-
if (ev.value) current += ev.value.length;
|
|
173
|
-
onprogress(current);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
reader.read().then(calc).catch(console.error);
|
|
177
|
-
|
|
178
|
-
return stream;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function downloadProgress(response: Response, onprogress?: (progress: number) => void): Response {
|
|
182
|
-
const contentLength = response.headers.get("Content-Length") ?? "";
|
|
183
|
-
const total = parseInt(contentLength, 10);
|
|
184
|
-
const tee = response.body.tee();
|
|
185
|
-
streamProgress(tee[0], (bytesCount: number) => onprogress && onprogress(bytesCount / total));
|
|
186
|
-
return new Response(tee[1]);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
interface XMLHttpParams {
|
|
190
|
-
headers: HeadersInit;
|
|
191
|
-
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
192
|
-
body?: XMLHttpRequestBodyInit | Document;
|
|
193
|
-
uploadProgress?: (progress: number) => void;
|
|
194
|
-
downloadProgress?: (progress: number) => void;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function $XMLHttp(
|
|
198
|
-
url: string,
|
|
199
|
-
{ headers, method, body, uploadProgress, downloadProgress }: XMLHttpParams
|
|
200
|
-
): Promise<XMLHttpRequest> {
|
|
201
|
-
return new Promise((resolve, reject) => {
|
|
202
|
-
const xhr = new XMLHttpRequest();
|
|
203
|
-
xhr.open(method, url, true);
|
|
204
|
-
for (const key in headers) {
|
|
205
|
-
xhr.setRequestHeader(key, headers[key]);
|
|
206
|
-
}
|
|
207
|
-
function calcProgress(event) {
|
|
208
|
-
return event.lengthComputable ? event.loaded / event.total : 1;
|
|
209
|
-
}
|
|
210
|
-
xhr.upload.onprogress = (event) => uploadProgress && uploadProgress(calcProgress(event));
|
|
211
|
-
xhr.onprogress = (event) => downloadProgress && downloadProgress(calcProgress(event));
|
|
212
|
-
xhr.onloadend = (event) => handleXMLHttpError(event.target).then(resolve, reject);
|
|
213
|
-
xhr.send(body);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function delay(ms: number, signal: AbortSignal) {
|
|
218
|
-
return new Promise((resolve) => {
|
|
219
|
-
let timeoutId = 0;
|
|
220
|
-
|
|
221
|
-
const abortHandler = () => {
|
|
222
|
-
clearTimeout(timeoutId);
|
|
223
|
-
resolve(true);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
timeoutId = window.setTimeout(() => {
|
|
227
|
-
signal.removeEventListener("abort", abortHandler);
|
|
228
|
-
resolve(false);
|
|
229
|
-
}, ms);
|
|
230
|
-
|
|
231
|
-
signal.addEventListener("abort", abortHandler, { once: true });
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export async function waitFor(
|
|
236
|
-
func: (params: any) => Promise<boolean>,
|
|
237
|
-
params: {
|
|
238
|
-
timeout?: number;
|
|
239
|
-
interval?: number;
|
|
240
|
-
signal?: AbortSignal;
|
|
241
|
-
abortError?: DOMException;
|
|
242
|
-
timeoutError?: DOMException;
|
|
243
|
-
result?: any;
|
|
244
|
-
} = {}
|
|
245
|
-
) {
|
|
246
|
-
const timeout = params.timeout ?? 600000;
|
|
247
|
-
const interval = params.interval ?? 3000;
|
|
248
|
-
const signal = params.signal ?? new AbortController().signal;
|
|
249
|
-
const abortError = params.abortError ?? new DOMException("Aborted", "AbortError");
|
|
250
|
-
const timeoutError = params.timeoutError ?? new DOMException("Timeout", "TimeoutError");
|
|
251
|
-
|
|
252
|
-
const end = performance.now() + timeout;
|
|
253
|
-
let count = timeout / interval;
|
|
254
|
-
|
|
255
|
-
do {
|
|
256
|
-
if (await func(params)) return Promise.resolve(params.result);
|
|
257
|
-
if ((await delay(interval, signal)) || signal.aborted) return Promise.reject(abortError);
|
|
258
|
-
} while (performance.now() < end && --count > 0);
|
|
259
|
-
|
|
260
|
-
return Promise.reject(timeoutError);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export async function downloadPartOfFile(
|
|
264
|
-
requestId: number,
|
|
265
|
-
records: any | null,
|
|
266
|
-
url: string,
|
|
267
|
-
defHeaders: HeadersInit,
|
|
268
|
-
onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void,
|
|
269
|
-
signal?: AbortSignal
|
|
270
|
-
): Promise<void> {
|
|
271
|
-
const headers = { ...defHeaders };
|
|
272
|
-
const isMultipleResourceParts = records && records.length;
|
|
273
|
-
if (records) {
|
|
274
|
-
const ranges: string[] = [];
|
|
275
|
-
if (isMultipleResourceParts) {
|
|
276
|
-
for (let i = 0; i < records.length; i++) {
|
|
277
|
-
const record = records[i];
|
|
278
|
-
ranges.push(`${record.begin}-${record.end}`);
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
for (let i = 0; i < records.size(); i++) {
|
|
282
|
-
const record = records.get(i);
|
|
283
|
-
ranges.push(`${record.begin}-${record.end}`);
|
|
284
|
-
record.delete();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
headers["Range"] = "bytes=" + ranges.join(",");
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const response = await $fetch(url, $init("GET", headers, null, signal));
|
|
291
|
-
const contentLength = response.headers.get("content-length") ?? "";
|
|
292
|
-
const total = parseInt(contentLength, 10);
|
|
293
|
-
|
|
294
|
-
const reader = response.body.getReader();
|
|
295
|
-
|
|
296
|
-
if (isMultipleResourceParts) {
|
|
297
|
-
let curRecordIndex = 0;
|
|
298
|
-
let curRecordPos = 0;
|
|
299
|
-
while (true) {
|
|
300
|
-
const { done, value } = await reader.read();
|
|
301
|
-
if (done) break;
|
|
302
|
-
let totalLeft = value.byteLength;
|
|
303
|
-
let loadedPos = 0;
|
|
304
|
-
while (totalLeft > 0) {
|
|
305
|
-
const curRecord = records[curRecordIndex];
|
|
306
|
-
const recLeft = curRecord.size - curRecordPos;
|
|
307
|
-
if (totalLeft < recLeft) {
|
|
308
|
-
const buf = value.subarray(loadedPos, loadedPos + totalLeft);
|
|
309
|
-
if (typeof onProgress === "function") onProgress(loadedPos / total, buf, curRecord.reqId);
|
|
310
|
-
curRecordPos += totalLeft;
|
|
311
|
-
totalLeft = 0;
|
|
312
|
-
} else {
|
|
313
|
-
const buf = value.subarray(loadedPos, loadedPos + recLeft);
|
|
314
|
-
if (typeof onProgress === "function") onProgress(loadedPos / total, buf, curRecord.reqId);
|
|
315
|
-
curRecordIndex++;
|
|
316
|
-
curRecordPos = 0;
|
|
317
|
-
loadedPos += recLeft;
|
|
318
|
-
totalLeft -= recLeft;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
} else {
|
|
323
|
-
let loaded = 0;
|
|
324
|
-
while (true) {
|
|
325
|
-
const { done, value } = await reader.read();
|
|
326
|
-
if (done) break;
|
|
327
|
-
loaded += value.byteLength;
|
|
328
|
-
if (onProgress) onProgress(loaded / total, value, requestId);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
export function parseArgs(args: string | object): object {
|
|
334
|
-
if (typeof args === "string") {
|
|
335
|
-
const firstArg = args.indexOf("--");
|
|
336
|
-
if (firstArg !== -1) args = args.slice(firstArg);
|
|
337
|
-
const argArray = args
|
|
338
|
-
.split("--")
|
|
339
|
-
.map((x) =>
|
|
340
|
-
x
|
|
341
|
-
.split("=")
|
|
342
|
-
.map((y) => y.split(" "))
|
|
343
|
-
.flat()
|
|
344
|
-
)
|
|
345
|
-
.filter((x) => x[0])
|
|
346
|
-
.map((x) => x.concat([""]));
|
|
347
|
-
return Object.fromEntries(argArray);
|
|
348
|
-
}
|
|
349
|
-
return args ?? {};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export function userFullName(firstName: string | any, lastName = "", userName = ""): string {
|
|
353
|
-
if (firstName && typeof firstName !== "string") {
|
|
354
|
-
return userFullName(firstName.firstName ?? firstName.name, firstName.lastName, firstName.userName);
|
|
355
|
-
}
|
|
356
|
-
return `${firstName ?? ""} ${lastName ?? ""}`.trim() || userName;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
export function userInitials(fullName = ""): string {
|
|
360
|
-
const names = fullName.split(" ").filter((x) => x);
|
|
361
|
-
return names
|
|
362
|
-
.reduce((initials, name, index) => {
|
|
363
|
-
if (index === 0 || index === names.length - 1) initials += name.charAt(0);
|
|
364
|
-
return initials;
|
|
365
|
-
}, "")
|
|
366
|
-
.toUpperCase();
|
|
367
|
-
}
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
// This software and its documentation and related materials are owned by
|
|
6
|
+
// the Alliance. The software may only be incorporated into application
|
|
7
|
+
// programs owned by members of the Alliance, subject to a signed
|
|
8
|
+
// Membership Agreement and Supplemental Software License Agreement with the
|
|
9
|
+
// Alliance. The structure and organization of this software are the valuable
|
|
10
|
+
// trade secrets of the Alliance and its suppliers. The software is also
|
|
11
|
+
// protected by copyright law and international treaty provisions. Application
|
|
12
|
+
// programs incorporating this software must include the following statement
|
|
13
|
+
// with their copyright notices:
|
|
14
|
+
//
|
|
15
|
+
// This application incorporates Open Design Alliance software pursuant to a
|
|
16
|
+
// license agreement with Open Design Alliance.
|
|
17
|
+
// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
|
|
18
|
+
// All rights reserved.
|
|
19
|
+
//
|
|
20
|
+
// By use of this software, its documentation or related materials, you
|
|
21
|
+
// acknowledge and accept the above terms.
|
|
22
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
import { FetchError } from "./FetchError";
|
|
25
|
+
import { statusText } from "./http";
|
|
26
|
+
|
|
27
|
+
export function json(request: any): any {
|
|
28
|
+
return request.then((response) => response.json());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function text(request: any): any {
|
|
32
|
+
return request.then((response) => response.text());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function arrayBuffer(request: any): any {
|
|
36
|
+
return request.then((response) => response.arrayBuffer());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function error400(text: string, _default = "400") {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(text).description;
|
|
42
|
+
} catch {
|
|
43
|
+
return _default;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function handleXMLHttpError(xhr: any): Promise<any> {
|
|
48
|
+
if (xhr.status === 0) {
|
|
49
|
+
return Promise.reject(new FetchError(0, "Network error"));
|
|
50
|
+
}
|
|
51
|
+
if (xhr.status < 200 || xhr.status > 299) {
|
|
52
|
+
switch (xhr.status) {
|
|
53
|
+
case 400: {
|
|
54
|
+
console.error(xhr.responseText);
|
|
55
|
+
return Promise.reject(new FetchError(400, error400(xhr.responseText)));
|
|
56
|
+
}
|
|
57
|
+
case 500: {
|
|
58
|
+
console.error(error400(xhr.responseText, xhr.responseText));
|
|
59
|
+
return Promise.reject(new FetchError(500));
|
|
60
|
+
}
|
|
61
|
+
default: {
|
|
62
|
+
return Promise.reject(new FetchError(xhr.status));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return Promise.resolve(xhr);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function handleFetchError(response: Response): Promise<Response> {
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
switch (response.status) {
|
|
72
|
+
case 400: {
|
|
73
|
+
return response.text().then((text) => {
|
|
74
|
+
console.error(text);
|
|
75
|
+
return Promise.reject(new FetchError(400, error400(text)));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
case 500: {
|
|
79
|
+
return response.text().then((text) => {
|
|
80
|
+
console.error(error400(text, text));
|
|
81
|
+
return Promise.reject(new FetchError(500));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
return Promise.reject(new FetchError(response.status, statusText(response.status)));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return Promise.resolve(response);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function $init(
|
|
92
|
+
method: "GET" | "POST" | "PUT" | "DELETE",
|
|
93
|
+
headers?: HeadersInit,
|
|
94
|
+
body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null,
|
|
95
|
+
signal?: AbortSignal
|
|
96
|
+
): RequestInit {
|
|
97
|
+
headers = { ...headers };
|
|
98
|
+
headers["Content-Type"] = "application/json";
|
|
99
|
+
|
|
100
|
+
if (method === "POST" || method === "PUT") {
|
|
101
|
+
if (body instanceof FormData) {
|
|
102
|
+
delete headers["Content-Type"];
|
|
103
|
+
} else if (body instanceof File || body instanceof Blob) {
|
|
104
|
+
const formData = new FormData();
|
|
105
|
+
formData.append("file", body);
|
|
106
|
+
return $init(method, headers, formData, signal);
|
|
107
|
+
} else if (body instanceof ArrayBuffer) {
|
|
108
|
+
const blob = new Blob([body]);
|
|
109
|
+
return $init(method, headers, blob, signal);
|
|
110
|
+
} else if (body && typeof body === "object") {
|
|
111
|
+
body = JSON.stringify(body);
|
|
112
|
+
} else if (typeof body === "string") {
|
|
113
|
+
headers["Content-Type"] = "text/plain";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const result = { method, headers } as RequestInit;
|
|
118
|
+
|
|
119
|
+
// body with type "object", converted to type "string" in the code above
|
|
120
|
+
if (
|
|
121
|
+
body &&
|
|
122
|
+
(body instanceof ArrayBuffer ||
|
|
123
|
+
body instanceof Blob ||
|
|
124
|
+
body instanceof globalThis.File ||
|
|
125
|
+
body instanceof FormData ||
|
|
126
|
+
typeof body === "string")
|
|
127
|
+
) {
|
|
128
|
+
result.body = body;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (signal) result.signal = signal;
|
|
132
|
+
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function $fetch(url: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
137
|
+
return fetch(url, init).then((response) => handleFetchError(response));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function $get(url: RequestInfo | URL, headers?: HeadersInit, signal?: AbortSignal): Promise<Response> {
|
|
141
|
+
return $fetch(url, $init("GET", headers, null, signal));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function $put(
|
|
145
|
+
url: RequestInfo | URL,
|
|
146
|
+
headers?: HeadersInit,
|
|
147
|
+
body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
|
|
148
|
+
) {
|
|
149
|
+
return $fetch(url, $init("PUT", headers, body));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function $post(
|
|
153
|
+
url: RequestInfo | URL,
|
|
154
|
+
headers?: HeadersInit,
|
|
155
|
+
body?: ArrayBuffer | Blob | globalThis.File | FormData | object | string | null
|
|
156
|
+
) {
|
|
157
|
+
return $fetch(url, $init("POST", headers, body));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function $delete(url: RequestInfo | URL, headers?: HeadersInit) {
|
|
161
|
+
return $fetch(url, $init("DELETE", headers));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function streamProgress(stream: ReadableStream<Uint8Array>, onprogress: (progress: number) => void) {
|
|
165
|
+
const reader = stream.getReader();
|
|
166
|
+
let current = 0;
|
|
167
|
+
|
|
168
|
+
function calc(ev) {
|
|
169
|
+
if (!ev.done) {
|
|
170
|
+
reader.read().then(calc).catch(console.error);
|
|
171
|
+
}
|
|
172
|
+
if (ev.value) current += ev.value.length;
|
|
173
|
+
onprogress(current);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
reader.read().then(calc).catch(console.error);
|
|
177
|
+
|
|
178
|
+
return stream;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function downloadProgress(response: Response, onprogress?: (progress: number) => void): Response {
|
|
182
|
+
const contentLength = response.headers.get("Content-Length") ?? "";
|
|
183
|
+
const total = parseInt(contentLength, 10);
|
|
184
|
+
const tee = response.body.tee();
|
|
185
|
+
streamProgress(tee[0], (bytesCount: number) => onprogress && onprogress(bytesCount / total));
|
|
186
|
+
return new Response(tee[1]);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface XMLHttpParams {
|
|
190
|
+
headers: HeadersInit;
|
|
191
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
192
|
+
body?: XMLHttpRequestBodyInit | Document;
|
|
193
|
+
uploadProgress?: (progress: number) => void;
|
|
194
|
+
downloadProgress?: (progress: number) => void;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function $XMLHttp(
|
|
198
|
+
url: string,
|
|
199
|
+
{ headers, method, body, uploadProgress, downloadProgress }: XMLHttpParams
|
|
200
|
+
): Promise<XMLHttpRequest> {
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
const xhr = new XMLHttpRequest();
|
|
203
|
+
xhr.open(method, url, true);
|
|
204
|
+
for (const key in headers) {
|
|
205
|
+
xhr.setRequestHeader(key, headers[key]);
|
|
206
|
+
}
|
|
207
|
+
function calcProgress(event) {
|
|
208
|
+
return event.lengthComputable ? event.loaded / event.total : 1;
|
|
209
|
+
}
|
|
210
|
+
xhr.upload.onprogress = (event) => uploadProgress && uploadProgress(calcProgress(event));
|
|
211
|
+
xhr.onprogress = (event) => downloadProgress && downloadProgress(calcProgress(event));
|
|
212
|
+
xhr.onloadend = (event) => handleXMLHttpError(event.target).then(resolve, reject);
|
|
213
|
+
xhr.send(body);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function delay(ms: number, signal: AbortSignal) {
|
|
218
|
+
return new Promise((resolve) => {
|
|
219
|
+
let timeoutId = 0;
|
|
220
|
+
|
|
221
|
+
const abortHandler = () => {
|
|
222
|
+
clearTimeout(timeoutId);
|
|
223
|
+
resolve(true);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
timeoutId = window.setTimeout(() => {
|
|
227
|
+
signal.removeEventListener("abort", abortHandler);
|
|
228
|
+
resolve(false);
|
|
229
|
+
}, ms);
|
|
230
|
+
|
|
231
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export async function waitFor(
|
|
236
|
+
func: (params: any) => Promise<boolean>,
|
|
237
|
+
params: {
|
|
238
|
+
timeout?: number;
|
|
239
|
+
interval?: number;
|
|
240
|
+
signal?: AbortSignal;
|
|
241
|
+
abortError?: DOMException;
|
|
242
|
+
timeoutError?: DOMException;
|
|
243
|
+
result?: any;
|
|
244
|
+
} = {}
|
|
245
|
+
) {
|
|
246
|
+
const timeout = params.timeout ?? 600000;
|
|
247
|
+
const interval = params.interval ?? 3000;
|
|
248
|
+
const signal = params.signal ?? new AbortController().signal;
|
|
249
|
+
const abortError = params.abortError ?? new DOMException("Aborted", "AbortError");
|
|
250
|
+
const timeoutError = params.timeoutError ?? new DOMException("Timeout", "TimeoutError");
|
|
251
|
+
|
|
252
|
+
const end = performance.now() + timeout;
|
|
253
|
+
let count = timeout / interval;
|
|
254
|
+
|
|
255
|
+
do {
|
|
256
|
+
if (await func(params)) return Promise.resolve(params.result);
|
|
257
|
+
if ((await delay(interval, signal)) || signal.aborted) return Promise.reject(abortError);
|
|
258
|
+
} while (performance.now() < end && --count > 0);
|
|
259
|
+
|
|
260
|
+
return Promise.reject(timeoutError);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function downloadPartOfFile(
|
|
264
|
+
requestId: number,
|
|
265
|
+
records: any | null,
|
|
266
|
+
url: string,
|
|
267
|
+
defHeaders: HeadersInit,
|
|
268
|
+
onProgress?: (progress: number, downloaded: Uint8Array, requestId: number) => void,
|
|
269
|
+
signal?: AbortSignal
|
|
270
|
+
): Promise<void> {
|
|
271
|
+
const headers = { ...defHeaders };
|
|
272
|
+
const isMultipleResourceParts = records && records.length;
|
|
273
|
+
if (records) {
|
|
274
|
+
const ranges: string[] = [];
|
|
275
|
+
if (isMultipleResourceParts) {
|
|
276
|
+
for (let i = 0; i < records.length; i++) {
|
|
277
|
+
const record = records[i];
|
|
278
|
+
ranges.push(`${record.begin}-${record.end}`);
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
for (let i = 0; i < records.size(); i++) {
|
|
282
|
+
const record = records.get(i);
|
|
283
|
+
ranges.push(`${record.begin}-${record.end}`);
|
|
284
|
+
record.delete();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
headers["Range"] = "bytes=" + ranges.join(",");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const response = await $fetch(url, $init("GET", headers, null, signal));
|
|
291
|
+
const contentLength = response.headers.get("content-length") ?? "";
|
|
292
|
+
const total = parseInt(contentLength, 10);
|
|
293
|
+
|
|
294
|
+
const reader = response.body.getReader();
|
|
295
|
+
|
|
296
|
+
if (isMultipleResourceParts) {
|
|
297
|
+
let curRecordIndex = 0;
|
|
298
|
+
let curRecordPos = 0;
|
|
299
|
+
while (true) {
|
|
300
|
+
const { done, value } = await reader.read();
|
|
301
|
+
if (done) break;
|
|
302
|
+
let totalLeft = value.byteLength;
|
|
303
|
+
let loadedPos = 0;
|
|
304
|
+
while (totalLeft > 0) {
|
|
305
|
+
const curRecord = records[curRecordIndex];
|
|
306
|
+
const recLeft = curRecord.size - curRecordPos;
|
|
307
|
+
if (totalLeft < recLeft) {
|
|
308
|
+
const buf = value.subarray(loadedPos, loadedPos + totalLeft);
|
|
309
|
+
if (typeof onProgress === "function") onProgress(loadedPos / total, buf, curRecord.reqId);
|
|
310
|
+
curRecordPos += totalLeft;
|
|
311
|
+
totalLeft = 0;
|
|
312
|
+
} else {
|
|
313
|
+
const buf = value.subarray(loadedPos, loadedPos + recLeft);
|
|
314
|
+
if (typeof onProgress === "function") onProgress(loadedPos / total, buf, curRecord.reqId);
|
|
315
|
+
curRecordIndex++;
|
|
316
|
+
curRecordPos = 0;
|
|
317
|
+
loadedPos += recLeft;
|
|
318
|
+
totalLeft -= recLeft;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
let loaded = 0;
|
|
324
|
+
while (true) {
|
|
325
|
+
const { done, value } = await reader.read();
|
|
326
|
+
if (done) break;
|
|
327
|
+
loaded += value.byteLength;
|
|
328
|
+
if (onProgress) onProgress(loaded / total, value, requestId);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function parseArgs(args: string | object): object {
|
|
334
|
+
if (typeof args === "string") {
|
|
335
|
+
const firstArg = args.indexOf("--");
|
|
336
|
+
if (firstArg !== -1) args = args.slice(firstArg);
|
|
337
|
+
const argArray = args
|
|
338
|
+
.split("--")
|
|
339
|
+
.map((x) =>
|
|
340
|
+
x
|
|
341
|
+
.split("=")
|
|
342
|
+
.map((y) => y.split(" "))
|
|
343
|
+
.flat()
|
|
344
|
+
)
|
|
345
|
+
.filter((x) => x[0])
|
|
346
|
+
.map((x) => x.concat([""]));
|
|
347
|
+
return Object.fromEntries(argArray);
|
|
348
|
+
}
|
|
349
|
+
return args ?? {};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function userFullName(firstName: string | any, lastName = "", userName = ""): string {
|
|
353
|
+
if (firstName && typeof firstName !== "string") {
|
|
354
|
+
return userFullName(firstName.firstName ?? firstName.name, firstName.lastName, firstName.userName);
|
|
355
|
+
}
|
|
356
|
+
return `${firstName ?? ""} ${lastName ?? ""}`.trim() || userName;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export function userInitials(fullName = ""): string {
|
|
360
|
+
const names = fullName.split(" ").filter((x) => x);
|
|
361
|
+
return names
|
|
362
|
+
.reduce((initials, name, index) => {
|
|
363
|
+
if (index === 0 || index === names.length - 1) initials += name.charAt(0);
|
|
364
|
+
return initials;
|
|
365
|
+
}, "")
|
|
366
|
+
.toUpperCase();
|
|
367
|
+
}
|