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

View file

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

View file

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