Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _startDownloadForId(id) {
const data = this._getDataWithId(id);
const videoUri = data.videos['240p'];
const fileUri = FileSystem.documentDirectory + id + '.mp4';
// TODO: Catch errors
try {
const { exists } = await FileSystem.getInfoAsync(fileUri);
if (exists) {
await FileSystem.deleteAsync(fileUri);
}
} catch (e) {
console.log('File overwrite error', e);
Sentry.captureException(e);
Sentry.captureMessage('File overwrite error');
this._updateStore(id, ERROR({ message: 'Error downloading file' }));
return;
}
try {
const downloadResumable = FileSystem.createDownloadResumable(
videoUri,
fileUri,
{},
_.throttle(this._createDownloadProgressHandler(id), 200)
);
this._downloadResumables[id] = downloadResumable;
const uri = await downloadResumable.downloadAsync();
if (uri) {
this._updateStore(id, DOWNLOADED({ uri }));
}
.catch(error => {
Sentry.captureMessage(JSON.stringify(error));
});
console.log(data);
try {
const downloadResumable = new FileSystem.DownloadResumable(
downloadFromStore.url,
downloadFromStore.fileUri,
downloadFromStore.options,
this._createDownloadProgressHandler(id),
downloadFromStore.resumeData
);
this._downloadResumables[id] = downloadResumable;
const uri = await downloadResumable.resumeAsync();
if (uri) {
this._updateStore(id, DOWNLOADED({ uri }));
}
} catch (e) {
console.log('File download error', e);
Sentry.captureMessage('File download error');
Sentry.captureException(e);
this._updateStore(id, ERROR({ message: 'Error downloading file' }));
} finally {
delete this._downloadResumables[id];
}
}
}
try {
const downloadResumable = FileSystem.createDownloadResumable(
videoUri,
fileUri,
{},
_.throttle(this._createDownloadProgressHandler(id), 200)
);
this._downloadResumables[id] = downloadResumable;
const uri = await downloadResumable.downloadAsync();
if (uri) {
this._updateStore(id, DOWNLOADED({ uri }));
}
} catch (e) {
console.log('File download error', e);
Sentry.captureMessage('File download error');
Sentry.captureException(e);
this._updateStore(id, ERROR({ message: 'Error downloading file' }));
} finally {
delete this._downloadResumables[id];
}
}
return new Promise(function(
resolve: () => void,
reject: (error: Error) => void
) {
try {
Promise.all([
importItems(tx, items),
importItemDetails(tx, itemDetail),
importCalendars(tx, calendars),
]).then(function() {
resolve();
});
} catch (err) {
Sentry.captureMessage(err);
reject(err);
}
});
};
export const migrationV104 = async (): Promise => {
try {
await db.transaction(async (tx: SQLite.Transaction) => {
await v1040(tx);
await v1041(tx);
});
return true;
} catch (err) {
Sentry.captureMessage(err);
return false;
}
};
bulkInsertItemDetail(tx, itemDetail, (data: ItemDetail[], err: any) => {
if (err) {
Sentry.captureMessage(err);
reject(err);
return;
}
resolve(data);
return;
});
});