From 5c640c22102c908593cdc286a43d3d54ce200d79 Mon Sep 17 00:00:00 2001 From: kukhariev Date: Mon, 18 Feb 2019 11:23:52 +0300 Subject: [PATCH] feat: allow keys in response --- server/index.js | 2 +- src/uploadx/src/uploader.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/index.js b/server/index.js index b1766f86..b05fbd18 100644 --- a/server/index.js +++ b/server/index.js @@ -149,7 +149,7 @@ app.use('/upload/', auth, (req, res, next) => { const location = `${req.protocol}://${req.hostname}:${PORT}/upload/${query}`; res.location(location); - res.sendStatus(200); + res.json(200, { location }); }); // ------------------------------ ERROR HANDLER ------------------------------ diff --git a/src/uploadx/src/uploader.ts b/src/uploadx/src/uploader.ts index 6ddb3970..48b795f5 100644 --- a/src/uploadx/src/uploader.ts +++ b/src/uploadx/src/uploader.ts @@ -254,11 +254,12 @@ function getRange(xhr: XMLHttpRequest) { const match = getKeyFromResponse(xhr, 'Range').match(/(-1|\d+)$/g); return 1 + +(match && match[0]); } - }; - this.status = 'error'; - XHRFactory.release(xhr); - this.options.nextFile(); - } + +function getKeyFromResponse(xhr: XMLHttpRequest, key: string) { + const fromHeader = xhr.getResponseHeader(key); + if (fromHeader) { + return fromHeader; + } }; const onDataSendSuccess = () => { if (xhr.status === 200 || xhr.status === 201) {