|
|
@ -1,5 +1,6 @@ |
|
|
|
module.exports = (app, router) => { |
|
|
|
module.exports = (app, router) => { |
|
|
|
const Anime = app.db.models.ani.series; |
|
|
|
const Anime = app.db.models.ani.series; |
|
|
|
|
|
|
|
//TODO solution for all endpoints to resolve by numerical ID
|
|
|
|
|
|
|
|
|
|
|
|
const editCheck = (series, req, res) => { |
|
|
|
const editCheck = (series, req, res) => { |
|
|
|
if (!series) {res.status(400).send("A series with that ID doesn't exist!"); return 0;} |
|
|
|
if (!series) {res.status(400).send("A series with that ID doesn't exist!"); return 0;} |
|
|
@ -19,7 +20,7 @@ module.exports = (app, router) => { |
|
|
|
series.markModified('meta.edits'); |
|
|
|
series.markModified('meta.edits'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const edits = app.util.editString('/:id', pushEdit, editCheck, router, Anime); |
|
|
|
const edits = app.util.editString('/:id', pushEdit, editCheck, router, Anime, 'series-approve'); |
|
|
|
|
|
|
|
|
|
|
|
router.route('/:id/synopsis') //completed i think?
|
|
|
|
router.route('/:id/synopsis') //completed i think?
|
|
|
|
.patch(app.auth.token, app.auth.perms('series-submit'), async (req, res, next) => { |
|
|
|
.patch(app.auth.token, app.auth.perms('series-submit'), async (req, res, next) => { |
|
|
@ -46,38 +47,41 @@ module.exports = (app, router) => { |
|
|
|
return res.send({synopsis: series.synopsis.synopsis, by: series.synopsis.by}); |
|
|
|
return res.send({synopsis: series.synopsis.synopsis, by: series.synopsis.by}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
[ |
|
|
|
[ //?SINGLE STRING FIELDS
|
|
|
|
['name', x => x.match(/^[\w\-!?.:; ]+$/gm) && x.length < 150], |
|
|
|
['name', x => x.match(/^[\w\-!?.:; ]+$/gm) && x.length < 150], |
|
|
|
['romaji', x => x.length < 150], |
|
|
|
['romaji', x => x.length < 150], |
|
|
|
['kanji', x => x.length < 150], |
|
|
|
['kanji', x => x.length < 150], |
|
|
|
['official-site', x => x.length] |
|
|
|
['official-site', x => x.length < 150] |
|
|
|
|
|
|
|
|
|
|
|
].forEach(field => edits.stringWrap(...field)); |
|
|
|
].forEach(field => edits.stringWrap(...field)); |
|
|
|
|
|
|
|
|
|
|
|
const editStringList = async (name, match) => { |
|
|
|
const editStringList = async (name, bodyName, match) => { |
|
|
|
|
|
|
|
const camelName = app.util.bodyCase(name); |
|
|
|
router.use(`/:id/${name}`, app.auth.tokenPass, app.auth.permsPass('series-approve'), async (req, res, next) => { |
|
|
|
router.use(`/:id/${name}`, app.auth.tokenPass, app.auth.permsPass('series-approve'), async (req, res, next) => { |
|
|
|
if (!req.params.id) {return res.status(400).send("Missing ID!");} |
|
|
|
if (!req.params.id) {return await res.status(400).send("Missing ID!");} |
|
|
|
const series = await Anime.findOne({id: req.params.id.toLowerCase()}); |
|
|
|
const series = await Anime.findOne({id: req.params.id.toLowerCase()}); |
|
|
|
if (!editCheck(series, req, res)) {return;} |
|
|
|
if (!editCheck(series, req, res)) {return;} |
|
|
|
req.series = series; |
|
|
|
req.series = series; |
|
|
|
req.listData = req.user.permissions; |
|
|
|
req.listData = series[camelName]; |
|
|
|
next(); |
|
|
|
next(); |
|
|
|
}, app.util.list(router, `/:id/${name}`, true, name, async (req, res, permissions, permission) => { |
|
|
|
}, app.util.list(router, `/:id/${name}`, true, bodyName, async (req, res, list, item) => { |
|
|
|
if (permission && (!permission.match(/^[\w-]+$/gm) || permission.length > 15)) {res.status(400).send("The permission you provided is invalid."); return 0;} |
|
|
|
if (item && !match(item)) {res.status(400).send(`The ${camelName} you provided is invalid.`); return 0;} |
|
|
|
if (permission) {permissions[permissions.length - 1] = permission.toLowerCase();} |
|
|
|
if (item) {list[list.length - 1] = item;} |
|
|
|
req.user.permissions = permissions; |
|
|
|
req.series[camelName] = list; |
|
|
|
req.user.markModified('permissions'); |
|
|
|
req.series.markModified(camelName); |
|
|
|
await req.user.save(); |
|
|
|
await req.series.save(); |
|
|
|
}, (req, res, next) => { |
|
|
|
}, (req, res, next) => { |
|
|
|
if (!req.authenticatedUser) {return res.status(401).send("You must be authenticated before you do that!");} |
|
|
|
if (!req.authenticatedUser) {return res.status(401).send("You must be authenticated before you do that!");} |
|
|
|
if (req.unauthorized) {return res.status(401).send("You are not authorized to edit users!");} |
|
|
|
if (req.unauthorized) {return res.status(401).send("You are not authorized to edit that!");} |
|
|
|
return next(); |
|
|
|
return next(); |
|
|
|
})); |
|
|
|
})); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
[ |
|
|
|
[ //?STRING LIST FIELDS
|
|
|
|
['tags', x => x.match()] |
|
|
|
['tags', 'tag', x => x.match(/^[a-z-]+$/) && x.length < 25], //TODO set list length limits
|
|
|
|
] |
|
|
|
['genres', 'genre', x => x.match(/^[a-zA-Z- ]+$/) && x.length < 25], |
|
|
|
|
|
|
|
['stream-at', 'location', x => x.match(/^[\w- ]+$/) && x.length < 40] //TODO doc cheeky field
|
|
|
|
|
|
|
|
].forEach(x => editStringList(...x)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|