1 | /* |
2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
3 | |
4 | This program is free software; |
5 | you can redistribute it and/or modify it under the terms of the |
6 | GNU General Public License as published by the Free Software Foundation; |
7 | either version 3 of the License, or any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | /* |
19 | Changes: |
20 | - v4.0.0: |
21 | - created from v3.6.0 |
22 | Doc reviewed 202208 |
23 | */ |
24 | |
25 | import PasswordDialog from '../passwordDialog/PasswordDialog.js'; |
26 | import DataEncryptor from '../../core/lib/DataEncryptor.js'; |
27 | import DataEncryptorHandlers from './DataEncryptorHandlers.js'; |
28 | import { ZERO } from '../../main/Constants.js'; |
29 | |
30 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
31 | /** |
32 | Change event listener for the open secure file input |
33 | */ |
34 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
35 | |
36 | class OpenSecureFileChangeEL { |
37 | |
38 | /** |
39 | A reference to the ApiKeys dialog |
40 | @type {ApiKeysDialog} |
41 | */ |
42 | |
43 | #apiKeysDialog; |
44 | |
45 | /** |
46 | A DataEncryptorHandlers object used to encode / decode the ApiKeys |
47 | @type {DataEncryptorHandlers} |
48 | */ |
49 | |
50 | #dataEncryptorHandlers; |
51 | |
52 | /** |
53 | The constructor |
54 | @param {ApiKeysDialog} apiKeysDialog A reference to the ApiKeys dialog |
55 | */ |
56 | |
57 | constructor ( apiKeysDialog ) { |
58 | Object.freeze ( this ); |
59 | this.#apiKeysDialog = apiKeysDialog; |
60 | this.#dataEncryptorHandlers = new DataEncryptorHandlers ( this.#apiKeysDialog ); |
61 | } |
62 | |
63 | /** |
64 | The destructor |
65 | */ |
66 | |
67 | destructor ( ) { |
68 | this.#dataEncryptorHandlers.destructor ( ); |
69 | this.#apiKeysDialog = null; |
70 | } |
71 | |
72 | /** |
73 | Event listener method |
74 | @param {Event} changeEvent The event to handle |
75 | */ |
76 | |
77 | handleEvent ( changeEvent ) { |
78 | changeEvent.stopPropagation ( ); |
79 | this.#apiKeysDialog.showWait ( ); |
80 | this.#apiKeysDialog.keyboardELEnabled = false; |
81 | const fileReader = new FileReader ( ); |
82 | fileReader.onload = ( ) => { |
83 | new DataEncryptor ( ).decryptData ( |
84 | fileReader.result, |
85 | data => { this.#dataEncryptorHandlers.onOkDecrypt ( data ); }, |
86 | err => { this.#dataEncryptorHandlers.onErrorDecrypt ( err ); }, |
87 | new PasswordDialog ( false ).show ( ) |
88 | ); |
89 | }; |
90 | fileReader.readAsArrayBuffer ( changeEvent.target.files [ ZERO ] ); |
91 | } |
92 | } |
93 | |
94 | export default OpenSecureFileChangeEL; |
95 | |
96 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
97 |