feat: remove deprecated /begin /add /end interface for writing tracks

This commit is contained in:
Paul Bienkowski 2020-12-13 13:03:04 +01:00 committed by uwewoessner
parent 4d30d6ff1b
commit e956f78b2b

View file

@ -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',