@churchapps/helpers 1.0.34 → 1.0.35
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/FileHelper.d.ts +1 -1
- package/dist/FileHelper.d.ts.map +1 -1
- package/dist/FileHelper.js +27 -11
- package/dist/FileHelper.js.map +1 -1
- package/package.json +1 -2
- package/src/FileHelper.ts +29 -9
package/dist/FileHelper.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class FileHelper {
|
|
2
|
-
static postPresignedFile: (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void) => Promise<
|
|
2
|
+
static postPresignedFile: (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void) => Promise<unknown>;
|
|
3
3
|
static dataURLtoBlob(dataurl: string): Blob;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=FileHelper.d.ts.map
|
package/dist/FileHelper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileHelper.d.ts","sourceRoot":"","sources":["../src/FileHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileHelper.d.ts","sourceRoot":"","sources":["../src/FileHelper.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;IAErB,MAAM,CAAC,iBAAiB,GAAI,WAAW,GAAG,EAAE,cAAc,IAAI,EAAE,kBAAkB,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,sBAsCzG;IAEF,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;CAQrC"}
|
package/dist/FileHelper.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.FileHelper = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
4
|
class FileHelper {
|
|
9
5
|
static dataURLtoBlob(dataurl) {
|
|
10
6
|
let arr = dataurl.split(","), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
|
|
@@ -23,12 +19,32 @@ FileHelper.postPresignedFile = (presigned, uploadedFile, progressCallback) => {
|
|
|
23
19
|
for (const property in presigned.fields)
|
|
24
20
|
formData.append(property, presigned.fields[property]);
|
|
25
21
|
formData.append("file", uploadedFile);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
// Use XMLHttpRequest for upload progress tracking since fetch doesn't support it natively
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const xhr = new XMLHttpRequest();
|
|
25
|
+
xhr.upload.addEventListener('progress', (event) => {
|
|
26
|
+
if (event.lengthComputable) {
|
|
27
|
+
const percent = Math.round((event.loaded / event.total) * 100);
|
|
28
|
+
progressCallback(percent);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
xhr.addEventListener('load', () => {
|
|
32
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
33
|
+
resolve({
|
|
34
|
+
status: xhr.status,
|
|
35
|
+
statusText: xhr.statusText,
|
|
36
|
+
data: xhr.responseText
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
reject(new Error(`HTTP Error: ${xhr.status} ${xhr.statusText}`));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
xhr.addEventListener('error', () => {
|
|
44
|
+
reject(new Error('Network error occurred'));
|
|
45
|
+
});
|
|
46
|
+
xhr.open('POST', presigned.url);
|
|
47
|
+
xhr.send(formData);
|
|
48
|
+
});
|
|
33
49
|
};
|
|
34
50
|
//# sourceMappingURL=FileHelper.js.map
|
package/dist/FileHelper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileHelper.js","sourceRoot":"","sources":["../src/FileHelper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileHelper.js","sourceRoot":"","sources":["../src/FileHelper.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAU;IA0CrB,MAAM,CAAC,aAAa,CAAC,OAAe;QAClC,IAAI,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC7D,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,EAAE,EAAE,CAAC;YACX,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;;AAjDH,gCAkDC;AAhDQ,4BAAiB,GAAG,CAAC,SAAc,EAAE,YAAkB,EAAE,gBAA2C,EAAE,EAAE;IAC7G,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;IACnD,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,MAAM;QAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,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GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@churchapps/helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"description": "Library of helper functions not specific to any one ChurchApps project or framework.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"typescript": "^5.8.3"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"axios": "^1.9.0",
|
|
33
32
|
"date-fns": "^4.1.0",
|
|
34
33
|
"dayjs": "^1.11.13",
|
|
35
34
|
"react-ga4": "^2.1.0",
|
package/src/FileHelper.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
1
|
export class FileHelper {
|
|
4
2
|
|
|
5
3
|
static postPresignedFile = (presigned: any, uploadedFile: File, progressCallback: (percent: number) => void) => {
|
|
@@ -10,14 +8,36 @@ export class FileHelper {
|
|
|
10
8
|
for (const property in presigned.fields) formData.append(property, presigned.fields[property]);
|
|
11
9
|
formData.append("file", uploadedFile);
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
// Use XMLHttpRequest for upload progress tracking since fetch doesn't support it natively
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const xhr = new XMLHttpRequest();
|
|
14
|
+
|
|
15
|
+
xhr.upload.addEventListener('progress', (event) => {
|
|
16
|
+
if (event.lengthComputable) {
|
|
17
|
+
const percent = Math.round((event.loaded / event.total) * 100);
|
|
18
|
+
progressCallback(percent);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
xhr.addEventListener('load', () => {
|
|
23
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
24
|
+
resolve({
|
|
25
|
+
status: xhr.status,
|
|
26
|
+
statusText: xhr.statusText,
|
|
27
|
+
data: xhr.responseText
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
reject(new Error(`HTTP Error: ${xhr.status} ${xhr.statusText}`));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
xhr.addEventListener('error', () => {
|
|
35
|
+
reject(new Error('Network error occurred'));
|
|
36
|
+
});
|
|
19
37
|
|
|
20
|
-
|
|
38
|
+
xhr.open('POST', presigned.url);
|
|
39
|
+
xhr.send(formData);
|
|
40
|
+
});
|
|
21
41
|
};
|
|
22
42
|
|
|
23
43
|
static dataURLtoBlob(dataurl: string) {
|