@uploadista/expo 0.0.3
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 +21 -0
- package/README.md +567 -0
- package/expo-env.d.ts +3 -0
- package/package.json +45 -0
- package/src/client/create-uploadista-client.ts +67 -0
- package/src/client/index.ts +4 -0
- package/src/index.ts +77 -0
- package/src/services/abort-controller-factory.ts +32 -0
- package/src/services/base64-service.ts +29 -0
- package/src/services/checksum-service.ts +14 -0
- package/src/services/create-expo-services.ts +85 -0
- package/src/services/expo-file-system-provider.ts +227 -0
- package/src/services/file-reader-service.ts +184 -0
- package/src/services/fingerprint-service.ts +107 -0
- package/src/services/http-client.ts +235 -0
- package/src/services/id-generation-service.ts +14 -0
- package/src/services/index.ts +13 -0
- package/src/services/platform-service.ts +71 -0
- package/src/services/storage-service.ts +62 -0
- package/src/services/websocket-factory.ts +62 -0
- package/src/types/upload-input.ts +5 -0
- package/src/types.ts +116 -0
- package/src/utils/hash-util.ts +70 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as Crypto from "expo-crypto";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compute SHA-256 checksum using Web Crypto API
|
|
5
|
+
* Compatible with React Native and Expo environments
|
|
6
|
+
*
|
|
7
|
+
* @param data - Uint8Array to hash
|
|
8
|
+
* @returns Promise that resolves to hex-encoded SHA-256 checksum
|
|
9
|
+
*/
|
|
10
|
+
export async function computeUint8ArraySha256(
|
|
11
|
+
data: Uint8Array,
|
|
12
|
+
): Promise<string> {
|
|
13
|
+
try {
|
|
14
|
+
// Compute SHA-256 hash using Web Crypto API
|
|
15
|
+
const hashBuffer = await Crypto.digest(
|
|
16
|
+
Crypto.CryptoDigestAlgorithm.SHA256,
|
|
17
|
+
data,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// Convert hash to hex string
|
|
21
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
22
|
+
const hashHex = hashArray
|
|
23
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
24
|
+
.join("");
|
|
25
|
+
|
|
26
|
+
return hashHex;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Failed to compute checksum: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Compute SHA-256 checksum of a Blob using Web Crypto API
|
|
36
|
+
* Compatible with React Native and Expo Blob objects
|
|
37
|
+
*
|
|
38
|
+
* @param blob - Blob to hash
|
|
39
|
+
* @returns Promise that resolves to hex-encoded SHA-256 checksum
|
|
40
|
+
*/
|
|
41
|
+
export async function computeblobSha256(blob: Blob): Promise<string> {
|
|
42
|
+
try {
|
|
43
|
+
// Convert Blob to Uint8Array using FileReader for compatibility
|
|
44
|
+
const uint8Array = await blobToUint8Array(blob);
|
|
45
|
+
return computeUint8ArraySha256(uint8Array);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Failed to compute file checksum: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Convert Blob to Uint8Array using FileReader
|
|
55
|
+
* Works in React Native and Expo environments
|
|
56
|
+
*/
|
|
57
|
+
async function blobToUint8Array(blob: Blob): Promise<Uint8Array> {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const reader = new FileReader();
|
|
60
|
+
reader.onload = () => {
|
|
61
|
+
if (reader.result instanceof ArrayBuffer) {
|
|
62
|
+
resolve(new Uint8Array(reader.result));
|
|
63
|
+
} else {
|
|
64
|
+
reject(new Error("FileReader result is not an ArrayBuffer"));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
reader.onerror = () => reject(reader.error);
|
|
68
|
+
reader.readAsArrayBuffer(blob);
|
|
69
|
+
});
|
|
70
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@uploadista/typescript-config/base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"lib": ["ES2020", "ES2020.Promise"],
|
|
6
|
+
"baseUrl": "./",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@/*": ["./src/*"]
|
|
9
|
+
},
|
|
10
|
+
"typeRoots": ["../../node_modules/@types", "./src"],
|
|
11
|
+
"types": [],
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"rootDir": "./src"
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src/**/*.ts",
|
|
17
|
+
"src/**/*.d.ts",
|
|
18
|
+
".expo/types/**/*.ts",
|
|
19
|
+
"expo-env.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"dist",
|
|
24
|
+
"**/__tests__/**",
|
|
25
|
+
"**/*.test.ts",
|
|
26
|
+
"**/*.spec.ts"
|
|
27
|
+
]
|
|
28
|
+
}
|