catching up with progress from Sites and Soapbox

master
rob 2 years ago
parent 3131881e73
commit e0eb9f8a03

@ -22,7 +22,7 @@ MAILGUN_DOMAIN=
#
MONGODB_HOST=localhost:27017
MONGODB_DATABASE=dtp-sites
MONGODB_DATABASE=dtp-webapp
#
# Redis configuration
@ -39,7 +39,7 @@ REDIS_PASSWORD=
MINIO_ENDPOINT=localhost
MINIO_PORT=9000
MINIO_USE_SSL=disabled
MINIO_ACCESS_KEY=dtp-sites
MINIO_ACCESS_KEY=dtp-webapp
MINIO_SECRET_KEY=
MINIO_IMAGE_BUCKET=site-images
MINIO_VIDEO_BUCKET=site-videos
@ -60,7 +60,7 @@ DTP_LOG_CONSOLE=enabled
DTP_LOG_MONGODB=enabled
DTP_LOG_FILE=enabled
DTP_LOG_FILE_PATH=/tmp/dtp-sites/logs
DTP_LOG_FILE_PATH=/tmp/dtp-webapp/logs
DTP_LOG_FILE_NAME_APP=justjoeradio-app.log
DTP_LOG_FILE_NAME_HTTP=justjoeradio-access.log

@ -7,11 +7,11 @@
{
"type": "pwa-node",
"request": "launch",
"name": "web:dtp-sites",
"name": "web:dtp-webapp",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder:dtp-sites}/dtp-sites.js",
"program": "${workspaceFolder:dtp-base}/dtp-webapp.js",
"console": "integratedTerminal",
"env": {
"HTTP_BIND_PORT": "3333"
@ -20,11 +20,11 @@
{
"type": "pwa-node",
"request": "launch",
"name": "cli:dtp-sites",
"name": "cli:dtp-webapp",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder:dtp-sites}/dtp-sites-cli.js",
"program": "${workspaceFolder:dtp-base}/dtp-webapp-cli.js",
"console": "integratedTerminal",
"args": ["--action=reset-indexes", "all"]
}

@ -1,4 +1,4 @@
Copyright 2021 Digital Telepresence, LLC
Copyright 2022 DTP Technologies, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

@ -1,22 +1 @@
Want to tune in live
Want chat
Most Recent Episode
Featured Clips
Replays
About
Contact Us
Forum
Suggestion Box
- "I want to see [name] on the show as a guest"
Merch Store
- T-shirt
- Hat
- Tumbler / coffee mug
Opie & Anthony (Cumia)
restream.io
2022-03-03: Forked from dtp-sites to become new base for all DTP web apps

