Fix POST and PUT of tracks, parsing was not really done
This commit is contained in:
parent
72eb553ede
commit
454803a062
|
@ -181,24 +181,19 @@ router.post(
|
||||||
const track = new Track(body);
|
const track = new Track(body);
|
||||||
track.author = req.user;
|
track.author = req.user;
|
||||||
|
|
||||||
if (track.body) {
|
|
||||||
track.body = track.body.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (track.body) {
|
|
||||||
// delete existing
|
|
||||||
if (track.trackData) {
|
|
||||||
await TrackData.findByIdAndDelete(track.trackData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (body.visible != null) {
|
if (body.visible != null) {
|
||||||
track.visible = Boolean(body.visible);
|
track.visible = Boolean(body.visible);
|
||||||
} else {
|
} else {
|
||||||
track.visible = track.author.areTracksVisibleForAll;
|
track.visible = track.author.areTracksVisibleForAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (track.body) {
|
||||||
|
track.body = track.body.trim();
|
||||||
|
track.uploadedByUserAgent = normalizeUserAgent(req.headers['user-agent']);
|
||||||
|
await track.rebuildTrackDataAndSave();
|
||||||
|
} else {
|
||||||
await track.save();
|
await track.save();
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(track.author);
|
// console.log(track.author);
|
||||||
return res.json({ track: track.toJSONFor(req.user) });
|
return res.json({ track: track.toJSONFor(req.user) });
|
||||||
|
@ -311,19 +306,18 @@ router.put(
|
||||||
track.visible = Boolean(body.visible);
|
track.visible = Boolean(body.visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
let bodyChanged = false;
|
|
||||||
|
|
||||||
if (body.body && body.body.trim()) {
|
|
||||||
track.body = body.body.trim();
|
|
||||||
track.uploadedByUserAgent = normalizeUserAgent(req.headers['user-agent']);
|
|
||||||
bodyChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof body.tagList !== 'undefined') {
|
if (typeof body.tagList !== 'undefined') {
|
||||||
track.tagList = body.tagList;
|
track.tagList = body.tagList;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bodyChanged) {
|
if (body.body && body.body.trim()) {
|
||||||
|
// delete existing
|
||||||
|
if (track.trackData) {
|
||||||
|
await TrackData.findByIdAndDelete(track.trackData);
|
||||||
|
}
|
||||||
|
|
||||||
|
track.body = body.body.trim();
|
||||||
|
track.uploadedByUserAgent = normalizeUserAgent(req.headers['user-agent']);
|
||||||
await track.rebuildTrackDataAndSave();
|
await track.rebuildTrackDataAndSave();
|
||||||
} else {
|
} else {
|
||||||
await track.save();
|
await track.save();
|
||||||
|
|
Loading…
Reference in a new issue