@acorex/core 18.5.17 → 18.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/esm2022/network/lib/network.types.mjs +2 -1
- package/esm2022/network/lib/upload-task.mjs +27 -18
- package/fesm2022/acorex-core-network.mjs +26 -16
- package/fesm2022/acorex-core-network.mjs.map +1 -1
- package/network/lib/network.types.d.ts +2 -1
- package/network/lib/upload-task.d.ts +1 -1
- package/package.json +13 -13
@@ -4,6 +4,7 @@ export var AXUploadStatus;
|
|
4
4
|
AXUploadStatus["UploadComplete"] = "Upload complete";
|
5
5
|
AXUploadStatus["StartingUpload"] = "Starting upload";
|
6
6
|
AXUploadStatus["UploadFailed"] = "Upload failed";
|
7
|
+
AXUploadStatus["UploadCanceled"] = "Upload Canceled";
|
7
8
|
})(AXUploadStatus || (AXUploadStatus = {}));
|
8
9
|
export var AXDownloadStatus;
|
9
10
|
(function (AXDownloadStatus) {
|
@@ -12,4 +13,4 @@ export var AXDownloadStatus;
|
|
12
13
|
AXDownloadStatus["StartingDownload"] = "Starting download";
|
13
14
|
AXDownloadStatus["DownloadFailed"] = "Download failed";
|
14
15
|
})(AXDownloadStatus || (AXDownloadStatus = {}));
|
15
|
-
//# sourceMappingURL=data:application/json;base64,
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmV0d29yay50eXBlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL2xpYnMvY29yZS9uZXR3b3JrL3NyYy9saWIvbmV0d29yay50eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQU4sSUFBWSxjQU1YO0FBTkQsV0FBWSxjQUFjO0lBQ3RCLDRDQUEwQixDQUFBO0lBQzFCLG9EQUFrQyxDQUFBO0lBQ2xDLG9EQUFrQyxDQUFBO0lBQ2xDLGdEQUE4QixDQUFBO0lBQzlCLG9EQUFrQyxDQUFBO0FBQ3RDLEN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ZCBmYWlsZWRcIlxufVxuXG5leHBvcnQgdHlwZSBBWERvd25sb2FkUmVzcG9uc2UgPSB7XG4gICAgcHJvZ3Jlc3M6IG51bWJlcjtcbiAgICBieXRlc1JlY2VpdmVkOiBudW1iZXI7XG4gICAgdG90YWxCeXRlczogbnVtYmVyO1xuICAgIHN0YXR1czogQVhEb3dubG9hZFN0YXR1cztcbiAgICBkYXRhPzogQmxvYjsgLy8gb3IgYW55IGFwcHJvcHJpYXRlIHR5cGUgYmFzZWQgb24geW91ciBzcGVjaWZpYyB1c2UgY2FzZVxufTtcbiJdfQ==
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Subject } from 'rxjs';
|
2
|
-
import { takeUntil, map } from 'rxjs/operators';
|
3
1
|
import { HttpEventType } from '@angular/common/http';
|
2
|
+
import { Subject } from 'rxjs';
|
3
|
+
import { map, takeUntil } from 'rxjs/operators';
|
4
4
|
import { AXUploadStatus } from './network.types'; // Ensure correct import path
|
5
5
|
export class AXUploadTask {
|
6
6
|
constructor(observable, totalFileSize) {
|
@@ -9,34 +9,43 @@ export class AXUploadTask {
|
|
9
9
|
this.cancelSignal = new Subject();
|
10
10
|
}
|
11
11
|
get events() {
|
12
|
-
return this.observable.pipe(takeUntil(this.cancelSignal), map(event => this.handleEvent(event)));
|
12
|
+
return this.observable.pipe(takeUntil(this.cancelSignal), map((event) => this.handleEvent(event)));
|
13
13
|
}
|
14
14
|
handleEvent(event) {
|
15
|
+
console.log(event.type);
|
15
16
|
switch (event.type) {
|
17
|
+
case HttpEventType.Sent:
|
18
|
+
case HttpEventType.ResponseHeader:
|
19
|
+
return {
|
20
|
+
progress: 0,
|
21
|
+
bytesTransferred: 0,
|
22
|
+
totalBytes: this.totalFileSize,
|
23
|
+
status: AXUploadStatus.StartingUpload,
|
24
|
+
};
|
16
25
|
case HttpEventType.UploadProgress:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
case HttpEventType.DownloadProgress: {
|
27
|
+
const percentDone = Math.round((100 * event.loaded) / (this.totalFileSize || event.total));
|
28
|
+
return {
|
29
|
+
progress: percentDone,
|
30
|
+
bytesTransferred: event.loaded,
|
31
|
+
totalBytes: this.totalFileSize || event.total,
|
32
|
+
status: AXUploadStatus.Uploading,
|
33
|
+
};
|
34
|
+
}
|
26
35
|
case HttpEventType.Response:
|
27
36
|
return {
|
28
37
|
progress: 100,
|
29
38
|
bytesTransferred: this.totalFileSize,
|
30
39
|
totalBytes: this.totalFileSize,
|
31
40
|
status: AXUploadStatus.UploadComplete,
|
32
|
-
result: event.body
|
41
|
+
result: event.body,
|
33
42
|
};
|
34
|
-
|
43
|
+
case HttpEventType.User:
|
35
44
|
return {
|
36
45
|
progress: 0,
|
37
|
-
bytesTransferred:
|
38
|
-
totalBytes:
|
39
|
-
status: AXUploadStatus.
|
46
|
+
bytesTransferred: this.totalFileSize,
|
47
|
+
totalBytes: this.totalFileSize,
|
48
|
+
status: AXUploadStatus.UploadCanceled,
|
40
49
|
};
|
41
50
|
}
|
42
51
|
}
|
@@ -45,4 +54,4 @@ export class AXUploadTask {
|
|
45
54
|
this.cancelSignal.complete();
|
46
55
|
}
|
47
56
|
}
|
48
|
-
//# sourceMappingURL=data:application/json;base64,
|
57
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBsb2FkLXRhc2suanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9saWJzL2NvcmUvbmV0d29yay9zcmMvbGliL3VwbG9hZC10YXNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBYSxhQUFhLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUNoRSxPQUFPLEVBQWMsT0FBTyxFQUFFLE1BQU0sTUFBTSxDQUFDO0FBQzNDLE9BQU8sRUFBRSxHQUFHL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SxcbiAgICAgICAgICBzdGF0dXM6IEFYVXBsb2FkU3RhdHVzLlVwbG9hZENvbXBsZXRlLFxuICAgICAgICAgIHJlc3VsdDogZXZlbnQuYm9keSxcbiAgICAgICAgfTtcblxuICAgICAgY2FzZSBIdHRwRXZlbnRUeXBlLlVzZXI6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgcHJvZ3Jlc3M6IDAsXG4gICAgICAgICAgYnl0ZXNUcmFuc2ZlcnJlZDogdGhpcy50b3RhbEZpbGVTaXplLFxuICAgICAgICAgIHRvdGFsQnl0ZXM6IHRoaXMudG90YWxGaWxlU2l6ZSxcbiAgICAgICAgICBzdGF0dXM6IEFYVXBsb2FkU3RhdHVzLlVwbG9hZENhbmNlbGVkLFxuICAgICAgICB9O1xuICAgIH1cbiAgfVxuXG4gIGNhbmNlbCgpIHtcbiAgICB0aGlzLmNhbmNlbFNpZ25hbC5uZXh0KCk7XG4gICAgdGhpcy5jYW5jZWxTaWduYWwuY29tcGxldGUoKTtcbiAgfVxufVxuIl19
|
@@ -1,6 +1,6 @@
|
|
1
|
+
import { HttpEventType, HttpClient, HttpRequest } from '@angular/common/http';
|
1
2
|
import { Subject, fromEvent, map as map$1, merge, startWith } from 'rxjs';
|
2
3
|
import { takeUntil, map } from 'rxjs/operators';
|
3
|
-
import { HttpEventType, HttpClient, HttpRequest } from '@angular/common/http';
|
4
4
|
import * as i0 from '@angular/core';
|
5
5
|
import { inject, signal, Injectable } from '@angular/core';
|
6
6
|
import { isBrowser } from '@acorex/core/platform';
|
@@ -11,6 +11,7 @@ var AXUploadStatus;
|
|
11
11
|
AXUploadStatus["UploadComplete"] = "Upload complete";
|
12
12
|
AXUploadStatus["StartingUpload"] = "Starting upload";
|
13
13
|
AXUploadStatus["UploadFailed"] = "Upload failed";
|
14
|
+
AXUploadStatus["UploadCanceled"] = "Upload Canceled";
|
14
15
|
})(AXUploadStatus || (AXUploadStatus = {}));
|
15
16
|
var AXDownloadStatus;
|
16
17
|
(function (AXDownloadStatus) {
|
@@ -27,34 +28,43 @@ class AXUploadTask {
|
|
27
28
|
this.cancelSignal = new Subject();
|
28
29
|
}
|
29
30
|
get events() {
|
30
|
-
return this.observable.pipe(takeUntil(this.cancelSignal), map(event => this.handleEvent(event)));
|
31
|
+
return this.observable.pipe(takeUntil(this.cancelSignal), map((event) => this.handleEvent(event)));
|
31
32
|
}
|
32
33
|
handleEvent(event) {
|
34
|
+
console.log(event.type);
|
33
35
|
switch (event.type) {
|
36
|
+
case HttpEventType.Sent:
|
37
|
+
case HttpEventType.ResponseHeader:
|
38
|
+
return {
|
39
|
+
progress: 0,
|
40
|
+
bytesTransferred: 0,
|
41
|
+
totalBytes: this.totalFileSize,
|
42
|
+
status: AXUploadStatus.StartingUpload,
|
43
|
+
};
|
34
44
|
case HttpEventType.UploadProgress:
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
case HttpEventType.DownloadProgress: {
|
46
|
+
const percentDone = Math.round((100 * event.loaded) / (this.totalFileSize || event.total));
|
47
|
+
return {
|
48
|
+
progress: percentDone,
|
49
|
+
bytesTransferred: event.loaded,
|
50
|
+
totalBytes: this.totalFileSize || event.total,
|
51
|
+
status: AXUploadStatus.Uploading,
|
52
|
+
};
|
53
|
+
}
|
44
54
|
case HttpEventType.Response:
|
45
55
|
return {
|
46
56
|
progress: 100,
|
47
57
|
bytesTransferred: this.totalFileSize,
|
48
58
|
totalBytes: this.totalFileSize,
|
49
59
|
status: AXUploadStatus.UploadComplete,
|
50
|
-
result: event.body
|
60
|
+
result: event.body,
|
51
61
|
};
|
52
|
-
|
62
|
+
case HttpEventType.User:
|
53
63
|
return {
|
54
64
|
progress: 0,
|
55
|
-
bytesTransferred:
|
56
|
-
totalBytes:
|
57
|
-
status: AXUploadStatus.
|
65
|
+
bytesTransferred: this.totalFileSize,
|
66
|
+
totalBytes: this.totalFileSize,
|
67
|
+
status: AXUploadStatus.UploadCanceled,
|
58
68
|
};
|
59
69
|
}
|
60
70
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"acorex-core-network.mjs","sources":["../../../../libs/core/network/src/lib/network.types.ts","../../../../libs/core/network/src/lib/upload-task.ts","../../../../libs/core/network/src/lib/download-task.ts","../../../../libs/core/network/src/lib/network.service.ts","../../../../libs/core/network/src/acorex-core-network.ts"],"sourcesContent":["export enum AXUploadStatus {\n Uploading = \"Uploading...\",\n UploadComplete = \"Upload complete\",\n StartingUpload = \"Starting upload\",\n UploadFailed = \"Upload failed\"\n}\n\nexport type AXUploadResponse<T> = {\n progress: number;\n bytesTransferred: number;\n totalBytes: number;\n status: AXUploadStatus;\n result?: T;\n};\n\nexport enum AXDownloadStatus {\n Downloading = \"Downloading...\",\n DownloadComplete = \"Download complete\",\n StartingDownload = \"Starting download\",\n DownloadFailed = \"Download failed\"\n}\n\nexport type AXDownloadResponse = {\n progress: number;\n bytesReceived: number;\n totalBytes: number;\n status: AXDownloadStatus;\n data?: Blob; // or any appropriate type based on your specific use case\n};\n","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXUploadResponse, AXUploadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXUploadTask<T> {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<T>>, private totalFileSize: number) { }\n\n get events(): Observable<AXUploadResponse<T>> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event))\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXUploadResponse<T> {\n switch (event.type) {\n case HttpEventType.UploadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (this.totalFileSize || event.total));\n return {\n progress: percentDone,\n bytesTransferred: event.loaded,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.Uploading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesTransferred: this.totalFileSize,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.UploadComplete,\n result: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesTransferred: 0,\n totalBytes: 0,\n status: AXUploadStatus.StartingUpload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXDownloadResponse, AXDownloadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXDownloadTask {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<any>>) { }\n\n get events(): Observable<AXDownloadResponse> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event)),\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXDownloadResponse {\n switch (event.type) {\n case HttpEventType.DownloadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (event.total ?? event.loaded));\n return {\n progress: percentDone,\n bytesReceived: event.loaded,\n totalBytes: event.total ?? 0,\n status: AXDownloadStatus.Downloading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesReceived: event.body.size,\n totalBytes: event.body.size,\n status: AXDownloadStatus.DownloadComplete,\n data: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesReceived: 0,\n totalBytes: 0,\n status: AXDownloadStatus.StartingDownload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { HttpRequest, HttpClient } from '@angular/common/http';\nimport { inject, Injectable, signal } from '@angular/core';\nimport { AXDownloadTask } from './download-task';\nimport { AXUploadTask } from './upload-task';\nimport { fromEvent, map, merge, startWith } from 'rxjs';\nimport { isBrowser } from '@acorex/core/platform';\n\n\n\n@Injectable({ providedIn: 'root' })\nexport class AXNetworkService {\n\n private http = inject(HttpClient);\n\n private _status = signal<boolean>(true);\n\n public readonly status = this._status.asReadonly();\n\n constructor() {\n if (isBrowser()) {\n // Only subscribe to these events if on the browser platform\n const onlineEvent = fromEvent(window, 'online').pipe(map(() => true));\n const offlineEvent = fromEvent(window, 'offline').pipe(map(() => false));\n\n merge(onlineEvent, offlineEvent).pipe(\n startWith(navigator.onLine)\n ).subscribe(c => {\n this._status.set(c);\n });\n }\n }\n\n // Overload signatures\n upload<T>(url: string, formData: FormData): AXUploadTask<T>;\n upload<T>(request: HttpRequest<any>): AXUploadTask<T>;\n\n // Unified method handling both types of inputs\n upload<T>(arg1: string | HttpRequest<any>, arg2?: FormData): AXUploadTask<T> {\n let request: HttpRequest<any>;\n let totalFilesSize = 0;\n\n if (typeof arg1 === 'string' && arg2 instanceof FormData) {\n // Calculate total file size\n arg2.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n request = new HttpRequest('POST', arg1, arg2, {\n reportProgress: true,\n responseType: 'json'\n });\n } else if (arg1 instanceof HttpRequest) {\n if (arg1.body instanceof FormData) {\n // Calculate total file size\n arg1.body.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n }\n request = arg1.clone({\n reportProgress: true,\n responseType: arg1.responseType || 'json'\n });\n } else {\n throw new Error(\"Invalid arguments for upload method.\");\n }\n\n const events = this.http.request<T>(request);\n return new AXUploadTask<T>(events, totalFilesSize);\n }\n\n\n\n // Overload signatures\n download(url: string): AXDownloadTask;\n download(request: HttpRequest<Blob>): AXDownloadTask;\n\n // Unified method handling both types of inputs\n download(arg: string | HttpRequest<Blob>): AXDownloadTask {\n let request: HttpRequest<Blob>;\n\n if (typeof arg === 'string') {\n request = new HttpRequest('GET', arg, {\n reportProgress: true,\n responseType: 'blob',\n });\n } else {\n request = new HttpRequest(arg.method, arg.url, arg.body, {\n ...arg,\n reportProgress: true,\n responseType: 'blob',\n });\n }\n\n const events = this.http.request<Blob>(request);\n return new AXDownloadTask(events);\n }\n\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';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,cAAc,CAAC,MAAM,CAAC,CAAC;KACrC;8GAxFQ,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAAhB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cADH,MAAM,EAAA,CAAA,CAAA,EAAA;;2FACnB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;ACTlC;;AAEG;;;;"}
|
1
|
+
{"version":3,"file":"acorex-core-network.mjs","sources":["../../../../libs/core/network/src/lib/network.types.ts","../../../../libs/core/network/src/lib/upload-task.ts","../../../../libs/core/network/src/lib/download-task.ts","../../../../libs/core/network/src/lib/network.service.ts","../../../../libs/core/network/src/acorex-core-network.ts"],"sourcesContent":["export enum AXUploadStatus {\n Uploading = \"Uploading...\",\n UploadComplete = \"Upload complete\",\n StartingUpload = \"Starting upload\",\n UploadFailed = \"Upload failed\",\n UploadCanceled = \"Upload Canceled\",\n}\n\nexport type AXUploadResponse<T> = {\n progress: number;\n bytesTransferred: number;\n totalBytes: number;\n status: AXUploadStatus;\n result?: T;\n};\n\nexport enum AXDownloadStatus {\n Downloading = \"Downloading...\",\n DownloadComplete = \"Download complete\",\n StartingDownload = \"Starting download\",\n DownloadFailed = \"Download failed\"\n}\n\nexport type AXDownloadResponse = {\n progress: number;\n bytesReceived: number;\n totalBytes: number;\n status: AXDownloadStatus;\n data?: Blob; // or any appropriate type based on your specific use case\n};\n","import { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { Observable, Subject } from 'rxjs';\nimport { map, takeUntil } from 'rxjs/operators';\nimport { AXUploadResponse, AXUploadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXUploadTask<T> {\n private cancelSignal = new Subject<void>();\n\n constructor(\n private observable: Observable<HttpEvent<T>>,\n private totalFileSize: number,\n ) {}\n\n get events(): Observable<AXUploadResponse<T>> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map((event) => this.handleEvent(event)),\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXUploadResponse<T> {\n console.log(event.type);\n switch (event.type) {\n case HttpEventType.Sent:\n case HttpEventType.ResponseHeader:\n return {\n progress: 0,\n bytesTransferred: 0,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.StartingUpload,\n };\n\n case HttpEventType.UploadProgress:\n case HttpEventType.DownloadProgress: {\n const percentDone = Math.round((100 * event.loaded) / (this.totalFileSize || event.total));\n\n return {\n progress: percentDone,\n bytesTransferred: event.loaded,\n totalBytes: this.totalFileSize || event.total,\n status: AXUploadStatus.Uploading,\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesTransferred: this.totalFileSize,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.UploadComplete,\n result: event.body,\n };\n\n case HttpEventType.User:\n return {\n progress: 0,\n bytesTransferred: this.totalFileSize,\n totalBytes: this.totalFileSize,\n status: AXUploadStatus.UploadCanceled,\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { Observable, Subject } from 'rxjs';\nimport { takeUntil, map } from 'rxjs/operators';\nimport { HttpEvent, HttpEventType } from '@angular/common/http';\nimport { AXDownloadResponse, AXDownloadStatus } from './network.types'; // Ensure correct import path\n\nexport class AXDownloadTask {\n private cancelSignal = new Subject<void>();\n\n constructor(private observable: Observable<HttpEvent<any>>) { }\n\n get events(): Observable<AXDownloadResponse> {\n return this.observable.pipe(\n takeUntil(this.cancelSignal),\n map(event => this.handleEvent(event)),\n );\n }\n\n private handleEvent(event: HttpEvent<any>): AXDownloadResponse {\n switch (event.type) {\n case HttpEventType.DownloadProgress:\n {\n const percentDone = Math.round(100 * event.loaded / (event.total ?? event.loaded));\n return {\n progress: percentDone,\n bytesReceived: event.loaded,\n totalBytes: event.total ?? 0,\n status: AXDownloadStatus.Downloading\n };\n }\n\n case HttpEventType.Response:\n return {\n progress: 100,\n bytesReceived: event.body.size,\n totalBytes: event.body.size,\n status: AXDownloadStatus.DownloadComplete,\n data: event.body\n };\n\n default:\n return {\n progress: 0,\n bytesReceived: 0,\n totalBytes: 0,\n status: AXDownloadStatus.StartingDownload\n };\n }\n }\n\n cancel() {\n this.cancelSignal.next();\n this.cancelSignal.complete();\n }\n}\n","import { HttpRequest, HttpClient } from '@angular/common/http';\nimport { inject, Injectable, signal } from '@angular/core';\nimport { AXDownloadTask } from './download-task';\nimport { AXUploadTask } from './upload-task';\nimport { fromEvent, map, merge, startWith } from 'rxjs';\nimport { isBrowser } from '@acorex/core/platform';\n\n\n\n@Injectable({ providedIn: 'root' })\nexport class AXNetworkService {\n\n private http = inject(HttpClient);\n\n private _status = signal<boolean>(true);\n\n public readonly status = this._status.asReadonly();\n\n constructor() {\n if (isBrowser()) {\n // Only subscribe to these events if on the browser platform\n const onlineEvent = fromEvent(window, 'online').pipe(map(() => true));\n const offlineEvent = fromEvent(window, 'offline').pipe(map(() => false));\n\n merge(onlineEvent, offlineEvent).pipe(\n startWith(navigator.onLine)\n ).subscribe(c => {\n this._status.set(c);\n });\n }\n }\n\n // Overload signatures\n upload<T>(url: string, formData: FormData): AXUploadTask<T>;\n upload<T>(request: HttpRequest<any>): AXUploadTask<T>;\n\n // Unified method handling both types of inputs\n upload<T>(arg1: string | HttpRequest<any>, arg2?: FormData): AXUploadTask<T> {\n let request: HttpRequest<any>;\n let totalFilesSize = 0;\n\n if (typeof arg1 === 'string' && arg2 instanceof FormData) {\n // Calculate total file size\n arg2.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n request = new HttpRequest('POST', arg1, arg2, {\n reportProgress: true,\n responseType: 'json'\n });\n } else if (arg1 instanceof HttpRequest) {\n if (arg1.body instanceof FormData) {\n // Calculate total file size\n arg1.body.forEach((value) => {\n if (value instanceof File) {\n totalFilesSize += value.size;\n }\n });\n }\n request = arg1.clone({\n reportProgress: true,\n responseType: arg1.responseType || 'json'\n });\n } else {\n throw new Error(\"Invalid arguments for upload method.\");\n }\n\n const events = this.http.request<T>(request);\n return new AXUploadTask<T>(events, totalFilesSize);\n }\n\n\n\n // Overload signatures\n download(url: string): AXDownloadTask;\n download(request: HttpRequest<Blob>): AXDownloadTask;\n\n // Unified method handling both types of inputs\n download(arg: string | HttpRequest<Blob>): AXDownloadTask {\n let request: HttpRequest<Blob>;\n\n if (typeof arg === 'string') {\n request = new HttpRequest('GET', arg, {\n reportProgress: true,\n responseType: 'blob',\n });\n } else {\n request = new HttpRequest(arg.method, arg.url, arg.body, {\n ...arg,\n reportProgress: true,\n responseType: 'blob',\n });\n }\n\n const events = this.http.request<Blob>(request);\n return new AXDownloadTask(events);\n }\n\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["map"],"mappings":";;;;;;;IAAY,eAMX;AAND,CAAA,UAAY,cAAc,EAAA;AACtB,IAAA,cAAA,CAAA,WAAA,CAAA,GAAA,cAA0B,CAAA;AAC1B,IAAA,cAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,cAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,eAA8B,CAAA;AAC9B,IAAA,cAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AACtC,CAAC,EANW,cAAc,KAAd,cAAc,GAMzB,EAAA,CAAA,CAAA,CAAA;IAUW,iBAKX;AALD,CAAA,UAAY,gBAAgB,EAAA;AACxB,IAAA,gBAAA,CAAA,aAAA,CAAA,GAAA,gBAA8B,CAAA;AAC9B,IAAA,gBAAA,CAAA,kBAAA,CAAA,GAAA,mBAAsC,CAAA;AACtC,IAAA,gBAAA,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A,UAAA,EAAA,CAAA,CAAA,EAAA;AAAhB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cADH,MAAM,EAAA,CAAA,CAAA,EAAA;;2FACnB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;;;ACTlC;;AAEG;;;;"}
|
@@ -2,7 +2,8 @@ export declare enum AXUploadStatus {
|
|
2
2
|
Uploading = "Uploading...",
|
3
3
|
UploadComplete = "Upload complete",
|
4
4
|
StartingUpload = "Starting upload",
|
5
|
-
UploadFailed = "Upload failed"
|
5
|
+
UploadFailed = "Upload failed",
|
6
|
+
UploadCanceled = "Upload Canceled"
|
6
7
|
}
|
7
8
|
export type AXUploadResponse<T> = {
|
8
9
|
progress: number;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@acorex/core",
|
3
|
-
"version": "18.
|
3
|
+
"version": "18.6.0",
|
4
4
|
"peerDependencies": {
|
5
5
|
"@angular/common": ">=18.0.0",
|
6
6
|
"@angular/core": ">=18.0.0",
|
@@ -32,12 +32,24 @@
|
|
32
32
|
"esm": "./esm2022/common/acorex-core-common.mjs",
|
33
33
|
"default": "./fesm2022/acorex-core-common.mjs"
|
34
34
|
},
|
35
|
+
"./config": {
|
36
|
+
"types": "./config/index.d.ts",
|
37
|
+
"esm2022": "./esm2022/config/acorex-core-config.mjs",
|
38
|
+
"esm": "./esm2022/config/acorex-core-config.mjs",
|
39
|
+
"default": "./fesm2022/acorex-core-config.mjs"
|
40
|
+
},
|
35
41
|
"./date-time": {
|
36
42
|
"types": "./date-time/index.d.ts",
|
37
43
|
"esm2022": "./esm2022/date-time/acorex-core-date-time.mjs",
|
38
44
|
"esm": "./esm2022/date-time/acorex-core-date-time.mjs",
|
39
45
|
"default": "./fesm2022/acorex-core-date-time.mjs"
|
40
46
|
},
|
47
|
+
"./events": {
|
48
|
+
"types": "./events/index.d.ts",
|
49
|
+
"esm2022": "./esm2022/events/acorex-core-events.mjs",
|
50
|
+
"esm": "./esm2022/events/acorex-core-events.mjs",
|
51
|
+
"default": "./fesm2022/acorex-core-events.mjs"
|
52
|
+
},
|
41
53
|
"./file": {
|
42
54
|
"types": "./file/index.d.ts",
|
43
55
|
"esm2022": "./esm2022/file/acorex-core-file.mjs",
|
@@ -50,18 +62,6 @@
|
|
50
62
|
"esm": "./esm2022/format/acorex-core-format.mjs",
|
51
63
|
"default": "./fesm2022/acorex-core-format.mjs"
|
52
64
|
},
|
53
|
-
"./config": {
|
54
|
-
"types": "./config/index.d.ts",
|
55
|
-
"esm2022": "./esm2022/config/acorex-core-config.mjs",
|
56
|
-
"esm": "./esm2022/config/acorex-core-config.mjs",
|
57
|
-
"default": "./fesm2022/acorex-core-config.mjs"
|
58
|
-
},
|
59
|
-
"./events": {
|
60
|
-
"types": "./events/index.d.ts",
|
61
|
-
"esm2022": "./esm2022/events/acorex-core-events.mjs",
|
62
|
-
"esm": "./esm2022/events/acorex-core-events.mjs",
|
63
|
-
"default": "./fesm2022/acorex-core-events.mjs"
|
64
|
-
},
|
65
65
|
"./image": {
|
66
66
|
"types": "./image/index.d.ts",
|
67
67
|
"esm2022": "./esm2022/image/acorex-core-image.mjs",
|