소스 검색

Fix bug using wrong variable, send 404 if no picture for user

sbkwgh 7 년 전
부모
커밋
93f11354b9
1개의 변경된 파일14개의 추가작업 그리고 9개의 파일을 삭제
  1. 14 9
      routes/user.js

+ 14 - 9
routes/user.js

@@ -190,18 +190,23 @@ router.get('/:username/picture', async (req, res) => {
 			}
 		})
 
-		res.writeHead(200, {
-			'Content-Type': picture.mimetype,
-			'Content-disposition': 'attachment;filename=profile',
-			'Content-Length': picture.file.length
-		});
-		res.end(new Buffer(picture.file, 'binary'));
+		if(!picture) {
+			res.status(404)
+			res.end('')
+		} else {
+			res.writeHead(200, {
+				'Content-Type': picture.mimetype,
+				'Content-disposition': 'attachment;filename=profile',
+				'Content-Length': picture.file.length
+			})
+			res.end(new Buffer(picture.file, 'binary'))
+		}
 	} catch (e) {
-		if(err === Errors.accountDoesNotExist) {
+		if(e === Errors.accountDoesNotExist) {
 			res.status(400)
-			res.json({ errors: [err] })
+			res.json({ errors: [e] })
 		} else {
-			console.log(err)
+			console.log(e)
 			res.status(500)
 			res.json({
 				errors: [Errors.unknown]