-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
game of thrones quotes #77
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0cbe75e
game of thrones quotes
HritvikBhatia 6f4eacd
Merge branch 'master' into GOT-quotes
HritvikBhatia c5c43d9
resolved conflict and error
HritvikBhatia aaba4bf
Merge branch 'master' into GOT-quotes
akanshSirohi 020265b
modified readme
HritvikBhatia a917ad6
Merge branch 'GOT-quotes' of https://github.com/HritvikBhatia/Github-…
HritvikBhatia cee2967
conflict fix
HritvikBhatia 767f381
conflict fix
HritvikBhatia 7d8fdb3
Update README.md
akanshSirohi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,47 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const fs = require("fs").promises; | ||
|
||
const {generateCard, CARD_AGE, Languages} = require("../card-generator"); | ||
const { parseOptions } = require("../options-parser"); | ||
|
||
const DATA_FILE_PATH = "./src/data/got-quotes.json"; | ||
const DEFAULT_THEME = "dark_2"; | ||
|
||
const handleTheme = (req, res, next) => { | ||
req.theme = req.query.theme || DEFAULT_THEME; | ||
next(); | ||
}; | ||
|
||
const handleOptions = (req, res, next) => { | ||
if (req.theme === "custom") { | ||
req.options = parseOptions(req.query); | ||
} | ||
next(); | ||
}; | ||
|
||
router.get("/", handleTheme, handleOptions, async (req, res) => { | ||
try { | ||
const gotquotes = JSON.parse(await fs.readFile(DATA_FILE_PATH, "utf8")); | ||
const random_quotes = gotquotes[Math.floor(Math.random() * gotquotes.length)]; | ||
|
||
const quotes_content = `${random_quotes.sentence}\n\n- ${random_quotes.character}`; | ||
const got_card = await generateCard( | ||
quotes_content, | ||
req.theme, | ||
req.options, | ||
Languages.ENGLISH | ||
); | ||
|
||
res.writeHead(200, { | ||
"Content-Type": "image/svg+xml", | ||
"Cache-Control": `public, max-age=${CARD_AGE}`, | ||
}); | ||
res.end(got_card); | ||
} catch (error) { | ||
console.error("Error:", error); | ||
res.status(500).send("Internal Server Error"); | ||
} | ||
}); | ||
|
||
module.exports = router; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HritvikBhatia Check the line 67, you have added some extra text ":wq" looks like you were trying to use vim. I have fixed it but please check your PR from next time properly.