Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function create(song) {
let existDir = await RNFS.exists(RNFS.ExternalStorageDirectoryPath + '/MoeFM').then(boolean => boolean);
if (!existDir) await RNFS.mkdir(RNFS.ExternalStorageDirectoryPath + '/MoeFM');
let exist = await RNFS.exists(RNFS.ExternalStorageDirectoryPath + '/MoeFM/' + song.title + '.mp3').then(boolean => boolean);
if (!exist) {
RNFS.downloadFile({
fromUrl: song.url,
toFile: RNFS.ExternalStorageDirectoryPath + '/MoeFM/' + song.title + '.mp3',
background: true,
begin: ((res) => beginCallback(res, song)),
progress: (progressCallback)
}).promise.then((result) => {
resultCallback(result);
}).catch((err) => {
if(err.description === "cancelled") {
// cancelled by user
}
console.log(err);
});
async function _updateConfig(callbacks: ConfigurationUpdateCallbacks): Promise < void > {
if (configurationUpdates.length === 0) {
// If there are no updates, exit
return;
}
// Generate directories
await RNFS.mkdir(CONFIG_DIRECTORY);
await RNFS.mkdir(TEMP_CONFIG_DIRECTORY);
for (const type in CONFIG_SUBDIRECTORIES) {
if (CONFIG_SUBDIRECTORIES.hasOwnProperty(type)) {
await RNFS.mkdir(CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[type]);
}
}
// Get total size of update
let totalSize: number = 0;
for (let i = 0; i < configurationUpdates.length; i++) {
totalSize += configurationUpdates[i].size;
}
if (callbacks.onUpdateStart) {
callbacks.onUpdateStart(totalSize, configurationUpdates.length);
}
async function _updateConfig(callbacks: ConfigurationUpdateCallbacks): Promise < void > {
if (configurationUpdates.length === 0) {
// If there are no updates, exit
return;
}
// Generate directories
await RNFS.mkdir(CONFIG_DIRECTORY);
await RNFS.mkdir(TEMP_CONFIG_DIRECTORY);
for (const type in CONFIG_SUBDIRECTORIES) {
if (CONFIG_SUBDIRECTORIES.hasOwnProperty(type)) {
await RNFS.mkdir(CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[type]);
}
}
// Get total size of update
let totalSize: number = 0;
for (let i = 0; i < configurationUpdates.length; i++) {
totalSize += configurationUpdates[i].size;
}
if (callbacks.onUpdateStart) {
callbacks.onUpdateStart(totalSize, configurationUpdates.length);
}
// Add filename to download info and invoke start callback
const onStart = (filename: string, download: Object) => {
if (callbacks.onDownloadStart) {
download.filename = filename;
async function _updateConfig(
configDetails: ConfigurationDetails,
callbacks: UpdateCallbacks,
os: PlatformOSType): Promise {
if (configDetails.files.length === 0) {
// If there are no updates, exit
return;
}
// Generate directories
await RNFS.mkdir(CONFIG_DIRECTORY);
await RNFS.mkdir(TEMP_CONFIG_DIRECTORY);
for (const type in CONFIG_SUBDIRECTORIES) {
if (CONFIG_SUBDIRECTORIES.hasOwnProperty(type)) {
await RNFS.mkdir(CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[type]);
}
}
// Get total size of update
let totalSize = 0;
for (const update of configDetails.files) {
totalSize += update.size;
}
if (callbacks.onUpdateStart) {
callbacks.onUpdateStart(totalSize, configDetails.files.length);
}
async function _updateConfig(callbacks: ConfigurationUpdateCallbacks): Promise < void > {
if (configurationUpdates.length === 0) {
// If there are no updates, exit
return;
}
// Generate directories
await RNFS.mkdir(CONFIG_DIRECTORY);
await RNFS.mkdir(TEMP_CONFIG_DIRECTORY);
for (const type in CONFIG_SUBDIRECTORIES) {
if (CONFIG_SUBDIRECTORIES.hasOwnProperty(type)) {
await RNFS.mkdir(CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[type]);
}
}
// Get total size of update
let totalSize: number = 0;
for (let i = 0; i < configurationUpdates.length; i++) {
totalSize += configurationUpdates[i].size;
}
if (callbacks.onUpdateStart) {
callbacks.onUpdateStart(totalSize, configurationUpdates.length);
}
// Add filename to download info and invoke start callback
createLibraryArtworkCache(){
return RNFS.mkdir(APP_ARTWORK_CACHE_FOLDER,{NSURLIsExcludedFromBackupKey : true})
.then(() => {
console.log('MediaLibraryApi asset caching dir :',APP_ARTWORK_CACHE_FOLDER);
});
}
refreshLibraryArtworks(){
async init() {
await RNFS.mkdir(this._mapDir);
return Promise.resolve();
}
createCacheDirectory() {
fs.mkdir(this.getCacheDirectory());
}
RNFS.exists(dir).then(dirExists => {
if (dirExists) {
resolve();
} else {
RNFS.mkdir(dir).then(() => {
resolve();
});
}
});
});