From 12ccce30169262c9e4e94b3a7c620f572fed0c2c Mon Sep 17 00:00:00 2001 From: Emily Hou Date: Thu, 21 Jun 2018 16:36:34 -0700 Subject: [PATCH] fix checking file early --- app/api.js | 5 ++--- app/fileManager.js | 2 +- server/routes/index.js | 4 ---- server/routes/ws.js | 6 +++--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/api.js b/app/api.js index 12f0f64f..876756ba 100644 --- a/app/api.js +++ b/app/api.js @@ -141,11 +141,11 @@ async function upload( let size = 0; while (!state.done) { const buf = state.value; - ws.send(buf); - if (canceller.cancelled) { + ws.close(4000, 'upload cancelled'); throw new Error(0); } + ws.send(buf); onprogress([Math.min(streamInfo.fileSize, size), streamInfo.fileSize]); size += streamInfo.recordSize; @@ -174,7 +174,6 @@ export async function uploadWs( return { cancel: function() { - ws.close(4000, 'upload cancelled'); canceller.cancelled = true; }, result: upload( diff --git a/app/fileManager.js b/app/fileManager.js index 786f99f8..e29a05e2 100644 --- a/app/fileManager.js +++ b/app/fileManager.js @@ -52,7 +52,7 @@ export default function(state, emitter) { checkFiles(); }); - emitter.on('navigate', checkFiles); + //emitter.on('navigate', checkFiles); emitter.on('render', () => { lastRender = Date.now(); diff --git a/server/routes/index.js b/server/routes/index.js index 65e98aa0..4b7d6f31 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -62,10 +62,6 @@ module.exports = function(app) { app.post(`/api/params/:id${ID_REGEX}`, owner, require('./params')); app.post(`/api/info/:id${ID_REGEX}`, owner, require('./info')); - if (!IS_DEV) { - app.ws('/api/ws', require('./ws')); - } - app.get('/__version__', function(req, res) { res.sendFile(require.resolve('../../dist/version.json')); }); diff --git a/server/routes/ws.js b/server/routes/ws.js index 4734daaa..c29757e1 100644 --- a/server/routes/ws.js +++ b/server/routes/ws.js @@ -44,13 +44,13 @@ module.exports = async function(ws, req) { nonce: crypto.randomBytes(16).toString('base64') }; + const protocol = config.env === 'production' ? 'https' : req.protocol; + const url = `${protocol}://${req.get('host')}/download/${newId}/`; + const limiter = new Limiter(config.max_file_size); fileStream = wsStream(ws, { binary: true }).pipe(limiter); storage.set(newId, fileStream, meta); - const protocol = config.env === 'production' ? 'https' : req.protocol; - const url = `${protocol}://${req.get('host')}/download/${newId}/`; - ws.send( JSON.stringify({ url,