@restroom-mw/files
Advanced tools
Comparing version 0.12.3-d624e4f.0 to 0.12.3-f67e107.4
export declare const DOWNLOAD = "download the {} and extract it into {}"; | ||
export declare const STORE_RESULT = "store {} in the file {}"; |
"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 {}"; |
@@ -27,2 +27,9 @@ "use strict"; | ||
const actions_1 = require("./actions"); | ||
/** | ||
* `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) => { | ||
@@ -60,4 +67,27 @@ const rr = new core_1.Restroom(req, res); | ||
} | ||
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.3-d624e4f.0+d624e4f", | ||
"version": "0.12.3-f67e107.4+f67e107", | ||
"description": "Utilities middleware to work with files for Restroom", | ||
@@ -35,3 +35,3 @@ "author": "Alberto Lerda <alberto@dyne.org>", | ||
}, | ||
"gitHead": "d624e4f957c02afccc835b6d400b3fa959c950f4" | ||
"gitHead": "f67e107cdadae53b954f9d15011ed2d639acf854" | ||
} |
export const DOWNLOAD= "download the {} and extract it into {}"; | ||
export const STORE_RESULT= "store {} in the file {}"; |
@@ -17,3 +17,11 @@ import { Restroom } from "@restroom-mw/core"; | ||
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) => { | ||
@@ -52,2 +60,27 @@ const rr = new Restroom(req, res); | ||
} | ||
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`); | ||
} | ||
} | ||
} | ||
}); | ||
@@ -54,0 +87,0 @@ |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
43453
181