@nka212bg/backend-utils 0.1.50 → 0.1.52
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/mailSmsTools/index.js +2 -2
- package/misc.js +7 -10
- package/package.json +1 -1
package/mailSmsTools/index.js
CHANGED
|
@@ -166,7 +166,7 @@ const createInstance = (options = {}) => {
|
|
|
166
166
|
? ""
|
|
167
167
|
: `<tr>
|
|
168
168
|
<td>
|
|
169
|
-
<a href="${baseUrl}" target="_blank" style="text-decoration: none; color: gray; font-size: 12px">${new Date().getFullYear()} ${
|
|
169
|
+
<a href="${baseUrl}" target="_blank" style="text-decoration: none; color: gray; font-size: 12px">${new Date().getFullYear()} ${name || ""}</a>
|
|
170
170
|
</td>
|
|
171
171
|
</tr>`
|
|
172
172
|
}
|
|
@@ -176,7 +176,7 @@ const createInstance = (options = {}) => {
|
|
|
176
176
|
|
|
177
177
|
const mailOptions = {
|
|
178
178
|
from: name ? { name, address: smtpUser } : smtpUser,
|
|
179
|
-
// html: handlebars(
|
|
179
|
+
// html: handlebars(defaultTemplate, { content, subject, logoUrl: `${process.env.BASE_URL}/logo_black.png` }),
|
|
180
180
|
html,
|
|
181
181
|
subject,
|
|
182
182
|
to: e,
|
package/misc.js
CHANGED
|
@@ -118,17 +118,14 @@ exports.createToken = ({ length = 14, type } = {}) => {
|
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
exports.
|
|
122
|
-
const placeholders = template.match(/(\{\{)(.*?)(\}\})/g);
|
|
121
|
+
exports.escapeHtml = (s) => String(s).replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return template;
|
|
123
|
+
// {{ key }} → raw (trusted), {{{ key }}} → HTML-escaped (untrusted); supports nested keys like {{ user.name }}
|
|
124
|
+
exports.handlebars = (template = "", params = {}) => {
|
|
125
|
+
return template.replace(/\{\{(\{?)\s*([\w.]+)\s*\}?\}\}/g, (match, safe, key) => {
|
|
126
|
+
const value = key.split(".").reduce((o, k) => o?.[k], params);
|
|
127
|
+
return value == null ? match : safe ? this.escapeHtml(value) : value;
|
|
128
|
+
});
|
|
132
129
|
};
|
|
133
130
|
|
|
134
131
|
exports.shortCount = (value, bites) => {
|