updated ws dependency and slightly improved client side error handling, hung uploads will error instead of hang forever
This commit is contained in:
parent
80fb42ad3d
commit
527040afef
8 changed files with 68 additions and 101 deletions
|
@ -3,7 +3,7 @@ const routes = require('../routes');
|
|||
const pages = require('../routes/pages');
|
||||
const tests = require('../../test/frontend/routes');
|
||||
const express = require('express');
|
||||
const expressWs = require('express-ws');
|
||||
const expressWs = require('@dannycoates/express-ws');
|
||||
const morgan = require('morgan');
|
||||
const config = require('../config');
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ const Raven = require('raven');
|
|||
const config = require('../config');
|
||||
const routes = require('../routes');
|
||||
const pages = require('../routes/pages');
|
||||
const expressWs = require('express-ws');
|
||||
const expressWs = require('@dannycoates/express-ws');
|
||||
|
||||
if (config.sentry_dsn) {
|
||||
Raven.config(config.sentry_dsn).install();
|
||||
|
|
|
@ -2,7 +2,7 @@ const assets = require('../../common/assets');
|
|||
const routes = require('../routes');
|
||||
const pages = require('../routes/pages');
|
||||
const tests = require('../../test/frontend/routes');
|
||||
const expressWs = require('express-ws');
|
||||
const expressWs = require('@dannycoates/express-ws');
|
||||
|
||||
module.exports = function(app, devServer) {
|
||||
assets.setMiddleware(devServer.middleware);
|
||||
|
|
|
@ -3,12 +3,11 @@ const storage = require('../storage');
|
|||
const config = require('../config');
|
||||
const mozlog = require('../log');
|
||||
const Limiter = require('../limiter');
|
||||
const wsStream = require('websocket-stream/stream');
|
||||
const fxa = require('../fxa');
|
||||
const { statUploadEvent } = require('../amplitude');
|
||||
const { encryptedSize } = require('../../app/utils');
|
||||
|
||||
const { Duplex } = require('stream');
|
||||
const { Transform } = require('stream');
|
||||
|
||||
const log = mozlog('send.upload');
|
||||
|
||||
|
@ -76,25 +75,19 @@ module.exports = function(ws, req) {
|
|||
})
|
||||
);
|
||||
const limiter = new Limiter(encryptedSize(maxFileSize));
|
||||
const flowControl = new Duplex({
|
||||
read() {
|
||||
ws.resume();
|
||||
},
|
||||
write(chunk, encoding, callback) {
|
||||
const eof = new Transform({
|
||||
transform: function(chunk, encoding, callback) {
|
||||
if (chunk.length === 1 && chunk[0] === 0) {
|
||||
this.push(null);
|
||||
} else {
|
||||
if (!this.push(chunk)) {
|
||||
ws.pause();
|
||||
}
|
||||
this.push(chunk);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
});
|
||||
const wsStream = ws.constructor.createWebSocketStream(ws);
|
||||
|
||||
fileStream = wsStream(ws, { binary: true })
|
||||
.pipe(flowControl)
|
||||
.pipe(limiter); // limiter needs to be the last in the chain
|
||||
fileStream = wsStream.pipe(eof).pipe(limiter); // limiter needs to be the last in the chain
|
||||
|
||||
await storage.set(newId, fileStream, meta, timeLimit);
|
||||
|
||||
|
@ -126,8 +119,8 @@ module.exports = function(ws, req) {
|
|||
error: e === 'limit' ? 413 : 500
|
||||
})
|
||||
);
|
||||
ws.close();
|
||||
}
|
||||
}
|
||||
ws.close();
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue