decode url when parse file name from url

master
MaysWind 2020-09-05 18:12:19 +08:00
parent a091ee850f
commit a31c055167
1 changed files with 14 additions and 3 deletions

View File

@ -9,9 +9,11 @@
}
var path = file.path;
var needUrlDecode = false;
if (!path && file.uris && file.uris.length > 0) {
path = file.uris[0].uri;
needUrlDecode = true;
}
var index = path.lastIndexOf('/');
@ -22,12 +24,21 @@
var fileNameAndQueryString = path.substring(index + 1);
var queryStringStartPos = fileNameAndQueryString.indexOf('?');
var fileName = fileNameAndQueryString;
if (queryStringStartPos <= 0) {
return fileNameAndQueryString;
if (queryStringStartPos > 0) {
fileName = fileNameAndQueryString.substring(0, queryStringStartPos);
}
return fileNameAndQueryString.substring(0, queryStringStartPos);
if (needUrlDecode) {
try {
fileName = decodeURI(fileName);
} catch (ex) {
ariaNgLogService.warn('[aria2TaskService.getFileName] failed to url decode file name, original file name: ' + fileName, ex);
}
}
return fileName;
};
var calculateDownloadRemainTime = function (remainBytes, downloadSpeed) {