#35 [neutratywy] powiadomienia mailowe o potrzebie moderacji

This commit is contained in:
Avris 2020-08-06 16:33:16 +02:00
parent 14d83c27f3
commit aa47d2a904
5 changed files with 79 additions and 3 deletions

View File

@ -1,2 +1,9 @@
BASE_URL=http://localhost:3000
SECRET=secret
MAILER_HOST=
MAILER_PORT=
MAILER_USER=
MAILER_PASS=
MAILER_FROM=
MAILER_ADMINS=

View File

@ -14,12 +14,14 @@
"@nuxtjs/pwa": "^3.0.0-beta.20",
"body-parser": "^1.19.0",
"canvas": "^2.6.1",
"dotenv": "^8.2.0",
"mailer": "^0.6.7",
"nuxt": "^2.13.0",
"vue-matomo": "^3.13.5-0",
"sql-template-strings": "^2.2.2",
"sqlite": "^4.0.12",
"sqlite3": "^5.0.0",
"ulid": "^2.3.0"
"ulid": "^2.3.0",
"vue-matomo": "^3.13.5-0"
},
"devDependencies": {
"@fortawesome/fontawesome-pro": "git+ssh://git@gitlab.com:Avris/FontAwesomePro.git",

View File

@ -8,7 +8,7 @@ const fixtures = [
['filolog', 'filolożka', 'filologum', 'filologowie', 'filolożki', 'filologa'],
];
async function initDb () {
async function initDb() {
const db = await sqlite.open({
filename: __dirname + '/../data/db.sqlite',
driver: sqlite3.Database,

42
server/notify.js Normal file
View File

@ -0,0 +1,42 @@
const sqlite = require('sqlite');
const sqlite3 = require('sqlite3');
const mailer = require('mailer');
require('dotenv').config({ path:__dirname + '/../.env' });
async function notify() {
const db = await sqlite.open({
filename: __dirname + '/../data/db.sqlite',
driver: sqlite3.Database,
});
const awaitingModeration = (await db.get(`SELECT count(*) as c FROM nouns WHERE approved = 0`)).c;
if (!awaitingModeration) {
console.log('No entries awaiting moderation');
return;
}
console.log('Entries awaiting moderation: ' + awaitingModeration);
for (let admin of process.env.MAILER_ADMINS.split(',')) {
console.log('Sending email to ' + admin)
mailer.send({
host: process.env.MAILER_HOST,
port: parseInt(process.env.MAILER_PORT),
ssl: parseInt(process.env.MAILER_PORT) === 465,
authentication: 'login',
username: process.env.MAILER_USER,
password: process.env.MAILER_PASS,
from: process.env.MAILER_FROM,
to: admin,
subject: '[Zaimki.pl] Wpisy oczekują na moderację',
body: 'Liczba wpisów: ' + awaitingModeration,
},
function(err, result){
if (err) {
console.log(err);
}
});
}
}
notify();

View File

@ -2484,6 +2484,11 @@ colorette@^1.2.0:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
"colors@>= 0.3.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
@ -5064,6 +5069,14 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"
mailer@^0.6.7:
version "0.6.7"
resolved "https://registry.yarnpkg.com/mailer/-/mailer-0.6.7.tgz#012d69b2554864976d9d77f5326b35097653f653"
integrity sha1-AS1pslVIZJdtnXf1Mms1CXZT9lM=
dependencies:
colors ">= 0.3.0"
nodemailer "0.1.20"
make-dir@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c"
@ -5246,6 +5259,11 @@ mime@^2.3.1, mime@^2.4.4:
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.6.tgz#e5b407c90db442f2beb5b162373d07b69affa4d1"
integrity sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==
mimelib-noiconv@*:
version "0.1.9"
resolved "https://registry.yarnpkg.com/mimelib-noiconv/-/mimelib-noiconv-0.1.9.tgz#eadce6f9ce226842501a203e95bcee96af8189f2"
integrity sha1-6tzm+c4iaEJQGiA+lbzulq+BifI=
mimic-fn@^2.0.0, mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
@ -5561,6 +5579,13 @@ node-res@^5.0.1:
on-finished "^2.3.0"
vary "^1.1.2"
nodemailer@0.1.20:
version "0.1.20"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-0.1.20.tgz#a91748a448eddf35fe24d7272c8187ddcc38e253"
integrity sha1-qRdIpEjt3zX+JNcnLIGH3cw44lM=
dependencies:
mimelib-noiconv "*"
"nopt@2 || 3":
version "3.0.6"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-3.0.6.tgz#c6465dbf08abcd4db359317f79ac68a646b28ff9"