diff options
-rwxr-xr-x | index.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/index.js b/index.js index 53426f5..ef79d57 100755 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const readFile = util.promisify(fs.readFile) // General page size. const limit = 20 -const page = async (request, response, text) => { +const page = async (request, response, text, title = 'Scratch') => { const cookies = parseCookies(request) const notificationCount = await getMessageCount(cookies.username) @@ -22,7 +22,7 @@ const page = async (request, response, text) => { <html> <head> <meta charset="utf-8"> - <title>Scratch</title> + <title>${filterHTML(title)}</title> <link rel="stylesheet" href="/style.css"> </head> <body> @@ -264,7 +264,7 @@ const handleRequest = async (request, response) => { <p><label>CSRF Token: <input type="password" name="csrftoken"></label></p> <p><button>Login</button></p> </form> - `) + `, 'Login') } else if (request.method === 'POST') { const { username, token, sessionid, csrftoken } = await getData(request) @@ -279,7 +279,7 @@ const handleRequest = async (request, response) => { return page(request, response, fixWS` <p>Okay, you're logged in.</p> - `) + `, 'Logged In') } } @@ -291,7 +291,7 @@ const handleRequest = async (request, response) => { <p>Are you sure you want to log out?</p> <p><button>Log out</button></p> </form> - `) + `, 'Log Out') } else if (request.method === 'POST') { const { username, token, sessionid, csrftoken } = await getData(request) @@ -302,7 +302,7 @@ const handleRequest = async (request, response) => { return page(request, response, fixWS` <p>Okay, you've been logged out.</p> - `) + `, 'Logged Out') } } @@ -310,7 +310,7 @@ const handleRequest = async (request, response) => { if (!cookie.username) { return page(request, response, fixWS` <p>Sorry, you can't view your notifications until you've <a href="/login">logged in</a>.</p> - `) + `, 'Notifications') } const notifications = await getNotifications(cookie.username, cookie.token, pageNumber) @@ -345,7 +345,7 @@ const handleRequest = async (request, response) => { <p>You are on page ${pageNumber}. ${notifications.length === limit && `<a href="/notifications?page=${pageNumber + 1}">Next</a>`} ${pageNumber > 1 && `<a href="/notifications?page=${pageNumber - 1}">Previous</a>`}</p> - `) + `, 'Notifications') } if (compareArr(urlParts, ['notifications', 'mark-as-read'])) { @@ -370,7 +370,7 @@ const handleRequest = async (request, response) => { response.statusCode = 404 return page(request, response, fixWS` 404. Sorry, that project either doesn't exist or isn't shared. - `) + `, 'Project Not Found') } if (urlParts.length === 2) { @@ -388,7 +388,7 @@ const handleRequest = async (request, response) => { const remixesText = remixes.map(templates.projectThumbnail).join('\n') return page(request, response, fixWS` - <h1>${project.title}</h1> + <h1>${filterHTML(project.title)}</h1> <p>Created by ${templates.user(project.author.username)}.${parentProjectText}</p> <p><img src="${project.image}" alt="The thumbnail for this project"></p> ${project.instructions ? fixWS` @@ -412,12 +412,12 @@ const handleRequest = async (request, response) => { </ul> <p><a href="/projects/${project.id}/remixes">See all!</a></p> ` : ''} - `) + `, project.title) } else if (compareArr(urlParts.slice(2), ['remixes'])) { return page(request, response, fixWS` <h1>Remixes of ${filterHTML(project.title)}</h1> ${await templates.projectList(`https://api.scratch.mit.edu/projects/${projectID}/remixes`, pathname, pageNumber)} - `) + `, `Remixes of ${project.title}`) } } @@ -429,7 +429,7 @@ const handleRequest = async (request, response) => { response.statusCode = 404 return page(request, response, fixWS` 404. Sorry, that user doesn't exist. - `) + `, 'User Not Found') } if (urlParts.length === 2) { @@ -455,12 +455,12 @@ const handleRequest = async (request, response) => { ${projectsText} </ul> <p><a href="/users/${username}/projects">See all!</a></p> - `) + `, user.username) } else if (compareArr(urlParts.slice(2), ['projects'])) { return page(request, response, fixWS` - <h1>${user.username}'s projects</h1> + <h1>Projects by ${user.username}</h1> ${await templates.projectList(`https://api.scratch.mit.edu/users/${username}/projects`, pathname, pageNumber)} - `) + `, `Projects by ${user.username}`) } } @@ -477,13 +477,13 @@ const handleRequest = async (request, response) => { if (urlParts.length === 0) { return page(request, response, fixWS` You are at the homepage. Sorry, I haven't implmented any content for it yet. - `) + `, 'Scratch Homepage') } response.statusCode = 404 return page(request, response, fixWS` 404. Sorry, I'm not sure where you are right now. - `) + `, 'Page Not Found') } const server = http.createServer((request, response) => { @@ -492,7 +492,7 @@ const server = http.createServer((request, response) => { response.statusCode = 500 return page(request, response, fixWS` 500. Sorry, there was an internal server error. - `) + `, 'Internal Server Error') }) }) |