@amityco/ts-sdk-react-native 6.28.0 → 6.28.1-09c5133.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/.env +26 -26
- package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
- package/dist/fileRepository/utils/rebuildFormDataWithMimeType.d.ts +2 -0
- package/dist/fileRepository/utils/rebuildFormDataWithMimeType.d.ts.map +1 -0
- package/dist/index.cjs.js +24 -10
- package/dist/index.esm.js +23 -10
- package/dist/index.umd.js +3 -3
- package/dist/storyRepository/utils/createOptimisticEvent.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/fileRepository/api/uploadFile.ts +10 -5
- package/src/fileRepository/api/uploadImage.ts +2 -1
- package/src/fileRepository/api/uploadVideo.ts +2 -1
- package/src/fileRepository/utils/rebuildFormDataWithMimeType.ts +16 -0
- package/src/storyRepository/utils/createOptimisticEvent.ts +14 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOptimisticEvent.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/utils/createOptimisticEvent.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,qBAAqB;aAMrB,MAAM,kBAAkB;;;8BAIR,MAAM,YAAY,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"createOptimisticEvent.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/utils/createOptimisticEvent.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,qBAAqB;aAMrB,MAAM,kBAAkB;;;8BAIR,MAAM,YAAY,KAAK,IAAI,SAiCvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amityco/ts-sdk-react-native",
|
|
3
|
-
"version": "6.28.0",
|
|
3
|
+
"version": "6.28.1-09c5133.0",
|
|
4
4
|
"license": "CC-BY-ND-4.0",
|
|
5
5
|
"author": "amity.co <developers@amity.co> (https://amity.co)",
|
|
6
6
|
"description": "Amity Social Cloud Typescript SDK",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"test": "jest",
|
|
33
33
|
"test:coverage": "jest --coverage --silent"
|
|
34
34
|
},
|
|
35
|
-
"private": false,
|
|
36
35
|
"publishConfig": {
|
|
37
36
|
"access": "public"
|
|
38
37
|
},
|
|
@@ -72,6 +71,7 @@
|
|
|
72
71
|
"debug": "^4.3.4",
|
|
73
72
|
"hls.js": "^1.4.10",
|
|
74
73
|
"js-base64": "^3.7.2",
|
|
74
|
+
"mime": "3.0.0",
|
|
75
75
|
"mitt": "^3.0.0",
|
|
76
76
|
"mqtt": "^4.3.7",
|
|
77
77
|
"object-hash": "^3.0.0",
|
|
@@ -2,6 +2,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
5
|
+
import { rebuildFormDataWithMimeType } from '~/fileRepository/utils/rebuildFormDataWithMimeType';
|
|
5
6
|
|
|
6
7
|
/* begin_public_function
|
|
7
8
|
id: file.upload.file
|
|
@@ -42,12 +43,16 @@ export const uploadFile = async <T extends Amity.FileType = any>(
|
|
|
42
43
|
? (formData as any).getHeaders()
|
|
43
44
|
: { 'content-type': 'multipart/form-data' };
|
|
44
45
|
|
|
45
|
-
const { data } = await client.http.post<Amity.CreateFilePayload<T>>(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const { data } = await client.http.post<Amity.CreateFilePayload<T>>(
|
|
47
|
+
'/api/v4/files',
|
|
48
|
+
rebuildFormDataWithMimeType(formData),
|
|
49
|
+
{
|
|
50
|
+
headers,
|
|
51
|
+
onUploadProgress({ loaded, total = 100 }) {
|
|
52
|
+
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
53
|
+
},
|
|
49
54
|
},
|
|
50
|
-
|
|
55
|
+
);
|
|
51
56
|
|
|
52
57
|
// API-FIX: payload should be serialized properly
|
|
53
58
|
// const { files } = data
|
|
@@ -2,6 +2,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
5
|
+
import { rebuildFormDataWithMimeType } from '../utils/rebuildFormDataWithMimeType';
|
|
5
6
|
|
|
6
7
|
/* begin_public_function
|
|
7
8
|
id: file.upload.image
|
|
@@ -44,7 +45,7 @@ export const uploadImage = async (
|
|
|
44
45
|
|
|
45
46
|
const { data } = await client.http.post<Amity.CreateFilePayload<'image'>>(
|
|
46
47
|
'/api/v4/images',
|
|
47
|
-
formData,
|
|
48
|
+
rebuildFormDataWithMimeType(formData),
|
|
48
49
|
{
|
|
49
50
|
headers,
|
|
50
51
|
onUploadProgress({ loaded, total = 100 }) {
|
|
@@ -2,6 +2,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
5
|
+
import { rebuildFormDataWithMimeType } from '../utils/rebuildFormDataWithMimeType';
|
|
5
6
|
|
|
6
7
|
/* begin_public_function
|
|
7
8
|
id: file.upload.video, file.upload.audio
|
|
@@ -50,7 +51,7 @@ export const uploadVideo = async (
|
|
|
50
51
|
|
|
51
52
|
const { data } = await client.http.post<Amity.CreateFilePayload<'video'>>(
|
|
52
53
|
'/api/v4/videos',
|
|
53
|
-
formData,
|
|
54
|
+
rebuildFormDataWithMimeType(formData),
|
|
54
55
|
{
|
|
55
56
|
headers,
|
|
56
57
|
onUploadProgress({ loaded, total = 100 }) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import mime from 'mime';
|
|
2
|
+
|
|
3
|
+
export const rebuildFormDataWithMimeType = (formData: FormData): FormData => {
|
|
4
|
+
const files = formData.getAll('files') || [];
|
|
5
|
+
if (!files.length) return formData;
|
|
6
|
+
|
|
7
|
+
const newFormData = new FormData();
|
|
8
|
+
const imageFile = files[0] as File & { uri: string };
|
|
9
|
+
|
|
10
|
+
// In ReactNative Android, we need to define a file type for all upload items; otherwise backend will reject a request
|
|
11
|
+
// @ts-ignore - we need to modify `type` because in android this value will not set by default (https://github.com/axios/axios/issues/4823)
|
|
12
|
+
imageFile.type = mime.getType(imageFile.uri);
|
|
13
|
+
newFormData.append('files', imageFile);
|
|
14
|
+
|
|
15
|
+
return newFormData;
|
|
16
|
+
};
|
|
@@ -21,37 +21,24 @@ export const createOptimisticEvent = (
|
|
|
21
21
|
) => {
|
|
22
22
|
if (formData) {
|
|
23
23
|
const files = formData.getAll('files');
|
|
24
|
-
const fileObject = files[0] || undefined;
|
|
24
|
+
const fileObject = (files[0] as File & { uri: string }) || undefined;
|
|
25
25
|
|
|
26
26
|
if (!fileObject) return;
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
? {
|
|
36
|
-
...payload,
|
|
37
|
-
data: {
|
|
38
|
-
...payload.data,
|
|
39
|
-
fileId: undefined,
|
|
40
|
-
videoFileId: { original: undefined },
|
|
41
|
-
fileData: fileData?.result,
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
: {
|
|
45
|
-
...payload,
|
|
46
|
-
data: {
|
|
47
|
-
...payload.data,
|
|
48
|
-
fileId: undefined,
|
|
49
|
-
fileData: fileData?.result,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
),
|
|
53
|
-
);
|
|
28
|
+
const optimisticData = {
|
|
29
|
+
...payload,
|
|
30
|
+
data: {
|
|
31
|
+
...payload.data,
|
|
32
|
+
fileId: undefined,
|
|
33
|
+
fileData: fileObject.uri,
|
|
34
|
+
},
|
|
54
35
|
};
|
|
36
|
+
|
|
37
|
+
if (isVideo) {
|
|
38
|
+
optimisticData.data.videoFileId = { original: undefined };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return callback(saveOptimisticToCache(optimisticData));
|
|
55
42
|
}
|
|
56
43
|
|
|
57
44
|
return callback(
|