mirror of
https://github.com/moparisthebest/mail
synced 2024-11-10 11:15:01 -05:00
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
var ngModule = angular.module('woDirectives');
|
||
|
|
||
|
ngModule.directive('fileReader', function() {
|
||
|
return function(scope, elm) {
|
||
|
elm.bind('change', function(e) {
|
||
|
var files = e.target.files,
|
||
|
reader = new FileReader();
|
||
|
|
||
|
if (files.length === 0) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
reader.onload = function(e) {
|
||
|
var rawKeys = e.target.result,
|
||
|
index = rawKeys.indexOf('-----BEGIN PGP PRIVATE KEY BLOCK-----'),
|
||
|
keyParts;
|
||
|
|
||
|
if (index === -1) {
|
||
|
scope.displayError(new Error('Error parsing private PGP key block!'));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
keyParts = {
|
||
|
publicKeyArmored: rawKeys.substring(0, index).trim(),
|
||
|
privateKeyArmored: rawKeys.substring(index, rawKeys.length).trim()
|
||
|
};
|
||
|
|
||
|
scope.$apply(function() {
|
||
|
scope.key = keyParts;
|
||
|
});
|
||
|
};
|
||
|
reader.readAsText(files[0]);
|
||
|
});
|
||
|
};
|
||
|
});
|