Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

impress

Package Overview
Dependencies
Maintainers
4
Versions
719
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

impress - npm Package Compare versions

Comparing version 2.0.0-alpha.34 to 2.0.0-alpha.35

CHANGELOG.md

22

lib/dependencies.js

@@ -5,3 +5,3 @@ 'use strict';

const npm = {};
const metarhia = { common: require('@metarhia/common') };
const metarhia = {};

@@ -15,3 +15,8 @@ const system = ['util', 'child_process', 'worker_threads', 'os', 'v8', 'vm'];

const metapkg = ['metavm', 'metacom', 'metatests', 'metaschema', 'metasql'];
const ORG_LENGTH = '@metarhia'.length;
const metalibs = ['@metarhia/common', '@metarhia/config'];
const metacore = ['metavm', 'metacom', 'metaschema', 'metasql'];
const metatools = ['metatests', 'metalog'];
const metapkg = [...metalibs, ...metacore, ...metatools];
const npmpkg = ['ws'];

@@ -25,5 +30,12 @@ const pkg = require(process.cwd() + '/package.json');

const lib = require(name);
if (internals.includes(name)) node[name] = lib;
else if (metapkg.includes(name)) metarhia[name] = lib;
else npm[name] = lib;
if (internals.includes(name)) {
node[name] = lib;
continue;
}
if (metapkg.includes(name)) {
const key = name.startsWith('@') ? name.substring(ORG_LENGTH) : name;
metarhia[key] = lib;
continue;
}
npm[name] = lib;
}

@@ -30,0 +42,0 @@

