aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/MomentService.ts116
1 files changed, 115 insertions, 1 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts
index b837585a..c5b2c530 100644
--- a/src/services/MomentService.ts
+++ b/src/services/MomentService.ts
@@ -1,12 +1,20 @@
import AsyncStorage from '@react-native-community/async-storage';
+import {Image, Video} from 'react-native-image-crop-picker';
import RNFetchBlob from 'rn-fetch-blob';
+import {ProfileBody} from '../components';
import {
MOMENTS_ENDPOINT,
MOMENTTAG_ENDPOINT,
MOMENT_TAGS_ENDPOINT,
MOMENT_THUMBNAIL_ENDPOINT,
+ PRESIGNED_URL_ENDPOINT,
+ TAGG_CUSTOMER_SUPPORT,
} from '../constants';
-import {MomentPostType, MomentTagType} from '../types';
+import {
+ ERROR_SOMETHING_WENT_WRONG,
+ ERROR_SOMETHING_WENT_WRONG_REFRESH,
+} from '../constants/strings';
+import {MomentPostType, MomentTagType, ResponseURL} from '../types';
import {checkImageUploadStatus} from '../utils';
export const postMoment = async (
@@ -18,6 +26,7 @@ export const postMoment = async (
) => {
try {
const request = new FormData();
+
//Manipulating filename to end with .jpg instead of .heic
if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) {
fileName = fileName.split('.')[0] + '.jpg';
@@ -208,3 +217,108 @@ export const deleteMomentTag = async (moment_tag_id: string) => {
return false;
}
};
+
+export const handlePresignedURL = async (
+ value: string | undefined,
+ filename: string | undefined,
+) => {
+ try {
+ const response = await fetch(PRESIGNED_URL_ENDPOINT, {
+ method: 'POST',
+ body: JSON.stringify({
+ value,
+ filename,
+ }),
+ });
+ const status = response.status;
+ let data: ResponseURL = await response.json();
+ if (status === 200) {
+ console.log(data.response_msg);
+ return data;
+ } else {
+ if (status === 404) {
+ console.log(
+ `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`,
+ );
+ } else {
+ console.log(ERROR_SOMETHING_WENT_WRONG_REFRESH);
+ }
+ console.log(response);
+ }
+ } catch (error) {
+ console.log(error);
+ console.log(ERROR_SOMETHING_WENT_WRONG);
+ }
+};
+export const handleVideoUpload = async (
+ file: Video | Image | undefined,
+ urlObj: ResponseURL | undefined,
+) => {
+ try {
+ console.log('inside of second handler: \n' + JSON.stringify(urlObj));
+ console.log(urlObj?.response_url.url);
+ let fileName = file?.filename || ''; // check if null
+ if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) {
+ fileName = fileName.split('.')[0] + '.jpg';
+ }
+ //build payload packet
+ console.log('LOG');
+ const form = new FormData();
+ form.append('key', JSON.stringify(urlObj.response_url.fields.key));
+ form.append(
+ 'x-amz-algorithm',
+ JSON.stringify(urlObj.response_url.fields['x-amz-algorithm']),
+ );
+ form.append(
+ 'x-amz-credential',
+ JSON.stringify(urlObj.response_url.fields['x-amz-credential']),
+ );
+ form.append(
+ 'x-amz-date',
+ JSON.stringify(urlObj.response_url.fields['x-amz-date']),
+ );
+ form.append('policy', JSON.stringify(urlObj.response_url.fields.policy));
+ form.append(
+ 'x-amz-signature',
+ JSON.stringify(urlObj.response_url.fields['x-amz-signature']),
+ );
+
+ form.append('file', {
+ uri: file?.sourceURL,
+ type: 'video',
+ name: fileName,
+ });
+ console.log('FORM: \n' + JSON.stringify(form));
+
+ const response = await fetch(urlObj.response_url.url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ body: form,
+ });
+ console.log('response' + JSON.stringify(response));
+ const status = response.status;
+ console.log('responmse text' + response.text());
+ let data = await response.json();
+ if (status === 200) {
+ console.log(data.response_msg);
+ return data.response_url;
+ } else {
+ if (status === 404) {
+ console.log(
+ `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`,
+ );
+ } else {
+ console.log('bad');
+ console.log(ERROR_SOMETHING_WENT_WRONG_REFRESH);
+ }
+ console.log(response);
+ return false;
+ }
+ } catch (error) {
+ console.log(error);
+ console.log(ERROR_SOMETHING_WENT_WRONG);
+ return false;
+ }
+};