fixed issues in branch title

This commit is contained in:
Abhinav Adduri 2017-07-11 11:18:31 -07:00
parent 109fd671e0
commit 6231385c74
3 changed files with 30 additions and 1 deletions

View File

@ -12,7 +12,7 @@ class FileReceiver extends EventEmitter {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.onprogress = event => { xhr.onprogress = event => {
if (event.lengthComputable) { if (event.lengthComputable && event.target.status !== 404) {
const percentComplete = Math.floor( const percentComplete = Math.floor(
event.loaded / event.total * 100 event.loaded / event.total * 100
); );

View File

@ -45,6 +45,11 @@ app.get('/', (req, res) => {
app.get('/exists/:id', (req, res) => { app.get('/exists/:id', (req, res) => {
const id = req.params.id; const id = req.params.id;
if (!validateID(id)) {
res.sendStatus(404);
return;
}
storage storage
.exists(id) .exists(id)
.then(() => { .then(() => {
@ -55,6 +60,11 @@ app.get('/exists/:id', (req, res) => {
app.get('/download/:id', (req, res) => { app.get('/download/:id', (req, res) => {
const id = req.params.id; const id = req.params.id;
if (!validateID(id)) {
res.sendStatus(404);
return;
}
storage.filename(id).then(filename => { storage.filename(id).then(filename => {
storage storage
.length(id) .length(id)
@ -101,10 +111,14 @@ app.get('/assets/download/:id', (req, res) => {
}) })
.catch(err => { .catch(err => {
log.info('DeleteError:', id); log.info('DeleteError:', id);
res.sendStatus(404);
}); });
}); });
file_stream.pipe(res); file_stream.pipe(res);
})
.catch(err => {
res.sendStatus(404);
}); });
}) })
.catch(err => { .catch(err => {
@ -124,6 +138,7 @@ app.post('/delete/:id', (req, res) => {
if (!delete_token) { if (!delete_token) {
res.sendStatus(404); res.sendStatus(404);
return;
} }
storage storage
@ -140,6 +155,12 @@ app.post('/delete/:id', (req, res) => {
app.post('/upload', (req, res, next) => { app.post('/upload', (req, res, next) => {
const newId = crypto.randomBytes(5).toString('hex'); const newId = crypto.randomBytes(5).toString('hex');
const meta = JSON.parse(req.header('X-File-Metadata')); const meta = JSON.parse(req.header('X-File-Metadata'));
if (!validateIV(meta.id)) {
res.sendStatus(404);
return;
}
meta.delete = crypto.randomBytes(10).toString('hex'); meta.delete = crypto.randomBytes(10).toString('hex');
log.info('meta', meta); log.info('meta', meta);
req.pipe(req.busboy); req.pipe(req.busboy);
@ -178,3 +199,7 @@ app.listen(conf.listen_port, () => {
const validateID = route_id => { const validateID = route_id => {
return route_id.match(/^[0-9a-fA-F]{10}$/) !== null; return route_id.match(/^[0-9a-fA-F]{10}$/) !== null;
}; };
const validateIV = route_id => {
return route_id.match(/^[0-9a-fA-F]{24}$/) !== null;
};

View File

@ -25,7 +25,11 @@
<div> <div>
<button id="download-btn" onclick="download()">Download File</button> <button id="download-btn" onclick="download()">Download File</button>
</div> </div>
<div id='expired-img'>
<img src='/resources/link_expired.png' />
</div> </div>
</div>
<div id="download-progress"> <div id="download-progress">
<div id="download-text"> <div id="download-text">