Skip to content

Commit

Permalink
new path
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Apr 28, 2023
1 parent 26588ec commit c93da4d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/core/Snaps/location/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { assert, assertStruct, isObject } from '@metamask/utils';

import { DetectSnapLocationOptions, SnapLocation } from './location';
import { NativeModules } from 'react-native';
import { NativeModules, Platform } from 'react-native';
import RNFetchBlob, { FetchBlobResponse } from 'rn-fetch-blob';
import Logger from '../../../util/Logger';

Expand Down Expand Up @@ -90,19 +90,34 @@ const fetchAndStoreNPMPackage = async (
inputRequest: RequestInfo,
): Promise<string> => {
const { config } = RNFetchBlob;
const filePath = `${RNFetchBlob.fs.dirs.DocumentDir}/archive.tgz`;
const targetDir =
Platform.OS === 'ios'
? RNFetchBlob.fs.dirs.DocumentDir
: `${RNFetchBlob.fs.dirs.DownloadDir}`;
const filePath = `${targetDir}/archive.tgz`;
const urlToFetch: string =
typeof inputRequest === 'string' ? inputRequest : inputRequest.url;
console.log(SNAPS_NPM_LOG_TAG, 'fetchAndStoreNPMPackage', urlToFetch);

try {
const response: FetchBlobResponse = await config({
fileCache: true,
path: filePath,
}).fetch('GET', urlToFetch);
const dataPath = response.data;
const targetPath = RNFetchBlob.fs.dirs.DocumentDir;
try {
const decompressedPath = await decompressFile(dataPath, targetPath);
console.log(
SNAPS_NPM_LOG_TAG,
'calling decompressFile with',
dataPath,
targetDir,
);
const decompressedPath = await decompressFile(dataPath, targetDir);
console.log(
SNAPS_NPM_LOG_TAG,
'fetchAndStoreNPMPackage decompressedPath',
decompressedPath,
);
return decompressedPath;
} catch (error) {
Logger.error(
Expand Down

0 comments on commit c93da4d

Please sign in to comment.