Comparing version 0.3.0 to 0.4.4
{ | ||
"name": "fpark", | ||
"version": "0.3.0", | ||
"version": "0.4.4", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -23,8 +23,9 @@ # Fpark | ||
- [Node](#node) | ||
- [Systemd](#systemd) | ||
- [Usage](#usage) | ||
- [Configuration](#configuration) | ||
- [API](#api) | ||
- [GET /file/:container/:filename](#get-filecontainerfilename) | ||
- [PUT /file/:container/:filename](#put-filecontainerfilename) | ||
- [DELETE /file/:container/:filename](#delete-filecontainerfilename) | ||
- [GET /file/:filename/container/:container](#get-filefilenamecontainercontainer) | ||
- [PUT /file/:filename/container/:container](#put-filefilenamecontainercontainer) | ||
- [DELETE /file/:filename/container/:container](#delete-filefilenamecontainercontainer) | ||
- [POST /node/register](#post-noderegister) | ||
@@ -31,0 +32,0 @@ - [Token](#token) |
@@ -116,2 +116,3 @@ | ||
res.setHeader('Content-Encoding', 'gzip'); | ||
res.setHeader('Content-Disposition', 'inline; filename="' + params.id + '"'); | ||
@@ -118,0 +119,0 @@ getFile(store.CONFIG, req, res, params, queryParams, keyNodes, [zlib.createGzip()], () => { |
@@ -155,10 +155,34 @@ const fs = require('fs'); | ||
catch (e) { | ||
logger.error({ msg : 'Cannot put file', err : e.message }, { idKittenLogger : req.log_id }); | ||
return respond(res, 500); | ||
} | ||
let isWritePending = false; | ||
let isDone = false; | ||
function done () { | ||
if (isDone || isWritePending) { | ||
return; | ||
} | ||
isDone = true; | ||
req.unpipe(busboy); | ||
respond(...arguments); | ||
} | ||
busboy.on('file', (fieldname, fileStream, filename, encoding, mimetype) => { | ||
if (!filename) { | ||
return respond(res, 500); | ||
logger.error({ msg : 'Cannot put file: no filename' }, { idKittenLogger : req.log_id }); | ||
fileStream.resume(); | ||
return done(res, 500); | ||
} | ||
isWritePending = true; | ||
fileStream.on('error', err => { | ||
logger.error({ msg : 'Cannot put file', err : err.message }, { idKittenLogger : req.log_id }); | ||
isWritePending = false; | ||
return done(res, 500); | ||
}); | ||
/** | ||
@@ -169,3 +193,5 @@ * File size reached | ||
fileStream.on('limit', () => { | ||
return respond(res, 413); | ||
logger.warn({ msg : 'Cannot put file: limit reached' }, { idKittenLogger : req.log_id }); | ||
isWritePending = false; | ||
return done(res, 413); | ||
}); | ||
@@ -176,7 +202,9 @@ | ||
logger.warn({ msg : 'Cannot put file', err }, { idKittenLogger : req.log_id }); | ||
return respond(res, 500); | ||
isWritePending = false; | ||
return done(res, 500); | ||
} | ||
if (getHeaderFromNode(req.headers) && !req.headers['x-forwarded-for']) { | ||
return respond(res, 200); | ||
isWritePending = false; | ||
return done(res, 200); | ||
} | ||
@@ -211,3 +239,4 @@ | ||
respond(res, 200); | ||
isWritePending = false; | ||
done(res, 200); | ||
}).catch(() => { | ||
@@ -217,3 +246,4 @@ next(); | ||
}, () => { | ||
respond(res, nodes.length ? 500 : 200); | ||
isWritePending = false; | ||
done(res, nodes.length ? 500 : 200); | ||
}); | ||
@@ -223,9 +253,14 @@ }); | ||
busboy.on('error' , err => { | ||
logger.warn({ msg : 'Cannot put file', err }, { idKittenLogger : req.log_id }); | ||
respond(res, 500); | ||
busboy.on('error', err => { | ||
logger.error({ msg : 'Cannot put file', err : err.message }, { idKittenLogger : req.log_id }); | ||
isWritePending = false; | ||
done(res, 500); | ||
}); | ||
busboy.on('finish', () => { | ||
done(res, 200); | ||
}); | ||
req.pipe(busboy); | ||
}); | ||
} |
const fs = require('fs'); | ||
const path = require('path'); | ||
const { padlz } = require('./utils'); | ||
const encryption = require('../commons/encryption'); | ||
@@ -15,7 +14,13 @@ | ||
getFileName (filename, length) { | ||
if (filename.length < length) { | ||
return padlz(filename, length); | ||
let _bufferString = Buffer.from(filename); | ||
if (_bufferString.length >= length) { | ||
return _bufferString.slice(0, length).toString('ascii'); | ||
} | ||
return filename.substr(0, length); | ||
let _buffer = Buffer.alloc(length); | ||
_buffer.fill('0'); | ||
_bufferString.copy(_buffer, length - _bufferString.length); | ||
return _buffer.toString('ascii'); | ||
}, | ||
@@ -22,0 +27,0 @@ |
@@ -40,12 +40,2 @@ const fs = require('fs'); | ||
/** | ||
* Pad by zero a string to specified length | ||
* @param {String} n | ||
* @param {Int} length | ||
*/ | ||
padlz : function(n, length) { | ||
for (n+=""; n.length < length; n = "0" + n); | ||
return n; | ||
}, | ||
/** | ||
* Queue | ||
@@ -52,0 +42,0 @@ * @param {Array} items |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62071512
25
1324
216
7