From 0eb41a1e1280342111ec249fdf0da0129a4bd1d9 Mon Sep 17 00:00:00 2001 From: les Date: Sun, 25 Aug 2019 14:34:26 +0200 Subject: [PATCH] cleaning --- locales/email/it.json | 4 +- locales/it.js | 2 +- server/api/controller/event.js | 4 +- server/api/controller/fediverse.js | 68 ------------------------------ server/api/index.js | 12 +----- server/emails/confirm/html.pug | 4 +- server/emails/recover/html.pug | 2 +- server/federation/index.js | 1 - server/federation/users.js | 4 -- server/federation/webfinger.js | 8 ++++ server/index.js | 5 ++- server/notifier.js | 24 +++++------ server/routes.js | 15 +++++++ 13 files changed, 48 insertions(+), 105 deletions(-) delete mode 100644 server/api/controller/fediverse.js diff --git a/locales/email/it.json b/locales/email/it.json index ba704515..1b52696d 100644 --- a/locales/email/it.json +++ b/locales/email/it.json @@ -1,9 +1,9 @@ { "email.register.subject": "Richiesta registrazione ricevuta", "email.register": "Abbiamo ricevuto la richiesta di registrazione. La confermeremo quanto prima.\n Ciao", - "email.confirm": "Il tuo account su gancio è stato attivato e quindi puoi cominciare a pubblicare eventi", + "email.confirm": "Il tuo account su {{config.title}} è stato attivato e quindi puoi cominciare a pubblicare eventi", "email.recover.subject": "Recupero password", - "email.recover": "Ciao, hai richiesto un recupero della password su gancio.", + "email.recover": "Ciao, hai richiesto un recupero della password su {{config.title}}.", "email.press_here": "Premi qui", "email.confirm.subject": "Registrazione confermata", "email.user_confirm": "Ciao, il tuo account su {{config.title}} è stato creato. Confermalo." diff --git a/locales/it.js b/locales/it.js index d50c2a67..cc93d707 100644 --- a/locales/it.js +++ b/locales/it.js @@ -50,7 +50,7 @@ export default { me: 'Sei te', password_updated: 'Password modificata!', username: 'Nickname', - comments: 'Commenti' + comments: '|un commento|{n} commenti' }, login: { diff --git a/server/api/controller/event.js b/server/api/controller/event.js index cda38417..b52473df 100644 --- a/server/api/controller/event.js +++ b/server/api/controller/event.js @@ -5,6 +5,7 @@ const lodash = require('lodash') const { event: Event, comment: Comment, tag: Tag, place: Place, user: User, notification: Notification } = require('../models') const Sequelize = require('sequelize') const notifier = require('../../notifier') +const federation = require('../../federation/helpers') const eventController = { @@ -120,7 +121,8 @@ const eventController = { res.sendStatus(200) // send notification - notifier.notifyEvent(event.id) + //notifier.notifyEvent(event.id) + //federation.sendEvent(event, req.user) } catch (e) { res.sendStatus(404) } diff --git a/server/api/controller/fediverse.js b/server/api/controller/fediverse.js deleted file mode 100644 index c94c4816..00000000 --- a/server/api/controller/fediverse.js +++ /dev/null @@ -1,68 +0,0 @@ -// const fs = require('fs') -// const path = require('path') -// const moment = require('moment') -// const { event: Event, comment: Comment } = require('../models') -// const config = require('config') -// const settingsController = require('./settings') -// const get = require('lodash/get') - -// const botController = { -// bots: null, -// async initialize() { -// const access_token = get(settingsController.secretSettings, 'mastodon_auth.access_token') -// const instance = get(settingsController.settings, 'mastodon_instance') -// if (!access_token || !instance) return -// botController.bot = new Mastodon({ -// access_token, -// api_url: `https://${instance}/api/v1` -// }) -// const listener = botController.bot.stream('/streaming/user') -// listener.on('message', botController.message) -// listener.on('error', botController.error) -// }, -// async post(event) { -// const status = `${event.title} @${event.place.name} ${moment(event.start_datetime).format('ddd, D MMMM HH:mm')} - -// ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : event.description} - ${event.tags.map(t => '#' + t.tag).join(' ')} ${config.baseurl}/event/${event.id}` - -// let media -// if (event.image_path) { -// const file = path.resolve(config.upload_path, event.image_path) -// if (fs.statSync(file)) { -// media = await botController.bot.post('/media', { file: fs.createReadStream(file) }) -// } -// } -// return botController.bot.post('/statuses', { status, media_ids: media ? [media.data.id] : [] }) -// }, - -// async message(msg) { -// const type = msg.event - -// if (type === 'delete') { -// const activitypub_id = String(msg.data) -// const event = await Comment.findOne({ where: { activitypub_id } }) -// if (event) await event.destroy() -// return -// } - -// const activitypub_id = String(msg.data.status.in_reply_to_id) -// if (!activitypub_id) return -// let event = await Event.findOne({ where: { activitypub_id } }) -// if (!event) { -// // check for comment.. -// const comment = await Comment.findOne( { include: [Event], where: { activitypub_id }}) -// if (!comment) return -// event = comment.event -// } -// await Comment.create({ -// activitypub_id: String(msg.data.status.id), -// data: msg.data.status, -// eventId: event.id -// }) -// }, -// error(err) { -// console.log('error ', err) -// } -// } - -// setTimeout(botController.initialize, 5000) -// module.exports = botController diff --git a/server/api/index.js b/server/api/index.js index 8fdfcacf..7f132c5e 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -14,7 +14,7 @@ const settingsController = require('./controller/settings') const storage = require('./storage') const upload = multer({ storage }) -const api = express() +const api = express.Router() api.use(cookieParser()) api.use(bodyParser.urlencoded({ extended: false })) api.use(bodyParser.json()) @@ -100,15 +100,5 @@ api.get('/export/:type', exportController.export) // get events in this range api.get('/event/:month/:year', eventController.getAll) -// Handle 404 -api.use(function(req, res) { - res.status(404).send('404: Page not Found') -}) - -// Handle 500 -api.use(function(error, req, res, next) { - res.status(500).send('500: Internal Server Error') -}) - module.exports = api diff --git a/server/emails/confirm/html.pug b/server/emails/confirm/html.pug index 36a41773..091b2829 100644 --- a/server/emails/confirm/html.pug +++ b/server/emails/confirm/html.pug @@ -6,7 +6,7 @@ html(lang="en") meta(http-equiv="X-UA-Compatible", content="ie=edge") title #{config.title} body - p= t('email.confirm') + p= t('email.confirm', { config }) hr - #{config.title} - #{config.description} \ No newline at end of file + #{config.title} - #{config.description} diff --git a/server/emails/recover/html.pug b/server/emails/recover/html.pug index 86c3c7b6..d7b24e56 100644 --- a/server/emails/recover/html.pug +++ b/server/emails/recover/html.pug @@ -6,7 +6,7 @@ html(lang="en") meta(http-equiv="X-UA-Compatible", content="ie=edge") title #{config.title} body - p= t('email.recover') + p= t('email.recover', {config}) hr #{t('email.press_here')} diff --git a/server/federation/index.js b/server/federation/index.js index b092f333..9560694a 100644 --- a/server/federation/index.js +++ b/server/federation/index.js @@ -21,7 +21,6 @@ router.get('/m/:event_id', async (req, res) => { const event_id = req.params.event_id if (req.accepts('html')) return res.redirect(301, `/event/${event_id}`) - console.error('Not asked for html!') const event = await Event.findByPk(req.params.event_id, { include: [ User ] }) if (!event) return res.status(404).send('Not found') return res.json(event.toAP(event.user.username)) diff --git a/server/federation/users.js b/server/federation/users.js index fdd0d198..29f70c00 100644 --- a/server/federation/users.js +++ b/server/federation/users.js @@ -58,7 +58,6 @@ module.exports = { where: { username: name } }) - if (!user) return res.status(404).send(`No record found for ${name}`) console.error('Inside outbox, should return all events from this user') @@ -68,9 +67,7 @@ module.exports = { '@context': 'https://www.w3.org/ns/activitystreams', id: `${config.baseurl}/federation/u/${name}/outbox`, type: 'OrderedCollection', - // summary: `${user.username} outbox`, totalItems: user.events.length, - // orderedItems: user.events.map(e => e.toAP(user.username)) first: { id: `${config.baseurl}/federation/u/${name}/outbox?page=true`, type: 'OrderedCollectionPage', @@ -78,7 +75,6 @@ module.exports = { partOf: `${config.baseurl}/federation/u/${name}/outbox`, orderedItems: user.events.map(e => e.toAP(user.username)) } - // last: `${config.baseurl}/federation/u/${name}/outbox?page=true` } res.type('application/activity+json; charset=utf-8') return res.json(ret) diff --git a/server/federation/webfinger.js b/server/federation/webfinger.js index 7032822b..2a970bcb 100644 --- a/server/federation/webfinger.js +++ b/server/federation/webfinger.js @@ -94,6 +94,14 @@ router.get('/nodeinfo', async (req, res) => { }) +router.use('/host-meta', (req, res) => { + res.type('application/xml') + res.send(` + + +`) +}) + // Handle 404 router.use(function(req, res) { res.status(404).send('404: Page not Found') diff --git a/server/index.js b/server/index.js index 8105ee69..3ad41b7a 100644 --- a/server/index.js +++ b/server/index.js @@ -1,4 +1,3 @@ -//#!/bin/env node const { Nuxt, Builder } = require('nuxt') // Import and Set Nuxt.js options @@ -22,7 +21,9 @@ async function main() { // close connections/port/unix socket function shutdown() { - nuxt.close(() => { + nuxt.close(async () => { + const db = require('./api/models') + await db.sequelize.close() process.exit() }) } diff --git a/server/notifier.js b/server/notifier.js index 0bfe74d3..9cb8b554 100644 --- a/server/notifier.js +++ b/server/notifier.js @@ -1,5 +1,5 @@ const mail = require('./api/mail') -const bot = require('./api/controller/fediverse') +// const bot = require('./api/controller/fediverse') const settingsController = require('./api/controller/settings') const config = require('config') const eventController = require('./api/controller/event') @@ -17,17 +17,17 @@ const notifier = { return mail.send(notification.email, 'event', { event, config, notification }) case 'admin_email': return mail.send([config.smtp.auth.user, config.admin_email], 'event', { event, to_confirm: !event.is_visible, config, notification }) - case 'mastodon': - // instance publish - if (bot.bot) { - const b = bot.post(event).then(b => { - event.activitypub_id = String(b.data.id) - return event.save() - }).catch(e => { - console.error("ERROR !! ", e) - }) - promises.push(b) - } + // case 'mastodon': + // // instance publish + // if (bot.bot) { + // const b = bot.post(event).then(b => { + // event.activitypub_id = String(b.data.id) + // return event.save() + // }).catch(e => { + // console.error("ERROR !! ", e) + // }) + // promises.push(b) + // } } return Promise.all(promises) }, diff --git a/server/routes.js b/server/routes.js index 74a48fd0..9ee6e85b 100644 --- a/server/routes.js +++ b/server/routes.js @@ -4,6 +4,7 @@ const express = require('express') const api = require('./api') const federation = require('./federation') const webfinger = require('./federation/webfinger') +const debug = require('debug')('routes') const router = express.Router() router.use('/favicon.ico', express.static(path.resolve(config.favicon || 'assets/favicon.ico'))) @@ -14,4 +15,18 @@ router.use('/api', api) router.use('/.well-known', webfinger) router.use('/federation', federation) +// ignore unimplemented ping url from fediverse +router.use('/poco', (req, res) => res.status(404).send('404: Page not found')) + +// Handle 404 +// router.use((req, res) => res.status(404).send('404: Page not found')) + +// Handle 500 +router.use((error, req, res, next) => { + debug('Error 500: %s', error) + res.status(500).send('500: Internal Server Error') +}) + + + module.exports = router