@ -1,5 +1,5 @@
// admin.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/content-report.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/host.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/job-queue.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/log.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/newsletter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/page.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/post.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/settings.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// admin/user.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// auth.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// comment.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// content-report.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// home.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// page.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// manifest.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// newsletter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// page.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// post.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// user.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// welcome.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// category.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// chat-message.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// comment.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// connect-token.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// content-report.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// content-vote.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// csrf-token.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// email-blacklist.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// email-body.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// email.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// image.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// geo-types.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// lib/resource-stats.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// log.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// net-host-stats.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// net-host.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// newsletter-recipient.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// newsletter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// otp-account.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// page.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// post.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// resource-view.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// resource-visit.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// user-block.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// user-notification.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// user.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// cache.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// chat.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// comment.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// content-report.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// content-vote.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// crypto.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// csrf-token.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// display-engine.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// email.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// gab-tv.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// host-cache.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// minio.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// job-queue.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// limiter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// log.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// markdown.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// article.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// minio.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// newsletter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// otp-auth.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// page.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// post.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// resource.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// session.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// sms.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// user-notification.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// user.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// host-services.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
@ -585,6 +585,18 @@ module.expireNetHosts = async ( ) => {
(async ( ) => {
try {
process.on('unhandledRejection', (error, p) => {
module.log.error('Unhandled rejection', {
error: error,
promise: p,
stack: error.stack
});
});
process.on('warning', (error) => {
module.log.alert('warning', { error });
});
process.once('SIGINT', async ( ) => {
module.log.info('SIGINT received');
module.log.info('requesting shutdown...');

@ -1,113 +0,0 @@
// newsletter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// License: Apache-2.0
'use strict';
const DTP_COMPONENT_NAME = 'newsletter';
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '..', '..', '.env') });
const mongoose = require('mongoose');
const { SitePlatform, SiteLog } = require(path.join(__dirname, '..', '..', 'lib', 'site-lib'));
module.pkg = require(path.resolve(__dirname, '..', '..', 'package.json'));
module.config = {
componentName: DTP_COMPONENT_NAME,
root: path.resolve(__dirname, '..', '..'),
};
module.log = new SiteLog(module, module.config.componentName);
module.sendNewsletter = async (job) => {
module.log.info('newsletter email job received', { data: job.data });
const NewsletterRecipient = mongoose.model('NewsletterRecipient');
try {
/*
* Create one Bull Queue job per email to be delivered.
*/
await NewsletterRecipient
.find({ 'flags.isVerified': true, 'flags.isOptIn': true, 'flags.isRejected': false })
.lean()
.cursor()
.eachAsync(async (recipient) => {
try {
const jobData = {
newsletterId: job.data.newsletterId,
recipient: recipient.address,
};
const jobOptions = {
attempts: 3,
};
await module.jobQueue.add('email-send', jobData, jobOptions);
} catch (error) {
module.log.error('failed to create newsletter email job');
// but continue
}
}, { parallel: 4 });
} catch (error) {
module.log('failed to send newsletter', { newsletterId: job.data.newsletterId, error });
throw error; // throw error to Bull so it can report in job reports
}
};
module.sendNewsletterEmail = async (job) => {
const { newsletter: newsletterService, email: emailService } = module.services;
const { newsletterId, recipient } = job.data;
try {
let newsletter = module.newsletters[newsletterId];
if (!newsletter) {
newsletter = await newsletterService.getById(newsletterId);
module.newsletters[newsletterId] = newsletter; //TODO: clean up memory leak of newsletter (remove when all emails are sent)
}
if (!newsletter) {
throw new Error('newsletter not found');
}
const response = await emailService.send({
from: 'demo@wherever.com',
to: recipient,
subject: newsletter.title,
html: newsletter.content.html,
text: newsletter.content.text,
});
job.log(`newsletter email sent: ${response}`);
} catch (error) {
module.error('failed to send newsletter email', { newsletterId, recipient, error });
throw error; // throw error to Bull so it can report in job reports
}
};
(async ( ) => {
try {
/*
* Platform startup
*/
await SitePlatform.startPlatform(module);
const { jobQueue: jobQueueService } = module.services;
module.jobQueue = await jobQueueService.getJobQueue('newsletter', {
attempts: 3,
});
module.jobQueue.process('email', module.sendNewsletter);
module.jobQueue.process('email-send', module.sendNewsletterEmail);
/*
* Worker startup
*/
module.log.info(`${module.pkg.name} v${module.pkg.version} Newsletter worker started`);
} catch (error) {
module.log.error('failed to start Newsletter worker', { error });
process.exit(-1);
}
})();

@ -1,5 +1,5 @@
// host-services.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
@ -46,11 +46,23 @@ module.expireCrashedHosts = async ( ) => {
(async ( ) => {
try {
process.on('unhandledRejection', (error, p) => {
module.log.error('Unhandled rejection', {
error: error,
promise: p,
stack: error.stack
});
});
process.on('warning', (error) => {
module.log.alert('warning', { error });
});
process.once('SIGINT', async ( ) => {
module.log.info('SIGINT received');
module.log.info('requesting shutdown...');
const exitCode = await SitePlatform.shutdown();
process.nextTick(( ) => {
process.exit(exitCode);
});

@ -1,5 +1,5 @@
// index-admin.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// index.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// dtp-site-app.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// site-app.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -15,7 +15,6 @@
@import "site/dashboard.less";
@import "site/site.less";
@import "site/site-home.less";
@import "site/form.less";
@import "site/button.less";

@ -1,11 +1,11 @@
// job-queues.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
module.exports = {
// 'dvr-ingest': {
// 'queue-name': {
// attempts: 3,
// },
};

@ -1,5 +1,5 @@
// limiter.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -0,0 +1,13 @@
// site.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache 2.0
'use strict';
module.exports = {
name: process.env.DTP_SITE_NAME,
description: process.env.DTP_SITE_DESCRIPTION,
domain: process.env.DTP_SITE_DOMAIN,
domainKey: process.env.DTP_SITE_DOMAIN_KEY,
company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC',
};

@ -1,4 +1,4 @@
# DTP Sites: Services
# DTP Base: Services
Services are common logic implemented in a centralized location made accessible to the rest of the application to perform tasks in a common way. They live in [app/services](app/services), and are scripts that export a specific structure that identifies the service and provides a way to create, start, and stop them.

@ -1,9 +1,11 @@
// dtp-sites-cli.js
// Copyright (C) 2021 Digital Telepresence, LLC
// dtp-webapp-cli.js
// Copryright (C) DTP Technologies, LLC
// License: Apache-2.0
'use strict';
const DTP_COMPONENT_NAME = 'webapp-cli';
require('dotenv').config();
const path = require('path');
@ -16,17 +18,12 @@ const {
SiteLog,
} = require(path.join(__dirname, 'lib', 'site-lib'));
module.pkg = require(path.join(__dirname, 'package.json'));
module.rootPath = __dirname;
module.pkg = require(path.join(module.rootPath, 'package.json'));
module.config = {
componentName: 'sites-cli',
root: __dirname,
site: {
name: process.env.DTP_SITE_NAME,
description: process.env.DTP_SITE_DESCRIPTION,
domain: process.env.DTP_SITE_DOMAIN,
domainKey: process.env.DTP_SITE_DOMAIN_KEY,
company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC',
},
componentName: DTP_COMPONENT_NAME,
root: module.rootPath,
site: require(path.join(module.rootPath, 'config', 'site')),
};
module.log = new SiteLog(module, module.config.componentName);
@ -79,12 +76,6 @@ module.revokePermission = async (target, permission) => {
}
};
module.dvrIngest = async (episodeId) => {
const jobQueue = module.services.jobQueue.getJobQueue('dvr-ingest', module.config.jobQueues['dvr-ingest']);
const job = await jobQueue.add({ episodeId });
module.log.info('job created', { id: job.id });
};
module.deleteOtpAccount = async (target) => {
const { otpAuth: otpAuthService } = module.services;
const User = mongoose.model('User');
@ -116,6 +107,67 @@ module.resetIndexes = async ( ) => {
}
};
module.resetPassword = async (username) => {
const { user: userService } = module.services;
const User = mongoose.model('User');
const user = await User
.findOne({
username_lc: username.trim().toLowerCase(),
})
.lean();
if (!user) {
throw new Error('user not found');
}
const password = generatePassword(8, true);
module.log.info('updating user password', { username, password });
await userService.updatePassword(user, password);
};
module.sendWelcomeEmail = async (username) => {
const User = mongoose.model('User');
if (username === 'all') {
await User
.find()
.select('+flags +optIn')
.cursor()
.eachAsync(module.sendUserWelcomeEmail, 4);
} else {
const user = await User
.findOne({
username_lc: username.trim().toLowerCase(),
})
.select('+flags +optIn')
.lean();
if (!user) {
throw new Error('user not found');
}
await module.sendUserWelcomeEmail(user);
}
};
module.sendUserWelcomeEmail = async (user) => {
const { user: userService } = module.services;
if (user.flags.isEmailVerified) {
module.log.alert('user is email-verified (aboring welcome email)', {
user: user._id,
username: user.username,
});
return;
}
module.log.info('sending welcome email', {
user: user._id,
username: user.username,
email: user.email,
});
await userService.sendWelcomeEmail(user);
};
/*
* SERVER INIT
*/
@ -130,21 +182,21 @@ module.resetIndexes = async ( ) => {
short: 'a',
type: 'string',
description: 'The action to perform',
example: 'sites-cli --action=grant --permission=moderator email email ...',
example: 'dtp-webapp-cli --action=grant --permission=moderator email email ...',
},
{
name: 'permission',
short: 'p',
type: 'string',
description: 'The permission(s) being added or removed',
example: 'sites-cli --action=grant --permission=admin email email ...'
example: 'dtp-webapp-cli --action=grant --permission=admin email email ...'
},
]);
try {
await SitePlatform.startPlatform(module);
} catch (error) {
module.log.error('failed to start DTP Sites platform', { error });
module.log.error(`failed to start DTP ${DTP_COMPONENT_NAME} platform`, { error });
return;
}
@ -162,10 +214,6 @@ module.resetIndexes = async ( ) => {
await module.revokePermission(target, module.app.options.permission);
break;
case 'dvr-ingest':
await module.dvrIngest(target);
break;
case 'make-bucket':
await module.makeBucket(target);
break;
@ -174,10 +222,18 @@ module.resetIndexes = async ( ) => {
await module.deleteOtpAccount(target);
break;
case 'reset-password':
await module.resetPassword(target);
break;
case 'reset-indexes':
await module.resetIndexes();
break;
case 'welcome-email':
await module.sendWelcomeEmail(target);
break;
default:
throw new Error(`invalid action: ${module.app.options.action}`);
}

@ -1,26 +1,23 @@
// dtp-sites.js
// Copryright (C) Digital Telepresence, LLC
// dtp-webapp.js
// Copryright (C) DTP Technologies, LLC
// Licence: Apache-2.0
'use strict';
const DTP_COMPONENT_NAME = 'webapp';
require('dotenv').config();
const path = require('path');
const { SitePlatform, SiteLog } = require(path.join(__dirname, 'lib', 'site-lib'));
module.pkg = require(path.join(__dirname, 'package.json'));
module.rootPath = __dirname;
module.pkg = require(path.join(module.rootPath, 'package.json'));
module.config = {
componentName: 'sites',
root: __dirname,
site: {
name: process.env.DTP_SITE_NAME,
description: process.env.DTP_SITE_DESCRIPTION,
domain: process.env.DTP_SITE_DOMAIN,
domainKey: process.env.DTP_SITE_DOMAIN_KEY,
company: process.env.DTP_SITE_COMPANY || 'Digital Telepresence, LLC',
},
componentName: DTP_COMPONENT_NAME,
root: module.rootPath,
site: require(path.join(module.rootPath, 'config', 'site')),
http: {
address: process.env.HTTP_BIND_ADDRESS,
port: parseInt(process.env.HTTP_BIND_PORT, 10),
@ -29,6 +26,10 @@ module.config = {
module.log = new SiteLog(module, module.config.componentName);
module.shutdown = async ( ) => {
};
(async ( ) => {
process.on('unhandledRejection', (error, p) => {
@ -46,6 +47,7 @@ module.log = new SiteLog(module, module.config.componentName);
process.once('SIGINT', async ( ) => {
module.log.info('SIGINT received');
module.log.info('requesting shutdown...');
await module.shutdown();
const exitCode = await SitePlatform.shutdown();
process.nextTick(( ) => {
process.exit(exitCode);
@ -61,7 +63,7 @@ module.log = new SiteLog(module, module.config.componentName);
await SitePlatform.startPlatform(module);
await SitePlatform.startWebServer(module);
} catch (error) {
module.log.error('failed to start DTP Sites web server', { error });
module.log.error(`failed to start DTP ${DTP_COMPONENT_NAME}`, { error });
process.exit(-1);
}

@ -1,5 +1,5 @@
// dtp-app.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// dtp-display-engine.js
// Copyright (C) 2021 Digital Telepresence, Inc.
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// dtpweb-log.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// dtp-plugin.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
/**

@ -1,5 +1,5 @@
// dtpweb-socket.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

@ -1,5 +1,5 @@
// site-async.js
// Copyright (C) 2021 Digital Telepresence, LLC
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save