From 9d72ff12b9844ca847ddd8844375fcdbf235f550 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 26 Jan 2017 23:11:42 +0900 Subject: [PATCH] [Server] Fix bug --- src/file/server.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/file/server.ts b/src/file/server.ts index 0f269c442..1831ef23b 100644 --- a/src/file/server.ts +++ b/src/file/server.ts @@ -93,9 +93,12 @@ function send(data: Buffer, type: string, req: express.Request, res: express.Res app.get('/:id', async (req, res): Promise => { const file = await File.findOne({_id: new mongodb.ObjectID(req.params.id)}); - if (file === null) { + if (file == null) { res.status(404).sendFile(__dirname + '/resources/dummy.png'); return; + } else if (file.data == null) { + res.status(400); + return; } send(file.data.buffer, file.type, req, res); @@ -104,9 +107,12 @@ app.get('/:id', async (req, res): Promise => { app.get('/:id/:name', async (req, res): Promise => { const file = await File.findOne({_id: new mongodb.ObjectID(req.params.id)}); - if (file === null) { + if (file == null) { res.status(404).sendFile(__dirname + '/resources/dummy.png'); return; + } else if (file.data == null) { + res.status(400); + return; } send(file.data.buffer, file.type, req, res);