Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
// Copy the database to the backup location
console.log(
"[Dropbox backup] DB backup file is now gone; continue with backup."
);
return RNFS.copyFile(this.getLocalDBFilePath(), databaseBackupFilePath);
})
.then(() => {
reg.logger().info('Original dimensions ', dimensions);
if (dimensions.width > maxSize || dimensions.height > maxSize) {
dimensions.width = maxSize;
dimensions.height = maxSize;
}
reg.logger().info('New dimensions ', dimensions);
const format = mimeType == 'image/png' ? 'PNG' : 'JPEG';
reg.logger().info(`Resizing image ${localFilePath}`);
const resizedImage = await ImageResizer.createResizedImage(localFilePath, dimensions.width, dimensions.height, format, 85); // , 0, targetPath);
const resizedImagePath = resizedImage.uri;
reg.logger().info('Resized image ', resizedImagePath);
reg.logger().info(`Moving ${resizedImagePath} => ${targetPath}`);
await RNFS.copyFile(resizedImagePath, targetPath);
try {
await RNFS.unlink(resizedImagePath);
} catch (error) {
reg.logger().warn('Error when unlinking cached file: ', error);
}
}
async copy(source, dest) {
let retry = false;
try {
await RNFS.copyFile(source, dest);
} catch (error) {
// On iOS it will throw an error if the file already exist
retry = true;
await this.unlink(dest);
}
if (retry) await RNFS.copyFile(source, dest);
}
Zip.unzip(JS_BUNDLE_ZIP_PATH, DOCUMENT_FILE_PATH, async (res) => {
await deleteDir(JS_BUNDLE_ZIP_PATH);
if (res) {
onError && onError(ERROR_UNZIP_JS);
} else {
try {
let needCopyFiles = JSON.parse(await fs.readFile(CACHE_PATH + '/needCopyFiles.json'));
if (JS_VERISON_CODE === 0) {
for (let file of needCopyFiles) {
await fs.mkdir(CACHE_PATH + '/' + file.replace(/[^/]*$/, ''));
if (IS_ANDROID) {
await fs.copyFileRes(file.replace(/.*\/(.*)/, '$1'), CACHE_PATH + '/' + file);
} else {
await fs.copyFile(fs.MainBundlePath + '/' + file, CACHE_PATH + '/' + file);
}
}
} else {
for (let file of needCopyFiles) {
await fs.mkdir(CACHE_PATH + '/' + file.replace(/[^/]*$/, ''));
await fs.copyFile(WWW_PATH + '/' + file, CACHE_PATH + '/' + file);
}
}
} catch (e) {
console.log('unzip erorr:', e);
await deleteDir(CACHE_PATH);
onError && onError(ERROR_UNZIP_JS);
return;
}
await deleteDir(WWW_PATH);
await fs.unlink(CACHE_PATH + '/needCopyFiles.json');
componentWillMount() {
RNFS.unlink(RNFS.DocumentDirectoryPath + "/nkjv.realm");
RNFS.unlink(RNFS.DocumentDirectoryPath + "/nkjv.realm.lock");
if (Platform.OS == "android") {
RNFS.copyFileAssets("nkjv.realm", RNFS.DocumentDirectoryPath + "/nkjv.realm");
RNFS.copyFileAssets("nkjv.realm.lock", RNFS.DocumentDirectoryPath + "/nkjv.realm.lock");
} else {
try {
RNFS.copyFile(RNFS.MainBundlePath + "/nkjv.realm", RNFS.DocumentDirectoryPath + "/nkjv.realm");
RNFS.copyFile(RNFS.MainBundlePath + "/nkjv.realm.lock", RNFS.DocumentDirectoryPath + "/nkjv.realm.lock");
} catch (e) {
console.log("FILE ALREADY EXISTS");
}
}
}
_onShowSearch() {
() => {
if (Platform.OS == "android") {
RNFS.copyFileAssets(`${book}.realm.lock`, RNFS.DocumentDirectoryPath + `/${book}.realm.lock`);
RNFS.copyFileAssets(`${book}.realm`, RNFS.DocumentDirectoryPath + `/${book}.realm`).then(() => {
this.loadPassage();
this._bottomSheet.close();
});
} else {
try {
RNFS.copyFile(
RNFS.MainBundlePath + `/${book}.realm.lock`,
RNFS.DocumentDirectoryPath + `/${book}.realm.lock`
);
RNFS.copyFile(
RNFS.MainBundlePath + `/${book}.realm`,
RNFS.DocumentDirectoryPath + `/${book}.realm`
).then(() => {
this.loadPassage();
this._bottomSheet.close();
});
} catch (e) {
console.log("FILE ALREADY EXISTS");
}
}
}
);
const expoDirectoryExists = await RNFS.exists(RNFS.DocumentDirectoryPath + '/ExponentExperienceData');
if (!expoDirectoryExists) {
console.log('Expo data was previously migrated. Exiting migration...');
await this.migrateDataToSecureKeystore();
return;
}
try {
await RNFS.unlink(RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1');
console.log('/RCTAsyncLocalStorage_V1 has been deleted. Continuing...');
} catch (error) {
console.log(error);
console.log('/RCTAsyncLocalStorage_V1 does not exist. Continuing...');
}
try {
await RNFS.copyFile(WalletMigrate.expoDataDirectory, RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1');
} catch (error) {
console.log('An error was encountered when trying to copy Expo data to /RCTAsyncLocalStorage_V1. Exiting migration...');
console.log(error);
}
try {
await RNFS.unlink(RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1/.DS_Store');
} catch (error) {
console.log('An error was encountered when trying to delete .DS_Store. Continuing migration...');
console.log(error);
}
const files = await RNFS.readDir(WalletMigrate.expoDataDirectory);
for (const file of files) {
try {
if (file.isFile()) {
if (file.name === 'manifest.json') {
const manifestFile = await RNFS.readFile(file.path);
}).then(() => {
return copyFile(fileDetails.uri, filePath)
}).then(() => {
return isPasswordProtected(filePath)
loadVersion(payload, rootState) {
const activeVersion = rootState.bible.activeVersion.value;
if (Platform.OS == 'ios') {
RNFS.copyFile(
RNFS.MainBundlePath + `/${activeVersion}.realm`,
RNFS.DocumentDirectoryPath + `/${activeVersion}.realm`,
);
} else {
RNFS.copyFileAssets(`${activeVersion}.realm`, `${RNFS.DocumentDirectoryPath}/${activeVersion}.realm`);
}
},
fetchVerses(payload, rootState) {
this.index++;
const expandName = path.replace(/^.*(\..*)$/, '$1');
await AsyncStorage.setItem(ITEM_NAME_INDEX, JSON.stringify(this.index));
const item = {
mediaId: this.index,
url: DocumentPath + this.index + expandName,
local: true,
};
await fs.copyFile(path, item.url);
const taskItem = this.tempItem;
const list = isImage ? taskItem.images : taskItem.videos;
list.push(item);
resolve(list);
});
}
removeMediaFile (accusationId, url, isImage, noNeedChecked) {