diff options
author | Raphael <raphaelkabo@gmail.com> | 2020-06-13 12:59:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-13 12:59:42 +0100 |
commit | 030e2b3575a856c6fae65848b82626dde888a8c8 (patch) | |
tree | 963307a87e9f49a7956eed105ebafaf67aed5071 /routes.js | |
parent | 2ae20b09e6369202b4235b7fced87cc0daf6dff5 (diff) | |
parent | 335103a7f94e94f05b656e0193a30e12790a8d38 (diff) |
Merge pull request #48 from lowercasename/nanoid
Nanoid
Diffstat (limited to 'routes.js')
-rwxr-xr-x | routes.js | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -4,7 +4,10 @@ const express = require('express'); const mongoose = require('mongoose'); -const shortid = require('shortid'); +// This alphabet (used to generate all event, group, etc. IDs) is missing '-' +// because ActivityPub doesn't like it in IDs +const { customAlphabet } = require('nanoid'); +const nanoid = customAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_', 21); const randomstring = require("randomstring"); @@ -623,12 +626,8 @@ router.get('/exportevent/:eventID', (req, res) => { // failureFlash: true }) //); - router.post('/newevent', async (req, res) => { - let eventID = shortid.generate(); - // this is a hack, activitypub does not like "-" in ids so we are essentially going - // to have a 63-character alphabet instead of a 64-character one - eventID = eventID.replace(/-/g,'_'); + let eventID = nanoid(); let editToken = randomstring.generate(); let eventImageFilename = ""; let isPartOfEventGroup = false; @@ -717,7 +716,7 @@ router.post('/newevent', async (req, res) => { }); router.post('/importevent', (req, res) => { - let eventID = shortid.generate(); + let eventID = nanoid(); let editToken = randomstring.generate(); if (req.files && Object.keys(req.files).length !== 0) { let iCalObject = ical.parseICS(req.files.icsImportControl.data.toString('utf8')); @@ -788,7 +787,7 @@ router.post('/importevent', (req, res) => { }); router.post('/neweventgroup', (req, res) => { - let eventGroupID = shortid.generate(); + let eventGroupID = nanoid(); let editToken = randomstring.generate(); let eventGroupImageFilename = ""; if (req.files && Object.keys(req.files).length !== 0) { @@ -1395,7 +1394,7 @@ router.post('/removeattendee/:eventID/:attendeeID', (req, res) => { }); router.post('/post/comment/:eventID', (req, res) => { - let commentID = shortid.generate(); + let commentID = nanoid(); const newComment = { id: commentID, author: req.body.commentAuthor, @@ -1459,7 +1458,7 @@ router.post('/post/comment/:eventID', (req, res) => { }); router.post('/post/reply/:eventID/:commentID', (req, res) => { - let replyID = shortid.generate(); + let replyID = nanoid(); let commentID = req.params.commentID; const newReply = { id: replyID, |