isite 2022.9.15 → 2022.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/ui-print/site_files/js/index.js +186 -189
- package/lib/mongodb.js +17 -22
- package/lib/session.js +1 -1
- package/lib/sessions.js +7 -0
- package/package.json +1 -1
|
@@ -1,208 +1,205 @@
|
|
|
1
1
|
site.print = site.printHTML = function (options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
options = options || {};
|
|
3
|
+
let content = '';
|
|
4
|
+
|
|
5
|
+
if (typeof options === 'string') {
|
|
6
|
+
options = {
|
|
7
|
+
selector: options,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (!options.content) {
|
|
11
|
+
if (!options.selector) {
|
|
12
|
+
console.error('No Selector sets ...');
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
window.document.querySelectorAll('link[href]').forEach((l) => {
|
|
16
|
+
content += '<link rel="stylesheet" href="' + site.handle_url(l.href) + '" type="text/css" >';
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
window.document.querySelectorAll('style').forEach((s) => {
|
|
20
|
+
content += s.outerHTML;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (options.links) {
|
|
24
|
+
options.links.forEach((link) => {
|
|
25
|
+
content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
|
|
26
|
+
});
|
|
9
27
|
}
|
|
10
|
-
if (!options.content) {
|
|
11
|
-
if (!options.selector) {
|
|
12
|
-
console.error('No Selector sets ...');
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
window.document.querySelectorAll('link[rel=stylesheet]').forEach((l) => {
|
|
16
|
-
l.href = site.handle_url(l.href);
|
|
17
|
-
content += l.outerHTML;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
window.document.querySelectorAll('style').forEach((s) => {
|
|
21
|
-
content += s.outerHTML;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
if (options.links) {
|
|
25
|
-
options.links.forEach((link) => {
|
|
26
|
-
content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
});
|
|
29
|
+
if (options.preappends) {
|
|
30
|
+
options.preappends.forEach((el) => {
|
|
31
|
+
el = window.document.querySelector(el);
|
|
32
|
+
if (el) {
|
|
33
|
+
content += el.outerHTML;
|
|
37
34
|
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
document.querySelectorAll(options.selector).forEach((el) => {
|
|
39
|
+
let el2 = el.cloneNode(true);
|
|
40
|
+
el2.querySelectorAll('input').forEach((input) => {
|
|
41
|
+
input.setAttribute('value', input.value);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
el2.querySelectorAll('textarea').forEach((textarea) => {
|
|
45
|
+
textarea.innerText = textarea.value;
|
|
46
|
+
});
|
|
47
|
+
el2.style.display = 'block';
|
|
48
|
+
content += el2.outerHTML;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (options.appends) {
|
|
52
|
+
options.appends.forEach((el) => {
|
|
53
|
+
el = window.document.querySelector(el);
|
|
54
|
+
if (el) {
|
|
55
|
+
content += el.outerHTML;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
options.type = 'content';
|
|
61
|
+
content = options.content;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!options.ip) {
|
|
65
|
+
options.ip = '127.0.0.1';
|
|
66
|
+
}
|
|
67
|
+
if (!options.port) {
|
|
68
|
+
options.port = '60080';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
site.postData(
|
|
72
|
+
{ url: '/api/print', data: { content: content, type: options.type } },
|
|
73
|
+
(response) => {
|
|
74
|
+
if (response.done) {
|
|
75
|
+
if (options.printer) {
|
|
76
|
+
fetch(response.url, {
|
|
77
|
+
mode: 'cors',
|
|
78
|
+
method: 'get',
|
|
79
|
+
})
|
|
80
|
+
.then((res) => res.text())
|
|
81
|
+
.then((html) => {
|
|
82
|
+
options.html = html;
|
|
83
|
+
options.type = 'html';
|
|
84
|
+
site.postData(
|
|
85
|
+
{
|
|
86
|
+
url: `http://${options.ip}:${options.port}/print`,
|
|
87
|
+
data: options,
|
|
88
|
+
},
|
|
89
|
+
(res) => {
|
|
90
|
+
console.log(res);
|
|
91
|
+
},
|
|
92
|
+
(err) => {
|
|
93
|
+
console.log(err);
|
|
59
94
|
}
|
|
95
|
+
);
|
|
96
|
+
})
|
|
97
|
+
.catch((err) => {
|
|
98
|
+
console.error(err);
|
|
60
99
|
});
|
|
100
|
+
} else {
|
|
101
|
+
window.open(response.url);
|
|
61
102
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!options.ip) {
|
|
68
|
-
options.ip = '127.0.0.1';
|
|
69
|
-
}
|
|
70
|
-
if (!options.port) {
|
|
71
|
-
options.port = '60080';
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
(error) => {
|
|
106
|
+
console.log(error);
|
|
72
107
|
}
|
|
108
|
+
);
|
|
73
109
|
|
|
74
|
-
|
|
75
|
-
{ url: '/api/print', data: { content: content, type: options.type } },
|
|
76
|
-
(response) => {
|
|
77
|
-
if (response.done) {
|
|
78
|
-
if (options.printer) {
|
|
79
|
-
fetch(response.url, {
|
|
80
|
-
mode: 'cors',
|
|
81
|
-
method: 'get',
|
|
82
|
-
})
|
|
83
|
-
.then((res) => res.text())
|
|
84
|
-
.then((html) => {
|
|
85
|
-
options.html = html;
|
|
86
|
-
options.type = 'html';
|
|
87
|
-
site.postData(
|
|
88
|
-
{
|
|
89
|
-
url: `http://${options.ip}:${options.port}/print`,
|
|
90
|
-
data: options,
|
|
91
|
-
},
|
|
92
|
-
(res) => {
|
|
93
|
-
console.log(res);
|
|
94
|
-
},
|
|
95
|
-
(err) => {
|
|
96
|
-
console.log(err);
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
})
|
|
100
|
-
.catch((err) => {
|
|
101
|
-
console.error(err);
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
window.open(response.url);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
(error) => {
|
|
109
|
-
console.log(error);
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
return !0;
|
|
110
|
+
return !0;
|
|
114
111
|
};
|
|
115
112
|
|
|
116
113
|
site.printAsImageBusy = false;
|
|
117
114
|
|
|
118
115
|
site.printAsImage = function (options, callback) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
116
|
+
if (site.printAsImageBusy) {
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
site.printAsImage(options, callback);
|
|
119
|
+
}, 1000);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
site.printAsImageBusy = true;
|
|
124
|
+
options = options || {};
|
|
125
|
+
|
|
126
|
+
if (typeof options === 'string') {
|
|
127
|
+
options = {
|
|
128
|
+
selector: options,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (!options.selector) {
|
|
132
|
+
console.error('No Selector sets ...');
|
|
133
|
+
site.printAsImageBusy = false;
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (!options.ip) {
|
|
137
|
+
options.ip = '127.0.0.1';
|
|
138
|
+
}
|
|
139
|
+
if (!options.port) {
|
|
140
|
+
options.port = '60080';
|
|
141
|
+
}
|
|
142
|
+
if (!options.type) {
|
|
143
|
+
options.type = 'image';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let node = typeof options.selector === 'string' ? document.querySelector(options.selector) : options.selector;
|
|
147
|
+
if (!node) {
|
|
148
|
+
console.error('No Node Selector ');
|
|
149
|
+
site.printAsImageBusy = false;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
domtoimage
|
|
154
|
+
.toPng(node, { quality: 1, bgcolor: '#ffffff' })
|
|
155
|
+
.then(function (dataUrl) {
|
|
156
|
+
var img = new Image();
|
|
157
|
+
img.src = dataUrl;
|
|
158
|
+
if (callback) {
|
|
159
|
+
callback(img);
|
|
160
|
+
}
|
|
161
|
+
options.content = dataUrl;
|
|
162
|
+
site.printDataUrl(options);
|
|
163
|
+
site.printAsImageBusy = false;
|
|
164
|
+
})
|
|
165
|
+
.catch(function (error) {
|
|
166
|
+
console.error(error);
|
|
167
|
+
site.printAsImageBusy = false;
|
|
168
|
+
});
|
|
172
169
|
};
|
|
173
170
|
|
|
174
171
|
site.printDataUrl = function (options) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
172
|
+
site.postData(
|
|
173
|
+
{ url: '/api/print', data: options },
|
|
174
|
+
(response) => {
|
|
175
|
+
if (response.done) {
|
|
176
|
+
if (options.printer) {
|
|
177
|
+
fetch(response.url, {
|
|
178
|
+
mode: 'cors',
|
|
179
|
+
method: 'get',
|
|
180
|
+
})
|
|
181
|
+
.then((res) => res.text())
|
|
182
|
+
.then((html) => {
|
|
183
|
+
options.html = html;
|
|
184
|
+
options.type = 'html';
|
|
185
|
+
site.postData(
|
|
186
|
+
{
|
|
187
|
+
url: `http://${options.ip}:${options.port}/print`,
|
|
188
|
+
data: options,
|
|
189
|
+
},
|
|
190
|
+
(res) => {}
|
|
191
|
+
);
|
|
192
|
+
})
|
|
193
|
+
.catch((err) => {
|
|
194
|
+
console.error(err);
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
window.open(response.url);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
(error) => {
|
|
202
|
+
console.log(error);
|
|
203
|
+
}
|
|
204
|
+
);
|
|
208
205
|
};
|
package/lib/mongodb.js
CHANGED
|
@@ -56,27 +56,23 @@ module.exports = function init(____0) {
|
|
|
56
56
|
return doc;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
if (typeof doc === '
|
|
59
|
+
if (typeof doc === 'array') {
|
|
60
|
+
doc.forEach((v, i) => {
|
|
61
|
+
doc[i] = _mongo.handleDoc(v);
|
|
62
|
+
});
|
|
63
|
+
return doc;
|
|
64
|
+
} else if (typeof doc === 'object') {
|
|
60
65
|
for (let key in doc) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (typeof key === 'string') {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (typeof val === 'object') {
|
|
71
|
-
val = _mongo.handleDoc(val);
|
|
72
|
-
} else if (typeof val === 'array') {
|
|
73
|
-
val.forEach((v) => {
|
|
74
|
-
v = _mongo.handleDoc(v);
|
|
66
|
+
if (typeof key === 'string' && key.indexOf('$') === 0) {
|
|
67
|
+
delete doc[key];
|
|
68
|
+
} else if (typeof doc[key] === 'string' && ____0.fn.isDate(doc[key])) {
|
|
69
|
+
doc[key] = new Date(doc[key]);
|
|
70
|
+
} else if (typeof doc[key] === 'object') {
|
|
71
|
+
doc[key] = _mongo.handleDoc(doc[key]);
|
|
72
|
+
} else if (typeof doc[key] === 'array') {
|
|
73
|
+
doc[key].forEach((v, i) => {
|
|
74
|
+
doc[key][i] = _mongo.handleDoc(v);
|
|
75
75
|
});
|
|
76
|
-
} else if (typeof val === 'string') {
|
|
77
|
-
if (____0.fn.isDate(val)) {
|
|
78
|
-
doc[key] = new Date(val);
|
|
79
|
-
}
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
}
|
|
@@ -305,7 +301,6 @@ module.exports = function init(____0) {
|
|
|
305
301
|
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName).insertMany(obj.docs, obj.options, function (err, result) {
|
|
306
302
|
if (!err) {
|
|
307
303
|
callback(null, obj.docs, result);
|
|
308
|
-
console.log(' Sessions Saved : ' + obj.docs.length);
|
|
309
304
|
if (____0.options.mongodb.events) {
|
|
310
305
|
____0.call('mongodb after insert many', {
|
|
311
306
|
db: obj.dbName,
|
|
@@ -314,12 +309,12 @@ module.exports = function init(____0) {
|
|
|
314
309
|
});
|
|
315
310
|
}
|
|
316
311
|
} else {
|
|
317
|
-
console.error('
|
|
312
|
+
console.error(' _mongo.insertMany() ', err.message);
|
|
318
313
|
callback(err, obj.docs, result);
|
|
319
314
|
}
|
|
320
315
|
});
|
|
321
316
|
} else {
|
|
322
|
-
console.error('
|
|
317
|
+
console.error(' _mongo.insertMany() ', err.message);
|
|
323
318
|
callback(err);
|
|
324
319
|
}
|
|
325
320
|
});
|
package/lib/session.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = function init(req, res, ____0, callback) {
|
|
2
|
-
let session = ____0.getSession({ accessToken: req.cookie('access_token') || req.headers['access-token'] });
|
|
2
|
+
let session = ____0.getSession({ accessToken: req.cookie('access_token') || req.headers['Access-Token'] || req.headers['access-token'] });
|
|
3
3
|
|
|
4
4
|
if (!session.accessToken) {
|
|
5
5
|
session.accessToken = new Date().getTime().toString() + '_' + Math.random() * (10000 - 1000) + 1000;
|
package/lib/sessions.js
CHANGED
|
@@ -179,6 +179,13 @@ module.exports = function init(____0) {
|
|
|
179
179
|
});
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
+
____0.onPOST('x-api/session', (req, res) => {
|
|
183
|
+
res.json({
|
|
184
|
+
done: !0,
|
|
185
|
+
session: req.session,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
182
189
|
____0.onPOST('x-api/sessions', (req, res) => {
|
|
183
190
|
res.json({
|
|
184
191
|
done: !0,
|