fix cannot open torrent file sometimes

This commit is contained in:
MaysWind 2018-05-10 00:42:09 +08:00
parent 1588af21b7
commit ee1ea1626c
3 changed files with 40 additions and 31 deletions

View file

@ -120,7 +120,7 @@
$scope.changeTab('options');
}, function (error) {
ariaNgCommonService.showError(error);
});
}, angular.element('#file-holder'));
};
$scope.openMetalink = function () {
@ -130,7 +130,7 @@
$scope.changeTab('options');
}, function (error) {
ariaNgCommonService.showError(error);
});
}, angular.element('#file-holder'));
};
$scope.startDownload = function (pauseOnAdded) {

View file

@ -46,7 +46,7 @@
};
return {
openFileContent: function (fileFilter, successCallback, errorCallback) {
openFileContent: function (fileFilter, successCallback, errorCallback, element) {
if (!isSupportFileReader) {
if (errorCallback) {
errorCallback('Your browser does not support loading file!');
@ -57,43 +57,51 @@
var allowedExtensions = getAllowedExtensions(fileFilter);
angular.element('<input type="file" style="display: none"/>').change(function () {
if (!this.files || this.files.length < 1) {
return;
}
if (!element || !element.change) {
element = angular.element('<input type="file" style="display: none"/>');
}
var file = this.files[0];
var fileName = file.name;
if (!checkFileExtension(fileName, allowedExtensions)) {
if (errorCallback) {
errorCallback('The selected file type is invalid!');
if (element.attr('data-ariang-file-initialized') !== 'true') {
element.change(function () {
if (!this.files || this.files.length < 1) {
return;
}
return;
}
var file = this.files[0];
var fileName = file.name;
var reader = new FileReader();
if (!checkFileExtension(fileName, allowedExtensions)) {
if (errorCallback) {
errorCallback('The selected file type is invalid!');
}
reader.onload = function () {
var result = {
fileName: fileName,
base64Content: this.result.replace(/.*?base64,/, '')
return;
}
var reader = new FileReader();
reader.onload = function () {
var result = {
fileName: fileName,
base64Content: this.result.replace(/.*?base64,/, '')
};
if (successCallback) {
successCallback(result);
}
};
if (successCallback) {
successCallback(result);
}
};
reader.onerror = function () {
if (errorCallback) {
errorCallback('Failed to load file!');
}
};
reader.onerror = function () {
if (errorCallback) {
errorCallback('Failed to load file!');
}
};
reader.readAsDataURL(file);
}).attr('data-ariang-file-initialized', 'true');
}
reader.readAsDataURL(file);
}).trigger('click');
element.trigger('click');
}
};
}]);

View file

@ -61,6 +61,7 @@
</div>
</div>
</div>
<input id="file-holder" type="file" style="display: none"/>
</div>
<div class="tab-pane" ng-class="{'active': context.currentTab == 'options'}">
<div class="settings-table striped hoverable">