-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add code for storing info about drawing submissions * shuffle functions around so handleDrawingSubmission isn't redefined all the time * filter out non-image submissions * remove a console.log statement
- Loading branch information
1 parent
410c60e
commit 90f110b
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require("fs"); | ||
const { promisify } = require("util"); | ||
|
||
async function addImageToList(drawingInfo) { | ||
// throws error if file doesn't exist | ||
const drawingsListJson = await promisify(fs.readFile)( | ||
"./drawings.json", | ||
"utf-8" | ||
); | ||
|
||
// throws error if file is blank | ||
let drawingsList = JSON.parse(drawingsListJson); | ||
|
||
// just in case drawings.json has some other type at the root of structure | ||
if (!Array.isArray(drawingsList)) { | ||
drawingsList = []; | ||
} | ||
|
||
drawingsList.push(drawingInfo); | ||
|
||
const newJson = JSON.stringify(drawingsList, null, 2); | ||
|
||
return promisify(fs.writeFile)("./drawings.json", newJson); | ||
} | ||
|
||
module.exports = { | ||
addImageToList | ||
}; |
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