'use strict';
const { node, metarhia } = require('./dependencies.js');
const { fs, path, crypto, zlib, zipStream } = node;
const { fs, fsp, path, crypto, util } = node;
const { common } = metarhia;
const application = require('./application.js');
const UPLOAD_SIZE_ZIP = 1048576;
const mkdirp = util.promisify(common.nkdirp);
const COMPRESSED_EXT = [
'gif',
'jpg',
'jpe',
'jpeg',
'png',
'svgz',
'docx',
'xlsx',
'pptx',
'dotx',
'odm',
'odt',
'ott',
'odp',
'otp',
'djvu',
'djv',
'zip',
'rar',
'z7',
'gz',
'jar',
'arj',
'iso',
'nrg',
'img',
'apk',
'mp2',
'mp3',
'mp4',
'avi',
'flv',
'fla',
'swf',
'3gp',
'mkv',
'mpeg',
'mpg',
'mpe',
'mov',
'asf',
'wmv',
'vob',
'ogg',
const COMPRESSED = [
...['gif', 'jpg', 'jpe', 'jpeg', 'png', 'svgz', 'tiff'],
...['docx', 'xlsx', 'pptx', 'dotx', 'odm', 'odt', 'ott', 'odp', 'otp'],
...['zip', 'rar', 'z7', 'gz', 'jar', 'arj', 'tar', 'arc', 'tgz'],
...['iso', 'nrg', 'img', 'deb', 'dmg', 'rpm', 'apk'],
...['webm', 'vob', 'avi', 'mov', 'flv', 'fla', 'swf', '3gp', 'mkv'],
...['ogg', 'ogv', 'oga', 'ogx', 'wmv', 'wma', 'asf'],
...['mpg', 'mpeg', 'mpe', 'mpv', 'm2v', 'mp4', 'm4p', 'm4v'],
...['mp2', 'mp3', 'm4a', 'flac', 'aac', 'qma'],
...['djvu', 'djv'],
];
const NOT_COMPRESSED_EXT = [
'txt',
'pdf',
'doc',
'dot',
'xls',
'ppt',
'rtf',
'eml',
'uu',
'uue',
'css',
'htm',
'html',
'xhtml',
'tpl',
'vsd',
'ps',
'bmp',
'ico',
'eps',
'svg',
'psd',
'ai',
'tif',
'tiff',
'wmf',
'emf',
'ani',
'cur',
'wav',
'wave',
'mid',
'bak',
'sql',
'csv',
'xml',
'url',
'torrent',
'js',
'php',
'pl',
'pm',
'py',
'c',
'cpp',
'cs',
'd',
'e',
'h',
'inc',
'java',
'm',
'asm',
'res',
'bat',
'cmd',
'exe',
'dll',
'obj',
'sys',
'msi',
];
// Save uploaded file
// data <Object> { compressionFlag, storagePath, storageSize }
// callback <Function>
// error <Error>
// data <Object>
const saveUploadedFile = (data, callback) => {
if (data.compressionFlag === 'N') {
callback(null, data);
return;
}
fs.unlink(data.storagePath, () => {
fs.rename(data.storagePath + '.tmp', data.storagePath, () => {
fs.stat(data.storagePath, (err, stats) => {
if (!err) data.storageSize = stats.size;
callback(err, data);
});
const md5 = filePath =>
new Promise((resolve, reject) => {
const hash = crypto.createHash('md5');
const file = fs.createReadStream(filePath);
file.on('error', reject);
hash.once('readable', () => {
resolve(hash.read().toString('hex'));
});
file.pipe(hash);
});
};
// Upload file to /files in application base folder
// file <Object> { originalFilename, size, path }
// callback <Function>
// err <Error>
// data <Object>
const uploadFile = (file, callback) => {
const folder1 = common.generateKey(2, common.DIGIT);
const folder2 = common.generateKey(2, common.DIGIT);
// Upload file to application/files
const uploadFile = async fileName => {
const dir1 = common.generateKey(2, common.DIGIT);
const dir2 = common.generateKey(2, common.DIGIT);
const code = common.generateKey(8, common.ALPHA_DIGIT);
const targetDir = path.join(application.path, 'files', folder1, folder2);
const data = {
compressionFlag: 'N',
originalName: file.originalFilename,
storageName: folder1 + folder2 + code,
storagePath: path.join(targetDir, code),
originalHash: '',
originalSize: file.size,
storageSize: file.size,
};
const tempFile = file.path;
const fileExt = common.fileExt(data.originalName);
const isComp = COMPRESSED_EXT.includes(fileExt);
const isNotComp = NOT_COMPRESSED_EXT.includes(fileExt);
if (!isComp && !isNotComp) {
const msg = 'Invalid file type: ' + file.originalFilename;
application.logger.warn(msg);
callback(new Error(msg));
return;
}
if (isNotComp) {
// ZIP : GZIP
data.compressionFlag = data.originalSize >= UPLOAD_SIZE_ZIP ? 'Z' : 'G';
}
common.mkdirp(targetDir, () => {
const ws = fs.createWriteStream(data.storagePath);
const rs = fs.createReadStream(tempFile);
rs.pipe(ws);
const fd = fs.createReadStream(tempFile);
const hash = crypto.createHash('md5');
hash.setEncoding('hex');
fd.on('end', () => {
let arc, inp, out;
hash.end();
data.originalHash = hash.read();
if (data.compressionFlag === 'Z') {
arc = new zipStream(); // eslint-disable-line new-cap
out = fs.createWriteStream(data.storagePath + '.tmp');
arc.pipe(out);
arc.on('end', () => {
saveUploadedFile(data, callback);
});
arc.entry(
fs.createReadStream(data.storagePath),
{ name: data.originalName },
(err /*entry*/) => {
if (err) throw err;
arc.finalize();
}
);
} else if (data.compressionFlag === 'G') {
arc = zlib.createGzip();
inp = fs.createReadStream(data.storagePath);
out = fs.createWriteStream(data.storagePath + '.tmp');
inp.pipe(arc).pipe(out);
inp.on('end', () => {
saveUploadedFile(data, callback);
});
} else {
saveUploadedFile(data, callback);
}
});
fd.pipe(hash);
});
const dir = path.join(application.path, 'files', dir1, dir2);
await mkdirp(dir);
const ext = common.fileExt(fileName);
const name = dir1 + dir2 + code;
const dest = path.join(dir, name);
const compression = COMPRESSED.includes(ext) ? 'C' : 'N';
await fsp.rename(fileName, dest);
const hash = await md5(dest);
const { size } = await fs.stat(dest);
return { name, dir, hash, size, ext, compression };
};
module.exports = Object.freeze({ uploadFile });
'use strict';
const { node } = require('./dependencies.js');
const { node, metarhia } = require('./dependencies.js');
const { worker, fsp, path } = node;
const application = require('./application.js');
const { Config } = require('@metarhia/config');
const { Logger } = require('metalog');
const { Server } = require('metacom');
const { Channel } = require('./channel.js');
const { Config } = metarhia.config;
const { Logger } = metarhia.metalog;
const { Server, Channel } = metarhia.metacom;
const { Auth } = require('./auth.js');

@@ -12,0 +11,0 @@ const { Console } = require('./console.js');

{
"name": "impress",
"version": "2.0.0-alpha.34",
"version": "2.0.0-alpha.35",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",
"description": "Impress Application Server for Node.js",
"description": "Impress application server for Node.js and Metarhia private cloud",
"license": "MIT",

@@ -22,8 +22,13 @@ "keywords": [

"cluster",
"private",
"cloud",
"cache",
"http",
"https",
"websocket",
"websockets"
"websockets",
"interactive",
"rack",
"app",
"backend",
"fullstack"
],

@@ -39,3 +44,11 @@ "readmeFilename": "README.md",

},
"homepage": "https://github.com/metarhia",
"funding": {
"type": "patreon",
"url": "https://www.patreon.com/tshemsedinov"
},
"main": "impress.js",
"files": [
"lib/"
],
"scripts": {

@@ -47,3 +60,3 @@ "test": "npm run lint",

"engines": {
"node": ">=12.9.0"
"node": "^12.9 || 14 || 15"
},

@@ -53,12 +66,12 @@ "dependencies": {

"@metarhia/config": "^2.0.0-alpha.3",
"metacom": "0.1.0-alpha.9",
"metalog": "^3.0.0-alpha.0",
"metacom": "0.1.0-alpha.10",
"metalog": "^3.0.0-alpha.2",
"metaschema": "^0.4.0",
"metasql": "^0.3.0-alpha.1",
"metavm": "0.1.0",
"pg": "^8.4.2",
"ws": "^7.3.1"
"metasql": "^0.3.0-alpha.2",
"metavm": "0.2.0",
"pg": "^8.5.1",
"ws": "^7.4.0"
},
"devDependencies": {
"eslint": "^7.13.0",
"eslint": "^7.14.0",
"eslint-config-metarhia": "^7.0.1",

@@ -70,4 +83,4 @@ "eslint-config-prettier": "^6.15.0",

"metatests": "^0.7.2",
"prettier": "^2.1.2"
"prettier": "^2.2.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc