integrate with new ui

This commit is contained in:
Emily 2018-08-08 11:07:09 -07:00
parent 13057804ab
commit bf16e5c8a9
27 changed files with 250 additions and 315 deletions

View file

@ -13,7 +13,8 @@ module.exports = async function(req, res) {
'Content-Length': contentLength,
'WWW-Authenticate': `send-v1 ${req.nonce}`
});
const file_stream = storage.get(id);
const file_stream = await storage.get(id);
let cancelled = false;
req.on('close', () => {

View file

@ -35,7 +35,7 @@ if (isIE && !isUnsupportedPage) {
window.location.replace('/unsupported/ie');
}
var MAXFILESIZE = ${config.max_file_size};
var EXPIRE_SECONDS = ${config.expire_seconds};
var DEFAULT_EXPIRE_SECONDS = ${config.default_expire_seconds};
${ga}
${sentry}
`;

View file

@ -24,7 +24,9 @@ module.exports = async function(req, res) {
try {
const limiter = new Limiter(config.max_file_size);
const fileStream = req.pipe(limiter);
await storage.set(newId, fileStream, meta);
//this hasn't been updated to expiration time setting yet
//if you want to fallback to this code add this
await storage.set(newId, fileStream, meta, config.default_expire_seconds);
const protocol = config.env === 'production' ? 'https' : req.protocol;
const url = `${protocol}://${req.get('host')}/download/${newId}/`;
res.set('WWW-Authenticate', `send-v1 ${meta.nonce}`);

View file

@ -23,10 +23,16 @@ module.exports = async function(ws, req) {
const owner = crypto.randomBytes(10).toString('hex');
const fileInfo = JSON.parse(message);
const timeLimit = fileInfo.timeLimit;
const metadata = fileInfo.fileMetadata;
const auth = fileInfo.authorization;
if (!metadata || !auth) {
if (
!metadata ||
!auth ||
timeLimit <= 0 ||
timeLimit > config.max_expire_seconds
) {
ws.send(
JSON.stringify({
error: 400
@ -50,7 +56,7 @@ module.exports = async function(ws, req) {
fileStream = wsStream(ws, { binary: true })
.pipe(limiter)
.pipe(parser);
await storage.set(newId, fileStream, meta);
await storage.set(newId, fileStream, meta, timeLimit);
if (ws.readyState === 1) {
// if the socket is closed by a cancelled upload the stream