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

@restroom-mw/files

Package Overview
Dependencies
Maintainers
3
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@restroom-mw/files - npm Package Compare versions

Comparing version 0.12.2 to 0.12.3-080c675.5

1

dist/actions.d.ts
export declare const DOWNLOAD = "download the {} and extract it into {}";
export declare const STORE_RESULT = "store {} in the file {}";

3

dist/actions.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DOWNLOAD = void 0;
exports.STORE_RESULT = exports.DOWNLOAD = void 0;
exports.DOWNLOAD = "download the {} and extract it into {}";
exports.STORE_RESULT = "store {} in the file {}";

@@ -18,7 +18,20 @@ "use strict";

const fs_1 = __importDefault(require("fs"));
const extract_zip_1 = __importDefault(require("extract-zip"));
const path_1 = __importDefault(require("path"));
/**
* `download the 'myUrl' and extract it into 'myFolder'`
*
* Download a zip file located at the url `myUrl` and extract it at the path
* `myFolder` on the server.
*/
const actions_1 = require("./actions");
const extract_zip_1 = __importDefault(require("extract-zip"));
/**
* `store 'myVariable' in the file 'myFolder'`
*
* Store the content of the variable `myVariable` in the filesystem at the path
* `myFolder` on the server
*/
const actions_2 = require("./actions");
exports.default = (req, res, next) => {
const rr = new core_1.Restroom(req, res);
let content = {};
rr.onSuccess((params) => __awaiter(void 0, void 0, void 0, function* () {

@@ -31,4 +44,5 @@ const { result, zencode } = params;

const folder = result[allPassOutputs[i + 1]];
if (file) {
if (file && folder) {
try {
const absoluteFolder = path_1.default.resolve(folder);
const response = yield axios_1.default.get(file, {

@@ -40,3 +54,3 @@ responseType: 'arraybuffer'

fs_1.default.writeFileSync(tempfile, response.data);
yield (0, extract_zip_1.default)(tempfile, { dir: folder });
yield (0, extract_zip_1.default)(tempfile, { dir: absoluteFolder });
fs_1.default.unlinkSync(tempfile);

@@ -47,11 +61,35 @@ fs_1.default.rmdirSync(tempdir);

next(e);
throw new Error(`[FILES]
Error sending the result to "${file}":
${e}`);
throw new Error(`[FILES] Error sending the result to "${file}": ${e}`);
}
}
else {
throw new Error(`[FILES] url or destination folder not defined`);
}
}
}
if (zencode.match(actions_2.STORE_RESULT)) {
const allPassOutputs = zencode.paramsOf(actions_2.STORE_RESULT);
for (let i = 0; i < allPassOutputs.length; i += 2) {
const variable = result[allPassOutputs[i]];
const file = result[allPassOutputs[i + 1]];
if (variable && file) {
const variableJson = JSON.stringify(variable);
try {
const absoluteFile = path_1.default.resolve(file);
const absoluteFolder = path_1.default.dirname(absoluteFile);
fs_1.default.mkdirSync(absoluteFolder, { recursive: true });
fs_1.default.writeFileSync(absoluteFile, variableJson);
}
catch (e) {
next(e);
throw new Error(`[FILES] Error saving the result to "${file}": ${e}`);
}
}
else {
throw new Error(`[FILES] variable or destination folder not defined`);
}
}
}
}));
next();
};
{
"name": "@restroom-mw/files",
"version": "0.12.2",
"version": "0.12.3-080c675.5+080c675",
"description": "Utilities middleware to work with files for Restroom",

@@ -35,3 +35,3 @@ "author": "Alberto Lerda <alberto@dyne.org>",

},
"gitHead": "5786eb4008a95ffa6009bba94e7bd0e21a3f79f0"
"gitHead": "080c6758c249b8a2da898648941bfa5b02826964"
}
export const DOWNLOAD= "download the {} and extract it into {}";
export const STORE_RESULT= "store {} in the file {}";

@@ -7,12 +7,23 @@ import { Restroom } from "@restroom-mw/core";

import fs from 'fs'
import https from "https";
import {
DOWNLOAD,
} from "./actions";
import yauzl from 'yauzl';
import extract from 'extract-zip';
import path from 'path';
/**
* `download the 'myUrl' and extract it into 'myFolder'`
*
* Download a zip file located at the url `myUrl` and extract it at the path
* `myFolder` on the server.
*/
import { DOWNLOAD } from "./actions";
/**
* `store 'myVariable' in the file 'myFolder'`
*
* Store the content of the variable `myVariable` in the filesystem at the path
* `myFolder` on the server
*/
import { STORE_RESULT } from "./actions";
export default (req: Request, res: Response, next: NextFunction) => {
const rr = new Restroom(req, res);
let content: ObjectLiteral = {};

@@ -27,4 +38,5 @@ rr.onSuccess(async (params) => {

if (file) {
if (file && folder) {
try {
const absoluteFolder = path.resolve(folder);
const response = await axios.get(file, {

@@ -36,3 +48,3 @@ responseType: 'arraybuffer'

fs.writeFileSync(tempfile, response.data);
await extract(tempfile, { dir: folder });
await extract(tempfile, { dir: absoluteFolder });
fs.unlinkSync(tempfile);

@@ -42,9 +54,35 @@ fs.rmdirSync(tempdir);

next(e);
throw new Error(`[FILES]
Error sending the result to "${file}":
${e}`);
throw new Error(`[FILES] Error sending the result to "${file}": ${e}`);
}
}
else {
throw new Error(`[FILES] url or destination folder not defined`);
}
}
}
if (zencode.match(STORE_RESULT)) {
const allPassOutputs = zencode.paramsOf(STORE_RESULT);
for (let i = 0; i < allPassOutputs.length; i += 2) {
const variable = result[allPassOutputs[i]]
const file = result[allPassOutputs[i+1]]
if (variable && file) {
const variableJson = JSON.stringify(variable)
try {
const absoluteFile = path.resolve(file);
const absoluteFolder = path.dirname(absoluteFile);
fs.mkdirSync(absoluteFolder, { recursive: true });
fs.writeFileSync(absoluteFile, variableJson);
} catch (e) {
next(e);
throw new Error(`[FILES] Error saving the result to "${file}": ${e}`);
}
}
else {
throw new Error(`[FILES] variable or destination folder not defined`);
}
}
}
});

@@ -51,0 +89,0 @@

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