Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const generateLocalPath = async (url, format) => {
try {
const ABSOLUTEPATH = common.ios
? REACTNATIVEFS.LibraryDirectoryPath
: REACTNATIVEFS.ExternalDirectoryPath;
const STORAGEPATH = `${ABSOLUTEPATH}/${Date.now()}.${format}`;
const { statusCode } = await REACTNATIVEFS.downloadFile({
fromUrl: url,
toFile: STORAGEPATH
}).promise;
if (statusCode === 200) return `file://${STORAGEPATH}`;
return false;
} catch (error) {
console.error('生成本地路径异常', error);
}
};
_download(){
const {timeLine,} = this.props
var localPath = RNFS.LibraryDirectoryPath + '/' + this.state.pageInfo.id + '.mp3'
if(Platform.OS === 'android'){
localPath = RNFS.ExternalDirectoryPath + '/' + this.state.pageInfo.id + '.mp3'
}
let downloadManager = new DownloadManager()
if(downloadManager.isDownloading ){
Alert.alert('提示','已有任务在队列中',[{text:'确定',onPress:()=>{console.log('sure')} }])
return
}
console.log(localPath)
let starage = new MyStorage()
starage.getAudioInfo(this.state.pageInfo.id,(res)=>{
if(res){
Alert.alert('提示','资源已经下载',[{text:'确定',onPress:()=>{console.log('sure')} }])
}else{
_deleteRow(rowId,id){
var path = RNFS.LibraryDirectoryPath + '/' + id + '.mp3'
if(Platform.OS === 'android'){
path = RNFS.ExternalDirectoryPath + '/' + id + '.mp3'
}
Alert.alert('确定要删除吗?',path,[{text:'取消',onPress:null},{text:'确定',onPress:()=>{
storage.removeAudioInfo(id)
RNFS.unlink(path)
.then(() => {
this.getData()
})
.catch((err) => {
console.log(err.message);
});
} }])
}
_renderHiddenRow(data, secId, rowId, rowMap){
export const generateLocalPath = async (url, format) => {
try {
const ABSOLUTEPATH = VALUE.ios
? REACTNATIVEFS.LibraryDirectoryPath
: REACTNATIVEFS.ExternalDirectoryPath;
const STORAGEPATH = `${ABSOLUTEPATH}/${Date.now()}.${format}`;
const { statusCode } = await REACTNATIVEFS.downloadFile({
fromUrl: url,
toFile: STORAGEPATH
}).promise;
if (statusCode === 200) return `file://${STORAGEPATH}`;
return false;
} catch (error) {
console.error('生成本地路径异常', error);
}
};
private getLocalDBBackupFilePath(): string {
return (
RNFS.LibraryDirectoryPath +
"/LocalDatabase/" +
this.getDatabaseBackupName()
);
}
}
private getLocalDBFilePath(): string {
return (
RNFS.LibraryDirectoryPath + "/LocalDatabase/" + this.getDatabaseName()
);
}
initializeUrl(){
const {pageInfo,play} = this.props
if(pageInfo){
if(!play.isPlay && pageInfo.media.mp3[0]) {
var audioUrl = pageInfo.media.mp3[0]
if(pageInfo.localFile){
if(Platform.OS === 'android'){
audioUrl = RNFS.ExternalDirectoryPath + '/' + pageInfo.id + '.mp3'
}else {
audioUrl = RNFS.LibraryDirectoryPath + '/' + pageInfo.id + '.mp3'
}
audioUrl = "file://" + audioUrl
}
this.terminate()
let track = {
id: ''+pageInfo.id,
url:audioUrl,
title: pageInfo.title,
artist: pageInfo.desc,
artwork:pageInfo.thumb_url
}
TrackPlayer.add(track);
}
}
}