From cd26aaa86ec58b6480c8a5efb017622fdc945b52 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Tue, 18 Jul 2023 21:37:27 +0200 Subject: [PATCH] fix: use better already-exist check in note creation Signed-off-by: Tilman Vatteroth --- lib/web/note/util.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/web/note/util.js b/lib/web/note/util.js index 732152287..6604ea35a 100644 --- a/lib/web/note/util.js +++ b/lib/web/note/util.js @@ -60,17 +60,23 @@ exports.newNote = async function (req, res, body) { } else { return req.method === 'POST' ? errors.errorForbidden(res) : errors.errorNotFound(res) } + try { - const count = await models.Note.count({ - where: { - alias: req.alias - } + const id = await new Promise((resolve, reject) => { + models.Note.parseNoteId(noteId, (err, id) => { + if (err) { + reject(err) + } else { + resolve(id) + } + }) }) - if (count > 0) { + + if (id) { return errors.errorConflict(res) } - } catch (err) { - logger.error('Error while checking for possible duplicate: ' + err) + } catch (error) { + logger.error(error) return errors.errorInternalError(res) } }