Created
December 12, 2021 20:33
-
-
Save corupta/1fcead044b7078b83a85f98fa32c0e50 to your computer and use it in GitHub Desktop.
wander-api-after-hackathon.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/helpers/similarityCheck.js b/src/helpers/similarityCheck.js | |
index 1e4063a..7430e3a 100644 | |
--- a/src/helpers/similarityCheck.js | |
+++ b/src/helpers/similarityCheck.js | |
@@ -53,12 +53,12 @@ const similarityCheck = async (points, spell) => { | |
ctx.lineWidth = LINE_SIZE-4; | |
ctx.strokeStyle='#0c3240'; | |
ctx.stroke(); | |
- const buff = canvas.toBuffer('image/png', { compressionLevel: 3, filters: canvas.PNG_FILTER_NONE }) | |
+ const buffer = canvas.toBuffer('image/png', { compressionLevel: 3, filters: canvas.PNG_FILTER_NONE }) | |
const spellPath = path.join(baseSpellDir, spell.image.split('/').reverse()[0]); | |
const spellImg = await Jimp.read(spellPath); | |
- const drawnImg = await Jimp.read(buff); | |
+ const drawnImg = await Jimp.read(buffer); | |
// await drawnImg.writeAsync('lumossss.png'); | |
const distance = Jimp.distance(spellImg, drawnImg); | |
diff --git a/src/services/spell-check/spell-check.class.js b/src/services/spell-check/spell-check.class.js | |
index fa424fc..a933064 100644 | |
--- a/src/services/spell-check/spell-check.class.js | |
+++ b/src/services/spell-check/spell-check.class.js | |
@@ -29,6 +29,7 @@ exports.SpellCheck = class SpellCheck { | |
} | |
const spellService = this.options.app.service('spells'); | |
const spell = await spellService.Model.findById(spellId).lean(); | |
+ const userService = this.options.app.service('users'); | |
if (!spell) { | |
throw new Error('No such spell') | |
} | |
@@ -41,15 +42,16 @@ exports.SpellCheck = class SpellCheck { | |
if (isSimilar) { | |
if (currentLevel === spell.requiredLevel) { | |
levelUp = true; | |
- ctx.user.level += 1; | |
- await ctx.user.save(); | |
+ ctx.user = await userService.Model.findOneAndUpdate({ _id: ctx.user._id }, { level: ctx.user.level+1 }, { new: true }).lean(); | |
} | |
} | |
return { | |
- isSimilar, | |
- levelUp, | |
- user: ctx.user, | |
- drawnImage: buffer.toString('base64') | |
+ data: { | |
+ isSimilar, | |
+ levelUp, | |
+ user: ctx.user, | |
+ drawnImage: "data:image/png;base64," + buffer.toString('base64') | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment