Welcome to mirror list, hosted at ThFree Co, Russian Federation.

exporter-main.js « exporters « js - github.com/nextcloud/passman.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53d1ab9b29579756ddc26f2eb04a7a4836d3ea45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * Nextcloud - passman
 *
 * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

// Importers should always start with this
if (!window['PassmanExporter']) {
	var PassmanExporter = {
	    getCredentialsWithFiles: function(credentials, FileService, EncryptService) {
		var t = {
		    cred: credentials,
		    FS: FileService,
		    ES: EncryptService
		};
		/** global: C_Promise */
		return new C_Promise(function() {
		    var _this = this.parent;
		    var credentials = _this.cred;
		    this.parent.total = 0;
		    this.parent.finished = 0;
		    this.parent.fileGUID_cred = [];
		    this.parent.files = [];
		    this.parent.step = (function(file) {
			this.parent.finished ++;
			this.call_progress({
			    total: this.parent.total,
			    finished: this.parent.finished
			});
			
			var dta = this.parent.fileGUID_cred[file.guid];
			
			file.filename = this.parent.ES.decryptString(file.filename, this.parent.cred[dta.cred_pos].vault_key);
			file.file_data = this.parent.ES.decryptString(file.file_data, this.parent.cred[dta.cred_pos].vault_key);
			
			// Files and custom_fields have different field structure
			if (dta.on === 'files') {
			    this.parent.cred[dta.cred_pos][dta.on][dta.at] = file;
			}
			else {
			    this.parent.cred[dta.cred_pos][dta.on][dta.at].value = file;
			}
			
			// We have finished downloading everything, so let's hand over job to somewhere else!
			if (this.parent.total === this.parent.finished) {
			    this.call_then(this.parent.cred);
			}
		    }).bind(this);

		    for (var i = 0; i < credentials.length; i++) {
			
			var item = credentials[i];
			
			// Custom fields
			for (c = 0; c < item.custom_fields.length; c++) {
			    var cf = item.custom_fields[c];
			    if (cf.field_type === 'file') {
				this.parent.total ++;
				this.parent.fileGUID_cred[cf.value.guid] = {
				    cred_pos: i,
				    on: 'custom_fields',
				    at: c
				};

				this.parent.FS.getFile(cf.value).then((function(data){
				    this.parent.step(data);
				}).bind(this));
			    }
			}
			
			// Also get all files
			for (var c = 0; c < item.files.length; c++) {
			    this.parent.total ++;
			    this.parent.fileGUID_cred[item.files[c].guid] = {
				cred_pos: i,
				on: 'files',
				at: c
			    };

			    this.parent.FS.getFile(item.files[c]).then((function(data){
				this.parent.step(data);
			    }).bind(this));
			}
		    }
		}, t);
	    }
	};
}