From e956f78b2b433d3075494cbc048b70c2a4d9ff6d Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Sun, 13 Dec 2020 13:03:04 +0100 Subject: [PATCH] feat: remove deprecated /begin /add /end interface for writing tracks --- src/routes/api/tracks.js | 68 ---------------------------------------- 1 file changed, 68 deletions(-) diff --git a/src/routes/api/tracks.js b/src/routes/api/tracks.js index 4e9b765..46b3cc8 100644 --- a/src/routes/api/tracks.js +++ b/src/routes/api/tracks.js @@ -6,7 +6,6 @@ const Comment = mongoose.model('Comment'); const User = mongoose.model('User'); const busboy = require('connect-busboy'); const auth = require('../auth'); -const currentTracks = new Map(); const { normalizeUserAgent } = require('../../logic/tracks'); const wrapRoute = require('../../_helpers/wrapRoute'); @@ -200,73 +199,6 @@ router.post( }), ); -router.post( - '/begin', - auth.required, - wrapRoute(async (req, res) => { - const track = new Track(req.body.track); - track.author = req.user; - track.uploadedByUserAgent = normalizeUserAgent(req.headers['user-agent']); - - await track.save(); - - // remember which is the actively building track for this user - currentTracks.set(req.user.id, track._id); - - return res.sendStatus(200); - }), -); - -router.post( - '/add', - auth.required, - wrapRoute(async (req, res) => { - if (!currentTracks.has(req.user.id)) { - throw new Error('current user has no active track, start one with POST to /tracks/begin'); - } - - const trackId = currentTracks.get(req.user.id); - - const track = await Track.findById(trackId); - if (!track) { - throw new Error('current user active track is gone, retry upload'); - } - - track.body += req.body.track.body; - await track.save(); - - return res.sendStatus(200); - }), -); - -router.post( - '/end', - auth.required, - wrapRoute(async (req, res) => { - let track; - - if (currentTracks.has(req.user.id)) { - // the file is less than 100 lines - const trackId = currentTracks.get(req.user.id); - track = await Track.findById(trackId); - if (!track) { - throw new Error('current user active track is gone, retry upload'); - } - - track.body += req.body.track.body; - } else { - track = new Track(req.body.track); - } - - await track.rebuildTrackDataAndSave(); - - // We are done with this track, it is complete. - currentTracks.delete(req.user.id); - - return res.sendStatus(200); - }), -); - // return a track router.get( '/:track',