@plusscommunities/pluss-core-app 6.0.1 → 6.0.3-auth.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/package.json +4 -1
- package/src/apis/fileActions.js +19 -27
- package/src/components/ImageUploader.js +17 -10
- package/src/config.js +5 -0
- package/src/session.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-core-app",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3-auth.0",
|
|
4
4
|
"description": "Core extension package for Pluss Communities platform",
|
|
5
5
|
"main": "dist/module/index.js",
|
|
6
6
|
"module": "dist/module/index.js",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"patch": "npm version patch",
|
|
16
16
|
"betaupload": "npm run build && npm publish --access public --tag beta",
|
|
17
17
|
"betaupload:p": "npm run betapatch && npm run betaupload",
|
|
18
|
+
"authpatch": "npm version prepatch --preid=auth",
|
|
19
|
+
"authupload": "npm i && npm i && npm publish --access public --tag auth",
|
|
20
|
+
"authupload:p": "npm run authpatch && npm run authupload",
|
|
18
21
|
"upload": "npm run build && npm publish --access public",
|
|
19
22
|
"upload:p": "npm run patch && npm run upload"
|
|
20
23
|
},
|
package/src/apis/fileActions.js
CHANGED
|
@@ -1,41 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Storage } from 'aws-amplify';
|
|
1
|
+
import Axios from 'axios';
|
|
3
2
|
import { getUrl, generateImageName, randomString } from '../helper';
|
|
4
3
|
import { authedFunction } from '../session';
|
|
5
|
-
import Config from '../config';
|
|
6
4
|
|
|
7
5
|
export const fileActions = {
|
|
6
|
+
getPresignedUrl: async (filename, contentType) => {
|
|
7
|
+
// const newFilename = filename.replace(/[^a-z0-9+.]+/gi, '').toLowerCase();
|
|
8
|
+
const signedUrlRes = await authedFunction({
|
|
9
|
+
method: 'GET',
|
|
10
|
+
url: getUrl('media', 'get/presignedurl', { filename, contentType }),
|
|
11
|
+
});
|
|
12
|
+
return signedUrlRes.data;
|
|
13
|
+
},
|
|
8
14
|
getUploadUrl: (userId, fileName) => {
|
|
9
15
|
const newFilename = fileName.replace(/[^a-z0-9+.]+/gi, '').toLowerCase();
|
|
10
16
|
return `uploads/users/${userId}/public/${randomString()}/${newFilename}`;
|
|
11
17
|
},
|
|
12
|
-
uploadUserMediaWithProgress: async (
|
|
13
|
-
|
|
14
|
-
return fileActions.uploadBlobAWS(Config.env.awsUploadsBucket, url, blob, '', progressCallback);
|
|
18
|
+
uploadUserMediaWithProgress: async (blob, url, progressCallback = null) => {
|
|
19
|
+
return fileActions.uploadBlobAWS(url, blob, progressCallback);
|
|
15
20
|
},
|
|
16
|
-
// uploadUserMedia: async (userId, image, fileName) => {
|
|
17
|
-
// const blob = await fileActions.imageToBlob(image.uri);
|
|
18
|
-
// const url = fileActions.getUploadUrl(userId, fileName);
|
|
19
|
-
// return fileActions.uploadBlobAWS(Config.env.awsUploadsBucket, url, blob);
|
|
20
|
-
// },
|
|
21
|
-
// uploadSignatureImage: async (image, name) => {
|
|
22
|
-
// const blob = await fileActions.imageToBlob(image);
|
|
23
|
-
// const newImageName = generateImageName(name, 'signature.png');
|
|
24
|
-
// return fileActions.uploadBlobAWS(Config.env.awsStorageBucket, newImageName, blob, 'images/');
|
|
25
|
-
// },
|
|
26
21
|
imageToBlob: async imageUri => {
|
|
27
22
|
const response = await fetch(imageUri);
|
|
28
23
|
return response.blob();
|
|
29
24
|
},
|
|
30
|
-
uploadBlobAWS: (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
customPrefix: { public: '' },
|
|
38
|
-
progressCallback: progress =>
|
|
25
|
+
uploadBlobAWS: async (uri, blob, progressCallback = null) => {
|
|
26
|
+
return Axios.put(uri, blob, {
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': blob.type,
|
|
29
|
+
},
|
|
30
|
+
transformRequest: d => d,
|
|
31
|
+
onUploadProgress: progress =>
|
|
39
32
|
progressCallback &&
|
|
40
33
|
progressCallback({
|
|
41
34
|
uri,
|
|
@@ -43,8 +36,7 @@ export const fileActions = {
|
|
|
43
36
|
total: progress.total,
|
|
44
37
|
percentage: `${Math.floor((progress.loaded / progress.total) * 100)}%`,
|
|
45
38
|
}),
|
|
46
|
-
};
|
|
47
|
-
return Storage.put(`${prefix}${imageName}`, blob, access);
|
|
39
|
+
});
|
|
48
40
|
},
|
|
49
41
|
getStockPhotos: async () => {
|
|
50
42
|
const response = await authedFunction({
|
|
@@ -142,23 +142,25 @@ class ImageUploader extends Component {
|
|
|
142
142
|
let uploadUri;
|
|
143
143
|
try {
|
|
144
144
|
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_IMAGE_NAME)}.${DEFULAT_IMAGE_TYPE}`;
|
|
145
|
-
uploadUri = fileActions.getUploadUrl(this.props.userId, fileName);
|
|
146
145
|
|
|
147
|
-
this.props.onUploadStarted(uploadUri, imageUri);
|
|
148
146
|
this.hideUploadMenu();
|
|
149
147
|
|
|
150
148
|
const resized = await this.resizeImageAsync(imageUri);
|
|
149
|
+
const blob = await fileActions.imageToBlob(resized.uri);
|
|
150
|
+
const presignedUriRes = await fileActions.getPresignedUrl(_.last(resized.uri.split('/')), blob.type);
|
|
151
|
+
uploadUri = presignedUriRes.key;
|
|
152
|
+
this.props.onUploadStarted(uploadUri, imageUri);
|
|
151
153
|
if (this.props.onlySelectImage) {
|
|
152
154
|
this.props.onImageSelected(resized, fileName);
|
|
153
155
|
return;
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
const
|
|
158
|
+
const uploadResult = await fileActions.uploadUserMediaWithProgress(blob, presignedUriRes.url, progress => {
|
|
157
159
|
if (this.props.onUploadProgress) this.props.onUploadProgress(progress);
|
|
158
160
|
});
|
|
159
161
|
|
|
160
|
-
this.props.onUploadSuccess(Config.env.baseUploadsUrl +
|
|
161
|
-
console.log('upload success', Config.env.baseUploadsUrl +
|
|
162
|
+
this.props.onUploadSuccess(Config.env.baseUploadsUrl + uploadUri, uploadUri);
|
|
163
|
+
console.log('upload success', Config.env.baseUploadsUrl + uploadUri);
|
|
162
164
|
} catch (e) {
|
|
163
165
|
console.log('handleImagePicked error', e);
|
|
164
166
|
this.props.onUploadFailed(uploadUri);
|
|
@@ -170,7 +172,6 @@ class ImageUploader extends Component {
|
|
|
170
172
|
const imagesUploaded = imagesSelected.map(image => {
|
|
171
173
|
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_IMAGE_NAME)}.${DEFULAT_IMAGE_TYPE}`;
|
|
172
174
|
const uploadUri = fileActions.getUploadUrl(this.props.userId, fileName);
|
|
173
|
-
if (!this.props.onlySelectImage) this.props.onUploadStarted(uploadUri, image.uri);
|
|
174
175
|
return { imageUri: image.uri, uploadUri, fileName };
|
|
175
176
|
});
|
|
176
177
|
this.hideUploadMenu();
|
|
@@ -181,16 +182,21 @@ class ImageUploader extends Component {
|
|
|
181
182
|
const { imageUri, uploadUri, fileName } = image;
|
|
182
183
|
try {
|
|
183
184
|
const resized = await this.resizeImageAsync(imageUri);
|
|
185
|
+
const blob = await fileActions.imageToBlob(resized.uri);
|
|
184
186
|
if (this.props.onlySelectImage) {
|
|
185
187
|
this.props.onImageSelected(resized, fileName);
|
|
186
188
|
return;
|
|
187
189
|
}
|
|
190
|
+
const presignedUriRes = await fileActions.getPresignedUrl(_.last(resized.uri.split('/')), blob.type);
|
|
191
|
+
const uploadUri = presignedUriRes.key;
|
|
192
|
+
if (!this.props.onlySelectImage) this.props.onUploadStarted(uploadUri, imageUri);
|
|
188
193
|
|
|
189
|
-
const
|
|
194
|
+
const uploadResult = await fileActions.uploadUserMediaWithProgress(blob, presignedUriRes.url, progress => {
|
|
190
195
|
if (this.props.onUploadProgress) this.props.onUploadProgress(progress);
|
|
191
196
|
});
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
|
|
198
|
+
this.props.onUploadSuccess(Config.env.baseUploadsUrl + uploadUri, uploadUri);
|
|
199
|
+
console.log('upload success', Config.env.baseUploadsUrl + uploadUri);
|
|
194
200
|
} catch (e) {
|
|
195
201
|
console.log('handleMultiImagePicked error', e);
|
|
196
202
|
this.props.onUploadFailed(uploadUri);
|
|
@@ -203,7 +209,7 @@ class ImageUploader extends Component {
|
|
|
203
209
|
try {
|
|
204
210
|
const fileType = uri.substring(uri.lastIndexOf('.') + 1);
|
|
205
211
|
const fileName = `${getValueOrDefault(this.props.fileName, DEFAULT_VIDEO_NAME)}.${fileType}`;
|
|
206
|
-
uploadUri = fileActions.
|
|
212
|
+
uploadUri = await fileActions.getPresignedUrl(fileName);
|
|
207
213
|
|
|
208
214
|
this.props.onUploadStarted(uploadUri, uri);
|
|
209
215
|
this.hideUploadMenu();
|
|
@@ -266,6 +272,7 @@ class ImageUploader extends Component {
|
|
|
266
272
|
};
|
|
267
273
|
|
|
268
274
|
isEditingEnabled = () => {
|
|
275
|
+
return false;
|
|
269
276
|
return !this.props.multiple && !this.props.allowVideo && getValueOrDefault(this.props.allowsEditing, DEFAULT_ALLOWS_EDITING);
|
|
270
277
|
};
|
|
271
278
|
|
package/src/config.js
CHANGED
|
@@ -18,6 +18,11 @@ const CoreConfig = {
|
|
|
18
18
|
strings: {},
|
|
19
19
|
newEventDefaults: '',
|
|
20
20
|
defaultAllowComments: true,
|
|
21
|
+
AuthStrategy: {
|
|
22
|
+
getAccessToken: async () => null,
|
|
23
|
+
getCurrentUserId: async () => null,
|
|
24
|
+
hasActiveSession: async () => false,
|
|
25
|
+
},
|
|
21
26
|
},
|
|
22
27
|
init: (environment, navigation) => {
|
|
23
28
|
CoreConfig.env = environment;
|
package/src/session.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { Auth } from 'aws-amplify';
|
|
4
|
+
import Config from './config';
|
|
4
5
|
|
|
5
6
|
export const getSessionTokenAWS = async prefix => {
|
|
6
|
-
const
|
|
7
|
-
const token = data.accessToken.jwtToken;
|
|
7
|
+
const token = await Config.env.AuthStrategy.getAccessToken();
|
|
8
8
|
if (_.isUndefined(prefix)) return token;
|
|
9
9
|
return `${prefix} ${token}`;
|
|
10
10
|
};
|