Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function setupDefaultConfiguration(os: PlatformOSType): Promise {
let assetBasePath;
let readDir;
let copyFile;
let configDetails: ConfigurationDetails;
// Get functions and locations for Android vs iOS assets
if (os === 'android') {
assetBasePath = 'config';
readDir = RNFS.readDirAssets;
copyFile = RNFS.copyFileAssets;
configDetails = JSON.parse(await RNFS.readFileAssets(`${assetBasePath}/base_config.json`));
} else {
assetBasePath = `${RNFS.MainBundlePath}/config.bundle`;
readDir = RNFS.readDir;
copyFile = RNFS.copyFile;
configDetails = JSON.parse(await RNFS.readFile(`${assetBasePath}/base_config.json`));
}
// Create the config file directory
await RNFS.mkdir(CONFIG_DIRECTORY);
for (const type in CONFIG_SUBDIRECTORIES) {
if (CONFIG_SUBDIRECTORIES.hasOwnProperty(type)) {
await RNFS.mkdir(CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[type]);
}
}
// Copy base assets to config file directory
const assetTypes = await readDir(assetBasePath);
for (const type of assetTypes) {
() => {
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");
}
}
}
);
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Platform,
Button
} from 'react-native';
import OpenFile from 'react-native-doc-viewer';
var RNFS = require('react-native-fs');
var SavePath = Platform.OS === 'ios' ? RNFS.MainBundlePath : RNFS.DocumentDirectoryPath;
export default class DocViewerExample extends Component {
/*
* Handle WWW File Method
* fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url the File Extension is missing.
*/
handlePress = () => {
OpenFile.openDoc([{
url:"http://mail.hartl-haus.at/uploads/tx_hhhouses/htf13_classic153s(3_giebel_haus).jpg",
fileName:"sample"
}], (error, url) => {
if (error) {
console.error(error);
} else {
console.log(url)
}
action: () => {
const filename = "Annual Report.pdf";
const path = RNFS.DocumentDirectoryPath + "/" + filename;
const src = RNFS.MainBundlePath + "/PDFs/" + filename;
RNFS.exists(path)
.then(exists => {
if (!exists) {
return RNFS.copyFile(src, path);
}
})
.then(() => {
PSPDFKit.present(path, {});
PSPDFKit.setPageIndex(3, false);
})
.catch(err => {
console.log(err.message, err.code);
});
}
},
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) {
componentDidMount() {
if (this.props.type === NET) {
Api.get(this.props.url)
.then(response => this.setState({
visible: false,
html: MarkdownHelper.convert(response.data) }))
.catch(err => this.setState({
visible: false,
html: err.message,
}));
} else {
const basePath = Platform.OS === 'ios'
? RNFS.MainBundlePath
: RNFS.ExternalDirectoryPath;
if (basePath) {
let slug = '';
if (this.props.isFullSlug) {
slug = this.props.slug;
} else {
slug = `/growth-content/${this.props.domain}/${this.props.slug}.html`;
}
RNFS.readFile(basePath.concat(slug), 'utf8')
.then((result) => {
this.setState({
html: result,
visible: false,
});
});
const createSourceMapper = async () => {
const path = `${RNFS.MainBundlePath}/${options.sourceMapBundle}`;
try {
const fileExists = await RNFS.exists(path);
if (!fileExists) {
throw new Error(__DEV__ ?
'Unable to read source maps in DEV mode' :
`Unable to read source maps, possibly invalid sourceMapBundle file, please check that it exists here: ${RNFS.MainBundlePath}/${options.sourceMapBundle}`
);
}
const mapContents = await RNFS.readFile(path, 'utf8');
const sourceMaps = JSON.parse(mapContents);
const mapConsumer = new SourceMap.SourceMapConsumer(sourceMaps);
return sourceMapper = row => {
return mapConsumer.originalPositionFor({
line: row.lineNumber,
column: row.columnNumber,
});
};
}
catch (error) {
throw error;