@inweb/client 25.12.0 → 26.1.0
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/dist/client.js +618 -322
- package/dist/client.js.map +1 -1
- package/dist/client.min.js +1 -1
- package/dist/client.module.js +393 -312
- package/dist/client.module.js.map +1 -1
- package/lib/Api/Assembly.d.ts +7 -10
- package/lib/Api/ClashTest.d.ts +4 -8
- package/lib/Api/Client.d.ts +53 -4
- package/lib/Api/Endpoint.d.ts +73 -0
- package/lib/Api/Fetch.d.ts +3 -3
- package/lib/Api/File.d.ts +32 -14
- package/lib/Api/HttpClient.d.ts +7 -7
- package/lib/Api/IFile.d.ts +1 -1
- package/lib/Api/IHttpClient.d.ts +31 -26
- package/lib/Api/ISharedLink.d.ts +36 -0
- package/lib/Api/Job.d.ts +2 -5
- package/lib/Api/Member.d.ts +2 -6
- package/lib/Api/Model.d.ts +2 -4
- package/lib/Api/OAuthClient.d.ts +2 -6
- package/lib/Api/Permission.d.ts +3 -7
- package/lib/Api/Project.d.ts +3 -7
- package/lib/Api/Role.d.ts +2 -5
- package/lib/Api/SharedFile.d.ts +9 -0
- package/lib/Api/SharedLink.d.ts +70 -0
- package/lib/Api/User.d.ts +2 -2
- package/lib/Api/XMLHttp.d.ts +1 -1
- package/lib/index.d.ts +5 -1
- package/package.json +2 -2
- package/src/Api/Assembly.ts +45 -58
- package/src/Api/ClashTest.ts +10 -24
- package/src/Api/Client.ts +88 -9
- package/src/Api/Endpoint.ts +130 -0
- package/src/Api/Fetch.ts +20 -20
- package/src/Api/File.ts +101 -75
- package/src/Api/HttpClient.ts +40 -17
- package/src/Api/IFile.ts +1 -1
- package/src/Api/IHttpClient.ts +32 -26
- package/src/Api/ISharedLink.ts +63 -0
- package/src/Api/Job.ts +7 -19
- package/src/Api/Member.ts +7 -21
- package/src/Api/Model.ts +4 -7
- package/src/Api/OAuthClient.ts +8 -24
- package/src/Api/Permission.ts +8 -22
- package/src/Api/Project.ts +30 -43
- package/src/Api/Role.ts +8 -19
- package/src/Api/SharedFile.ts +54 -0
- package/src/Api/SharedLink.ts +135 -0
- package/src/Api/User.ts +16 -16
- package/src/Api/XMLHttp.ts +1 -1
- package/src/index.ts +5 -9
package/src/Api/File.ts
CHANGED
|
@@ -22,22 +22,22 @@
|
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
import { IHttpClient } from "./IHttpClient";
|
|
25
|
+
import { Endpoint } from "./Endpoint";
|
|
25
26
|
import { ICdaNode, IFileStatus, IFileReferences, IFileVersionInfo, IGrantedTo } from "./IFile";
|
|
26
27
|
import { IShortUserDesc } from "./IUser";
|
|
27
28
|
import { Model } from "./Model";
|
|
28
29
|
import { Permission } from "./Permission";
|
|
29
30
|
import { Job } from "./Job";
|
|
31
|
+
import { SharedLink } from "./SharedLink";
|
|
32
|
+
import { ISharedLinkPermissions } from "./ISharedLink";
|
|
30
33
|
import { waitFor, parseArgs, userFullName, userInitials } from "./Utils";
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* Provides properties and methods for obtaining information about a file on the Open Cloud
|
|
34
37
|
* Server and managing its data and versions.
|
|
35
38
|
*/
|
|
36
|
-
export class File {
|
|
39
|
+
export class File extends Endpoint {
|
|
37
40
|
private _data: any;
|
|
38
|
-
private _useVersion: number | undefined;
|
|
39
|
-
public httpClient: IHttpClient;
|
|
40
|
-
public path: string;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* @param data - Raw file data received from the server. For more information, see
|
|
@@ -45,37 +45,10 @@ export class File {
|
|
|
45
45
|
* @param httpClient - HTTP client instance used to send requests to the REST API server.
|
|
46
46
|
*/
|
|
47
47
|
constructor(data: any, httpClient: IHttpClient) {
|
|
48
|
-
|
|
49
|
-
this.httpClient = httpClient;
|
|
48
|
+
super(`/files/${data.id}`, httpClient);
|
|
50
49
|
this.data = data;
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
private appendVersionParam(relativePath: string): string {
|
|
54
|
-
if (this._useVersion === undefined) return relativePath;
|
|
55
|
-
const delimiter = relativePath.includes("?") ? "&" : "?";
|
|
56
|
-
return `${relativePath}${delimiter}version=${this._useVersion}`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private internalGet(relativePath: string, signal?: AbortSignal): Promise<Response> {
|
|
60
|
-
relativePath = this.appendVersionParam(relativePath);
|
|
61
|
-
return this.httpClient.get(`${this.path}${relativePath}`, signal);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private internalPost(relativePath: string, body?: BodyInit | object): Promise<Response> {
|
|
65
|
-
relativePath = this.appendVersionParam(relativePath);
|
|
66
|
-
return this.httpClient.post(`${this.path}${relativePath}`, body);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private internalPut(relativePath: string, body?: BodyInit | object): Promise<Response> {
|
|
70
|
-
relativePath = this.appendVersionParam(relativePath);
|
|
71
|
-
return this.httpClient.put(`${this.path}${relativePath}`, body);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private internalDelete(relativePath: string): Promise<Response> {
|
|
75
|
-
relativePath = this.appendVersionParam(relativePath);
|
|
76
|
-
return this.httpClient.delete(`${this.path}${relativePath}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
52
|
/**
|
|
80
53
|
* Active version number of the file.
|
|
81
54
|
*
|
|
@@ -97,8 +70,6 @@ export class File {
|
|
|
97
70
|
|
|
98
71
|
/**
|
|
99
72
|
* File custom fields object, to store custom data.
|
|
100
|
-
*
|
|
101
|
-
* @readonly
|
|
102
73
|
*/
|
|
103
74
|
get customFields(): any {
|
|
104
75
|
return this.data.customFields;
|
|
@@ -118,7 +89,7 @@ export class File {
|
|
|
118
89
|
return this._data;
|
|
119
90
|
}
|
|
120
91
|
|
|
121
|
-
|
|
92
|
+
set data(value: any) {
|
|
122
93
|
this._data = value;
|
|
123
94
|
this._data.previewUrl = value.preview
|
|
124
95
|
? `${this.httpClient.serverUrl}${this.path}/preview?updated=${value.updatedAt}`
|
|
@@ -145,6 +116,8 @@ export class File {
|
|
|
145
116
|
this._data.status.geometryGltf ??= { state: "none" };
|
|
146
117
|
// isFileDeleted since 25.7
|
|
147
118
|
this._data.isFileDeleted ??= false;
|
|
119
|
+
// sharedLinkToken since 26.0
|
|
120
|
+
this._data.sharedLinkToken ??= null;
|
|
148
121
|
}
|
|
149
122
|
|
|
150
123
|
/**
|
|
@@ -154,6 +127,8 @@ export class File {
|
|
|
154
127
|
* {@link createJob | createJob()}. To download exported file use
|
|
155
128
|
* {@link downloadResource | downloadResource()}.
|
|
156
129
|
*
|
|
130
|
+
* For an example of exporting files to other formats, see the {@link downloadResource} help.
|
|
131
|
+
*
|
|
157
132
|
* @readonly
|
|
158
133
|
*/
|
|
159
134
|
get exports(): string[] {
|
|
@@ -253,6 +228,15 @@ export class File {
|
|
|
253
228
|
return this.data.sizeTotal;
|
|
254
229
|
}
|
|
255
230
|
|
|
231
|
+
/**
|
|
232
|
+
* File shared link token or `null` if file is not shared yet.
|
|
233
|
+
*
|
|
234
|
+
* @readonly
|
|
235
|
+
*/
|
|
236
|
+
get sharedLinkToken(): string {
|
|
237
|
+
return this.data.sharedLinkToken;
|
|
238
|
+
}
|
|
239
|
+
|
|
256
240
|
/**
|
|
257
241
|
* Data status of the active version of the file. Contains:
|
|
258
242
|
*
|
|
@@ -321,7 +305,7 @@ export class File {
|
|
|
321
305
|
* Reloads file data from the server.
|
|
322
306
|
*/
|
|
323
307
|
async checkout(): Promise<this> {
|
|
324
|
-
const response = await this.
|
|
308
|
+
const response = await this.get("");
|
|
325
309
|
this.data = await response.json();
|
|
326
310
|
return this;
|
|
327
311
|
}
|
|
@@ -333,7 +317,7 @@ export class File {
|
|
|
333
317
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#Files | Open Cloud Files API}.
|
|
334
318
|
*/
|
|
335
319
|
async update(data: any): Promise<this> {
|
|
336
|
-
const response = await this.
|
|
320
|
+
const response = await this.put("", data);
|
|
337
321
|
this.data = await response.json();
|
|
338
322
|
return this;
|
|
339
323
|
}
|
|
@@ -347,8 +331,8 @@ export class File {
|
|
|
347
331
|
* @returns Returns the raw data of a deleted file. For more information, see
|
|
348
332
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#Files | Open Cloud Files API}.
|
|
349
333
|
*/
|
|
350
|
-
delete(): Promise<any> {
|
|
351
|
-
return
|
|
334
|
+
override delete(): Promise<any> {
|
|
335
|
+
return super.delete("").then((response) => response.json());
|
|
352
336
|
}
|
|
353
337
|
|
|
354
338
|
/**
|
|
@@ -374,7 +358,7 @@ export class File {
|
|
|
374
358
|
if (!image) {
|
|
375
359
|
await this.deletePreview();
|
|
376
360
|
} else {
|
|
377
|
-
const response = await this.
|
|
361
|
+
const response = await this.post("/preview", image);
|
|
378
362
|
this.data = await response.json();
|
|
379
363
|
}
|
|
380
364
|
return this;
|
|
@@ -384,7 +368,7 @@ export class File {
|
|
|
384
368
|
* Removes the file preview.
|
|
385
369
|
*/
|
|
386
370
|
async deletePreview(): Promise<this> {
|
|
387
|
-
const response = await
|
|
371
|
+
const response = await super.delete("/preview");
|
|
388
372
|
this.data = await response.json();
|
|
389
373
|
return this;
|
|
390
374
|
}
|
|
@@ -393,7 +377,7 @@ export class File {
|
|
|
393
377
|
* Returns a list of models of the active version of the file.
|
|
394
378
|
*/
|
|
395
379
|
getModels(): Promise<Model[]> {
|
|
396
|
-
return this.
|
|
380
|
+
return this.get("/geometry")
|
|
397
381
|
.then((response) => response.json())
|
|
398
382
|
.then((array) => array.map((data) => new Model(data, this)));
|
|
399
383
|
}
|
|
@@ -425,7 +409,7 @@ export class File {
|
|
|
425
409
|
*/
|
|
426
410
|
getProperties(handles?: string | string[]): Promise<any[]> {
|
|
427
411
|
const relativePath = handles !== undefined ? `/properties?handles=${handles}` : "/properties";
|
|
428
|
-
return this.
|
|
412
|
+
return this.get(relativePath).then((response) => response.json());
|
|
429
413
|
}
|
|
430
414
|
|
|
431
415
|
/**
|
|
@@ -473,14 +457,14 @@ export class File {
|
|
|
473
457
|
*/
|
|
474
458
|
|
|
475
459
|
searchProperties(searchPattern: any): Promise<any[]> {
|
|
476
|
-
return this.
|
|
460
|
+
return this.post("/properties/search", searchPattern).then((response) => response.json());
|
|
477
461
|
}
|
|
478
462
|
|
|
479
463
|
/**
|
|
480
464
|
* Returns the CDA tree for an active version of the file.
|
|
481
465
|
*/
|
|
482
466
|
getCdaTree(): Promise<ICdaNode[]> {
|
|
483
|
-
return this.
|
|
467
|
+
return this.get(`/properties/tree`).then((response) => response.json());
|
|
484
468
|
}
|
|
485
469
|
|
|
486
470
|
/**
|
|
@@ -488,7 +472,7 @@ export class File {
|
|
|
488
472
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#FileViewpoints | Open Cloud File Viewpoints API}.
|
|
489
473
|
*/
|
|
490
474
|
getViewpoints(): Promise<any[]> {
|
|
491
|
-
return this.
|
|
475
|
+
return this.get("/viewpoints")
|
|
492
476
|
.then((response) => response.json())
|
|
493
477
|
.then((viewpoints) => viewpoints.result);
|
|
494
478
|
}
|
|
@@ -500,7 +484,7 @@ export class File {
|
|
|
500
484
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#FileViewpoints | Open Cloud File Viewpoints API}.
|
|
501
485
|
*/
|
|
502
486
|
saveViewpoint(viewpoint: any): Promise<any> {
|
|
503
|
-
return this.
|
|
487
|
+
return this.post("/viewpoints", viewpoint).then((response) => response.json());
|
|
504
488
|
}
|
|
505
489
|
|
|
506
490
|
/**
|
|
@@ -511,7 +495,7 @@ export class File {
|
|
|
511
495
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#FileViewpoints | Open Cloud File Viewpoints API}.
|
|
512
496
|
*/
|
|
513
497
|
deleteViewpoint(guid: string): Promise<any> {
|
|
514
|
-
return
|
|
498
|
+
return super.delete(`/viewpoints/${guid}`).then((response) => response.json());
|
|
515
499
|
}
|
|
516
500
|
|
|
517
501
|
/**
|
|
@@ -521,7 +505,7 @@ export class File {
|
|
|
521
505
|
* @param guid - Viewpoint GUID.
|
|
522
506
|
*/
|
|
523
507
|
getSnapshot(guid: string): Promise<string> {
|
|
524
|
-
return this.
|
|
508
|
+
return this.get(`/viewpoints/${guid}/snapshot`).then((response) => response.text());
|
|
525
509
|
}
|
|
526
510
|
|
|
527
511
|
/**
|
|
@@ -531,7 +515,7 @@ export class File {
|
|
|
531
515
|
* @param bitmapGuid - Bitmap GUID.
|
|
532
516
|
*/
|
|
533
517
|
getSnapshotData(guid: string, bitmapGuid: string): Promise<string> {
|
|
534
|
-
return this.
|
|
518
|
+
return this.get(`/viewpoints/${guid}/bitmaps/${bitmapGuid}`).then((response) => response.text());
|
|
535
519
|
}
|
|
536
520
|
|
|
537
521
|
/**
|
|
@@ -543,9 +527,8 @@ export class File {
|
|
|
543
527
|
* signal. Allows to communicate with a fetch request and abort it if desired.
|
|
544
528
|
*/
|
|
545
529
|
download(onProgress?: (progress: number) => void, signal?: AbortSignal): Promise<ArrayBuffer> {
|
|
546
|
-
const relativePath = this.appendVersionParam("/downloads");
|
|
547
530
|
return this.httpClient
|
|
548
|
-
.downloadFile(
|
|
531
|
+
.downloadFile(this.getEndpointPath("/downloads"), onProgress, { signal, headers: this.headers })
|
|
549
532
|
.then((response) => response.arrayBuffer());
|
|
550
533
|
}
|
|
551
534
|
|
|
@@ -559,7 +542,7 @@ export class File {
|
|
|
559
542
|
* const dwgFileName = file.exports.find((x) => x.endsWith(".dwg"));
|
|
560
543
|
* const arrayBuffer = await file.downloadResource(dwgFileName);
|
|
561
544
|
* const blob = new Blob([arrayBuffer]);
|
|
562
|
-
* const fileName = file.name
|
|
545
|
+
* const fileName = file.name + ".dwg";
|
|
563
546
|
* FileSaver.saveAs(blob, fileName);
|
|
564
547
|
*
|
|
565
548
|
* @param dataId - Resource file name.
|
|
@@ -573,9 +556,8 @@ export class File {
|
|
|
573
556
|
onProgress?: (progress: number, chunk: Uint8Array) => void,
|
|
574
557
|
signal?: AbortSignal
|
|
575
558
|
): Promise<ArrayBuffer> {
|
|
576
|
-
const relativePath = this.appendVersionParam(`/downloads/${dataId}`);
|
|
577
559
|
return this.httpClient
|
|
578
|
-
.downloadFile(
|
|
560
|
+
.downloadFile(this.getEndpointPath(`/downloads/${dataId}`), onProgress, { signal, headers: this.headers })
|
|
579
561
|
.then((response) => response.arrayBuffer());
|
|
580
562
|
}
|
|
581
563
|
|
|
@@ -598,9 +580,14 @@ export class File {
|
|
|
598
580
|
onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
|
|
599
581
|
signal?: AbortSignal
|
|
600
582
|
): Promise<ArrayBuffer> {
|
|
601
|
-
const relativePath = this.appendVersionParam(`/downloads/${dataId}?requestId=${requestId}`);
|
|
602
583
|
return this.httpClient
|
|
603
|
-
.downloadFileRange(
|
|
584
|
+
.downloadFileRange(
|
|
585
|
+
this.getEndpointPath(`/downloads/${dataId}?requestId=${requestId}`),
|
|
586
|
+
requestId,
|
|
587
|
+
ranges,
|
|
588
|
+
onProgress,
|
|
589
|
+
{ signal, headers: this.headers }
|
|
590
|
+
)
|
|
604
591
|
.then((response) => response.arrayBuffer());
|
|
605
592
|
}
|
|
606
593
|
|
|
@@ -645,7 +632,7 @@ export class File {
|
|
|
645
632
|
* signal, which can be used to abort waiting as desired.
|
|
646
633
|
*/
|
|
647
634
|
getReferences(signal?: AbortSignal): Promise<IFileReferences> {
|
|
648
|
-
return this.
|
|
635
|
+
return this.get("/references", signal).then((response) => response.json());
|
|
649
636
|
}
|
|
650
637
|
|
|
651
638
|
/**
|
|
@@ -657,7 +644,7 @@ export class File {
|
|
|
657
644
|
* @param references - File references.
|
|
658
645
|
*/
|
|
659
646
|
setReferences(references: IFileReferences): Promise<IFileReferences> {
|
|
660
|
-
return this.
|
|
647
|
+
return this.put("/references", references).then((response) => response.json());
|
|
661
648
|
}
|
|
662
649
|
|
|
663
650
|
/**
|
|
@@ -679,9 +666,9 @@ export class File {
|
|
|
679
666
|
* for the File Converter tool in form `--arg=value`.
|
|
680
667
|
*/
|
|
681
668
|
createJob(outputFormat: string, parameters?: string | object): Promise<Job> {
|
|
682
|
-
const
|
|
683
|
-
return
|
|
684
|
-
.post(
|
|
669
|
+
const jobs = new Endpoint("/jobs", this.httpClient, this.headers);
|
|
670
|
+
return jobs
|
|
671
|
+
.post(this.appendVersionParam(""), {
|
|
685
672
|
fileId: this.id,
|
|
686
673
|
outputFormat,
|
|
687
674
|
parameters: parseArgs(parameters),
|
|
@@ -780,7 +767,7 @@ export class File {
|
|
|
780
767
|
* Returns a list of file permissions.
|
|
781
768
|
*/
|
|
782
769
|
getPermissions(): Promise<Permission[]> {
|
|
783
|
-
return this.
|
|
770
|
+
return this.get("/permissions")
|
|
784
771
|
.then((response) => response.json())
|
|
785
772
|
.then((array) => array.map((data) => new Permission(data, this.id, this.httpClient)));
|
|
786
773
|
}
|
|
@@ -791,7 +778,7 @@ export class File {
|
|
|
791
778
|
* @param permissionId - Permission ID.
|
|
792
779
|
*/
|
|
793
780
|
getPermission(permissionId: string): Promise<Permission> {
|
|
794
|
-
return this.
|
|
781
|
+
return this.get(`/permissions/${permissionId}`)
|
|
795
782
|
.then((response) => response.json())
|
|
796
783
|
.then((data) => new Permission(data, this.id, this.httpClient));
|
|
797
784
|
}
|
|
@@ -812,7 +799,7 @@ export class File {
|
|
|
812
799
|
* @param actions - Actions are allowed to be performed on a file with this permission:
|
|
813
800
|
*
|
|
814
801
|
* - `read` - The ability to read file description, geometry data and properties.
|
|
815
|
-
* - `readSourceFile` - The ability to
|
|
802
|
+
* - `readSourceFile` - The ability to download source file.
|
|
816
803
|
* - `write` - The ability to modify file name, description and references.
|
|
817
804
|
* - `readViewpoint` - The ability to read file viewpoints.
|
|
818
805
|
* - `createViewpoint` - The ability to create file viewpoints.
|
|
@@ -821,7 +808,7 @@ export class File {
|
|
|
821
808
|
* @param _public - Specifies whether all users have access to the file or not.
|
|
822
809
|
*/
|
|
823
810
|
createPermission(actions: string | string[], grantedTo: IGrantedTo[], _public: boolean): Promise<Permission> {
|
|
824
|
-
return this.
|
|
811
|
+
return this.post("/permissions", {
|
|
825
812
|
actions: Array.isArray(actions) ? actions : [actions],
|
|
826
813
|
grantedTo,
|
|
827
814
|
public: _public,
|
|
@@ -838,7 +825,7 @@ export class File {
|
|
|
838
825
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#Permission | Open Cloud File Permissions API}.
|
|
839
826
|
*/
|
|
840
827
|
deletePermission(permissionId: string): Promise<any> {
|
|
841
|
-
return
|
|
828
|
+
return super.delete(`/permissions/${permissionId}`).then((response) => response.json());
|
|
842
829
|
}
|
|
843
830
|
|
|
844
831
|
/**
|
|
@@ -879,7 +866,9 @@ export class File {
|
|
|
879
866
|
}
|
|
880
867
|
): Promise<File> {
|
|
881
868
|
const result = await this.httpClient
|
|
882
|
-
.uploadFile(
|
|
869
|
+
.uploadFile(this.getEndpointPath("/versions"), file, (progress) => params.onProgress?.(progress, file), {
|
|
870
|
+
headers: this.headers,
|
|
871
|
+
})
|
|
883
872
|
.then((xhr: XMLHttpRequest) => JSON.parse(xhr.responseText))
|
|
884
873
|
.then((data) => new File(data, this.httpClient));
|
|
885
874
|
|
|
@@ -907,7 +896,7 @@ export class File {
|
|
|
907
896
|
* Returns a list of version files.
|
|
908
897
|
*/
|
|
909
898
|
getVersions(): Promise<File[]> {
|
|
910
|
-
return this.
|
|
899
|
+
return this.get("/versions")
|
|
911
900
|
.then((response) => response.json())
|
|
912
901
|
.then((files) => files.map((data) => new File(data, this.httpClient)))
|
|
913
902
|
.then((files) => files.map((file) => (file.id == file.originalFileId ? file.useVersion(0) : file)));
|
|
@@ -919,7 +908,7 @@ export class File {
|
|
|
919
908
|
* @param version - Desired version.
|
|
920
909
|
*/
|
|
921
910
|
getVersion(version: number): Promise<File> {
|
|
922
|
-
return this.
|
|
911
|
+
return this.get(`/versions/${version}`)
|
|
923
912
|
.then((response) => response.json())
|
|
924
913
|
.then((data) => new File(data, this.httpClient))
|
|
925
914
|
.then((file) => (file.id == file.originalFileId ? file.useVersion(0) : file));
|
|
@@ -933,7 +922,7 @@ export class File {
|
|
|
933
922
|
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#Files | Open Cloud Files API}.
|
|
934
923
|
*/
|
|
935
924
|
async deleteVersion(version: number): Promise<any> {
|
|
936
|
-
const response = await
|
|
925
|
+
const response = await super.delete(`/versions/${version}`);
|
|
937
926
|
const data = await response.json();
|
|
938
927
|
await this.checkout();
|
|
939
928
|
return data;
|
|
@@ -974,17 +963,54 @@ export class File {
|
|
|
974
963
|
* You need to reload the file data using {@link checkout | checkout()} to match the size and
|
|
975
964
|
* status fields to the version you selected.
|
|
976
965
|
*/
|
|
977
|
-
useVersion(version?: number): this {
|
|
978
|
-
|
|
979
|
-
return this;
|
|
966
|
+
override useVersion(version?: number): this {
|
|
967
|
+
return super.useVersion(version);
|
|
980
968
|
}
|
|
981
969
|
|
|
982
970
|
/**
|
|
983
971
|
* Deletes the source file of the active file version from the server.
|
|
984
972
|
*/
|
|
985
973
|
async deleteSource(): Promise<this> {
|
|
986
|
-
const response = await
|
|
974
|
+
const response = await super.delete("/source");
|
|
987
975
|
this.data = await response.json();
|
|
988
976
|
return this;
|
|
989
977
|
}
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
* Creates a file shared link.
|
|
981
|
+
*
|
|
982
|
+
* @param permissions - Share permissions.
|
|
983
|
+
*/
|
|
984
|
+
async createSharedLink(permissions?: ISharedLinkPermissions): Promise<SharedLink> {
|
|
985
|
+
const shares = new Endpoint("/shares", this.httpClient, this.headers);
|
|
986
|
+
const response = await shares.post("", { fileId: this.id, permissions });
|
|
987
|
+
const data = await response.json();
|
|
988
|
+
await this.checkout();
|
|
989
|
+
return new SharedLink(data, this.httpClient);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Returns information about the file shared link or `undefined` if file is not shared.
|
|
994
|
+
*/
|
|
995
|
+
async getSharedLink(): Promise<SharedLink> {
|
|
996
|
+
if (!this.sharedLinkToken) return Promise.resolve(undefined);
|
|
997
|
+
const shares = new Endpoint("/shares", this.httpClient, this.headers);
|
|
998
|
+
const response = await shares.get(`/${this.sharedLinkToken}`);
|
|
999
|
+
const data = await response.json();
|
|
1000
|
+
return new SharedLink(data, this.httpClient);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Deletes the file shared link.
|
|
1005
|
+
*
|
|
1006
|
+
* @returns Returns the raw data of a deleted shared link. For more information, see
|
|
1007
|
+
* {@link https://cloud.opendesign.com/docs//pages/server/api.html#ShareLinks | Open Cloud SharedLinks API}.
|
|
1008
|
+
*/
|
|
1009
|
+
async deleteSharedLink(): Promise<any> {
|
|
1010
|
+
const shares = new Endpoint("/shares", this.httpClient, this.headers);
|
|
1011
|
+
const response = await shares.delete(`/${this.sharedLinkToken}`);
|
|
1012
|
+
const data = await response.json();
|
|
1013
|
+
await this.checkout();
|
|
1014
|
+
return data;
|
|
1015
|
+
}
|
|
990
1016
|
}
|
package/src/Api/HttpClient.ts
CHANGED
|
@@ -35,28 +35,51 @@ export class HttpClient implements IHttpClient {
|
|
|
35
35
|
this.serverUrl = serverUrl;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
get(relativePath: string,
|
|
39
|
-
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
38
|
+
get(relativePath: string, init: RequestInit = {}): Promise<Response> {
|
|
39
|
+
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
40
|
+
...init,
|
|
41
|
+
method: "GET",
|
|
42
|
+
headers: { ...this.headers, ...init.headers },
|
|
43
|
+
});
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
post(relativePath: string, body?: BodyInit | object): Promise<Response> {
|
|
43
|
-
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
46
|
+
post(relativePath: string, body?: BodyInit | object, init: RequestInit = {}): Promise<Response> {
|
|
47
|
+
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
48
|
+
...init,
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { ...this.headers, ...init.headers },
|
|
51
|
+
body,
|
|
52
|
+
});
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
put(relativePath: string, body?: BodyInit | object): Promise<Response> {
|
|
47
|
-
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
55
|
+
put(relativePath: string, body?: BodyInit | object, init: RequestInit = {}): Promise<Response> {
|
|
56
|
+
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
57
|
+
...init,
|
|
58
|
+
method: "PUT",
|
|
59
|
+
headers: { ...this.headers, ...init.headers },
|
|
60
|
+
body,
|
|
61
|
+
});
|
|
48
62
|
}
|
|
49
63
|
|
|
50
|
-
delete(relativePath: string): Promise<Response> {
|
|
51
|
-
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
64
|
+
delete(relativePath: string, init: RequestInit = {}): Promise<Response> {
|
|
65
|
+
return $fetch(`${this.serverUrl}${relativePath}`, {
|
|
66
|
+
...init,
|
|
67
|
+
method: "DELETE",
|
|
68
|
+
headers: { ...this.headers, ...init.headers },
|
|
69
|
+
});
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
uploadFile(
|
|
72
|
+
uploadFile(
|
|
73
|
+
relativePath: string,
|
|
74
|
+
file: File,
|
|
75
|
+
onProgress?: (progress: number) => void,
|
|
76
|
+
init: RequestInit = {}
|
|
77
|
+
): Promise<XMLHttpRequest> {
|
|
55
78
|
const data = new FormData();
|
|
56
79
|
data.append("file", file);
|
|
57
80
|
return $xmlhttp(`${this.serverUrl}${relativePath}`, {
|
|
58
81
|
method: "POST",
|
|
59
|
-
headers: this.headers,
|
|
82
|
+
headers: { ...this.headers, ...init.headers },
|
|
60
83
|
body: data,
|
|
61
84
|
uploadProgress: onProgress,
|
|
62
85
|
});
|
|
@@ -65,9 +88,9 @@ export class HttpClient implements IHttpClient {
|
|
|
65
88
|
// async downloadFile(
|
|
66
89
|
// relativePath: string,
|
|
67
90
|
// onProgress?: (progress: number, chunk: Uint8Array) => void,
|
|
68
|
-
//
|
|
91
|
+
// init: RequestInit = {}
|
|
69
92
|
// ): Promise<Response> {
|
|
70
|
-
// const response = await this.get(relativePath,
|
|
93
|
+
// const response = await this.get(relativePath, init);
|
|
71
94
|
// const teedOff = response.body.tee();
|
|
72
95
|
// if (onProgress) {
|
|
73
96
|
// const contentLength = response.headers.get("Content-Length");
|
|
@@ -87,9 +110,9 @@ export class HttpClient implements IHttpClient {
|
|
|
87
110
|
async downloadFile(
|
|
88
111
|
relativePath: string,
|
|
89
112
|
onProgress?: (progress: number, chunk: Uint8Array) => void,
|
|
90
|
-
|
|
113
|
+
init: RequestInit = {}
|
|
91
114
|
): Promise<Response> {
|
|
92
|
-
const response = await this.get(relativePath,
|
|
115
|
+
const response = await this.get(relativePath, init);
|
|
93
116
|
const contentLength = response.headers.get("Content-Length");
|
|
94
117
|
const total = parseInt(contentLength || "", 10) || 1;
|
|
95
118
|
return new Response(
|
|
@@ -115,11 +138,11 @@ export class HttpClient implements IHttpClient {
|
|
|
115
138
|
reserved: number,
|
|
116
139
|
ranges: Array<{ begin: number; end: number; requestId: number }>,
|
|
117
140
|
onProgress?: (progress: number, chunk: Uint8Array, requestId: number) => void,
|
|
118
|
-
|
|
141
|
+
init: RequestInit = {}
|
|
119
142
|
): Promise<Response> {
|
|
120
|
-
const headers = { ...
|
|
143
|
+
const headers = { ...init.headers };
|
|
121
144
|
headers["Range"] = "bytes=" + ranges.map((x) => `${x.begin}-${x.end}`).join(",");
|
|
122
|
-
const response = await
|
|
145
|
+
const response = await this.get(relativePath, { ...init, headers });
|
|
123
146
|
const contentLength = response.headers.get("content-length");
|
|
124
147
|
const total = parseInt(contentLength || "", 10) || 1;
|
|
125
148
|
return new Response(
|
package/src/Api/IFile.ts
CHANGED
|
@@ -129,7 +129,7 @@ export interface IFileVersionInfo {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* Defines the user, project, or group that will have access to the
|
|
132
|
+
* Defines the user, project, or group that will have access to the file.
|
|
133
133
|
*/
|
|
134
134
|
export interface IGrantedTo {
|
|
135
135
|
/**
|