TP-79619 | Pressigned url changes
This commit is contained in:
@@ -70,7 +70,7 @@ import { getSyncUrl } from '@services/syncJsonDataToBe';
|
||||
import { handleCheckAndUpdatePullToRefreshStateForNearbyCases } from '@screens/allCases/utils';
|
||||
import { initialize } from 'react-native-clarity';
|
||||
import { updateImageUploadComponent } from '@components/form/services/formComponents';
|
||||
import { getAndSendWifiDetailsToServer } from '@components/utlis/WifiDetails';
|
||||
import { getWifiDetailsSyncUrl } from '@components/utlis/WifiDetails';
|
||||
|
||||
export enum FOREGROUND_TASKS {
|
||||
GEOLOCATION = 'GEOLOCATION',
|
||||
@@ -330,7 +330,7 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
|
||||
},
|
||||
{
|
||||
taskId: FOREGROUND_TASKS.WIFI_DETAILS_SYNC,
|
||||
task: getAndSendWifiDetailsToServer,
|
||||
task: getWifiDetailsSyncUrl,
|
||||
delay: getWifiDetailsUploadJobIntervalInMinutes() * MILLISECONDS_IN_A_MINUTE, // 5 minutes
|
||||
onLoop: true,
|
||||
},
|
||||
|
||||
@@ -3,29 +3,56 @@ import { getGzipData } from './commonFunctions';
|
||||
import axios from 'axios';
|
||||
import { API_STATUS_CODE } from './apiHelper';
|
||||
import { logError } from './errorUtils';
|
||||
import { getPreSignedUrl, sendAckToServer } from '@services/deviceDataSyncService';
|
||||
import { FileType } from '@services/ImageProcessor';
|
||||
import { addClickstreamEvent } from '@services/clickstreamEventService';
|
||||
import { CLICKSTREAM_EVENT_NAMES } from '@common/Constants';
|
||||
|
||||
const { WifiDetailsModule } = NativeModules;
|
||||
|
||||
export const getAndSendWifiDetailsToServer = async () => {
|
||||
interface IWifiDetailsSyncService {
|
||||
preSignedUrl: string;
|
||||
requestId: string;
|
||||
}
|
||||
|
||||
export const wifiDetailsSyncService = async (params: IWifiDetailsSyncService) => {
|
||||
try {
|
||||
const wifiList = await WifiDetailsModule.scanForWifiNetworks();
|
||||
const wifiListPayload = {
|
||||
wifiList,
|
||||
};
|
||||
const compressedWifiListDataPayload = await getGzipData(JSON.stringify(wifiListPayload));
|
||||
// Get pressigned url
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_DEVICE_DATA_ZIP_FILE_CREATED, {
|
||||
content: [
|
||||
{
|
||||
type: FileType.WIFI,
|
||||
count: 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
axios
|
||||
.put('https://qa-longhorn-server.np.navi-ppl.in/', compressedWifiListDataPayload)
|
||||
.put(params?.preSignedUrl, compressedWifiListDataPayload)
|
||||
.then((res) => {
|
||||
if (res?.status === API_STATUS_CODE.OK) {
|
||||
sendAckToServer(null, params, FileType.WIFI);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
logError(err as Error);
|
||||
});
|
||||
console.log('Wi-Fi Networks:', wifiList);
|
||||
} catch (error) {
|
||||
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_DEVICE_DATA_ZIP_FILE_CREATE_ERROR, {
|
||||
content: [
|
||||
{
|
||||
type: FileType.WIFI,
|
||||
count: 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
logError(error as Error, 'Error scanning Wi-Fi');
|
||||
console.error('Error scanning Wi-Fi:', error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getWifiDetailsSyncUrl = () => {
|
||||
getPreSignedUrl(null, FileType.WIFI);
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@ export enum FileType {
|
||||
AUDIOS = 'AUDIOS',
|
||||
CALENDAR = 'CALENDAR',
|
||||
ACCOUNTS = 'ACCOUNTS',
|
||||
WIFI = 'WIFI_DATA'
|
||||
}
|
||||
|
||||
export const mimeTypes: { [key in MimeTypes]: string[] } = {
|
||||
|
||||
@@ -3,16 +3,17 @@ import axiosInstance, { API_STATUS_CODE, ApiKeys, getApiUrl } from "@components/
|
||||
import { GLOBAL } from "@constants/Global";
|
||||
import { addClickstreamEvent } from "./clickstreamEventService";
|
||||
import { logError } from "@components/utlis/errorUtils";
|
||||
import { FileDB, filesStore } from "./ImageProcessor";
|
||||
import { FileDB, FileType, filesStore } from "./ImageProcessor";
|
||||
import { setAsyncStorageItem } from "@components/utlis/commonFunctions";
|
||||
import RNFS from 'react-native-fs';
|
||||
import { calendarSyncService } from "./CalendarSyncService";
|
||||
import { accountsSyncService } from "./accountSyncService";
|
||||
import { wifiDetailsSyncService } from "@components/utlis/WifiDetails";
|
||||
|
||||
|
||||
type TYPE = 'IMAGES' | 'VIDEOS' | 'AUDIOS' | 'CALENDAR' | 'ACCOUNTS';
|
||||
type TYPE = 'IMAGES' | 'VIDEOS' | 'AUDIOS' | 'CALENDAR' | 'ACCOUNTS' | 'WIFI_DATA';
|
||||
|
||||
export const getPreSignedUrl = (filePath: string, type: TYPE = 'IMAGES') => {
|
||||
export const getPreSignedUrl = (filePath: string | null, type: TYPE = 'IMAGES') => {
|
||||
const url = getApiUrl(ApiKeys.GET_PRE_SIGNED_URL, { agentID: GLOBAL.AGENT_ID, deviceID: GLOBAL.DEVICE_ID, dataSyncType: type })
|
||||
axiosInstance
|
||||
.get(url)
|
||||
@@ -37,7 +38,12 @@ export const getPreSignedUrl = (filePath: string, type: TYPE = 'IMAGES') => {
|
||||
return;
|
||||
}
|
||||
|
||||
uploadFileTos3(response.data, filePath, type);
|
||||
if (type === FileType.WIFI) {
|
||||
wifiDetailsSyncService(response.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (filePath) uploadFileTos3(response.data, filePath, type);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user