|
|
@ -2,10 +2,6 @@ const fs = require("fs");
|
|
|
|
const Mailgun = require("mailgun.js");
|
|
|
|
const Mailgun = require("mailgun.js");
|
|
|
|
const formData = require("form-data");
|
|
|
|
const formData = require("form-data");
|
|
|
|
const dotenv = require("dotenv");
|
|
|
|
const dotenv = require("dotenv");
|
|
|
|
const i18next = require("i18next");
|
|
|
|
|
|
|
|
const Backend = require("i18next-chained-backend");
|
|
|
|
|
|
|
|
const FSBackend = require("i18next-fs-backend");
|
|
|
|
|
|
|
|
const HttpApi = require("i18next-http-backend");
|
|
|
|
|
|
|
|
const Handlebars = require("handlebars");
|
|
|
|
const Handlebars = require("handlebars");
|
|
|
|
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
dotenv.config();
|
|
|
@ -33,55 +29,6 @@ const err = {
|
|
|
|
body: "Can't send message",
|
|
|
|
body: "Can't send message",
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// setup i18n
|
|
|
|
|
|
|
|
// i18next.use(Backend).init({
|
|
|
|
|
|
|
|
// lng: "fr",
|
|
|
|
|
|
|
|
// ns: ["emailInvite", "common"],
|
|
|
|
|
|
|
|
// defaultNS: "emailInvite",
|
|
|
|
|
|
|
|
// fallbackNS: "common",
|
|
|
|
|
|
|
|
// debug: false,
|
|
|
|
|
|
|
|
// fallbackLng: ["fr"],
|
|
|
|
|
|
|
|
// backend: {
|
|
|
|
|
|
|
|
// backends: [FSBackend, HttpApi],
|
|
|
|
|
|
|
|
// backendOptions: [{ loadPath: "/public/locales/{{lng}}/{{ns}}.json" }, {}],
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// setup the template engine
|
|
|
|
|
|
|
|
// See https://github.com/UUDigitalHumanitieslab/handlebars-i18next
|
|
|
|
|
|
|
|
// function extend(target, ...sources) {
|
|
|
|
|
|
|
|
// sources.forEach((source) => {
|
|
|
|
|
|
|
|
// if (source)
|
|
|
|
|
|
|
|
// for (let key in source) {
|
|
|
|
|
|
|
|
// target[key] = source[key];
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// return target;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Handlebars.registerHelper("i18n", function (key, { hash, data, fn }) {
|
|
|
|
|
|
|
|
// let parsed = {};
|
|
|
|
|
|
|
|
// const jsonKeys = [
|
|
|
|
|
|
|
|
// "lngs",
|
|
|
|
|
|
|
|
// "fallbackLng",
|
|
|
|
|
|
|
|
// "ns",
|
|
|
|
|
|
|
|
// "postProcess",
|
|
|
|
|
|
|
|
// "interpolation",
|
|
|
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// jsonKeys.forEach((key) => {
|
|
|
|
|
|
|
|
// if (hash[key]) {
|
|
|
|
|
|
|
|
// parsed[key] = JSON.parse(hash[key]);
|
|
|
|
|
|
|
|
// delete hash[key];
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// let options = extend({}, data.root.i18next, hash, parsed, {
|
|
|
|
|
|
|
|
// returnObjects: false,
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// let replace = (options.replace = extend({}, this, options.replace, hash));
|
|
|
|
|
|
|
|
// delete replace.i18next; // may creep in if this === data.root
|
|
|
|
|
|
|
|
// if (fn) options.defaultValue = fn(replace);
|
|
|
|
|
|
|
|
// return new Handlebars.SafeString(i18next.t(key, options));
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// const txtStr = fs.readFileSync(__dirname + "/invite.txt").toString();
|
|
|
|
|
|
|
|
const txtStr = {
|
|
|
|
const txtStr = {
|
|
|
|
en: fs.readFileSync(__dirname + "/invite-en.txt").toString(),
|
|
|
|
en: fs.readFileSync(__dirname + "/invite-en.txt").toString(),
|
|
|
|
fr: fs.readFileSync(__dirname + "/invite-fr.txt").toString(),
|
|
|
|
fr: fs.readFileSync(__dirname + "/invite-fr.txt").toString(),
|
|
|
@ -118,13 +65,11 @@ const sendMail = async (event) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// i18next.changeLanguage(data.locale);
|
|
|
|
|
|
|
|
const templateData = {
|
|
|
|
const templateData = {
|
|
|
|
title: data.title,
|
|
|
|
title: data.title,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const mailgunData = {
|
|
|
|
const mailgunData = {
|
|
|
|
// from: `${i18next.t("Mieux Voter")} <mailgun@mg.app.mieuxvoter.fr>`,
|
|
|
|
|
|
|
|
from: '"Mieux Voter" <postmaster@mg.app.mieuxvoter.fr>',
|
|
|
|
from: '"Mieux Voter" <postmaster@mg.app.mieuxvoter.fr>',
|
|
|
|
to: Object.keys(data.recipientVariables),
|
|
|
|
to: Object.keys(data.recipientVariables),
|
|
|
|
text: txtTemplate.fr(templateData),
|
|
|
|
text: txtTemplate.fr(templateData),
|
|
|
|