From 3d0b316fe909815cf1e858c70085f9a6c936cb91 Mon Sep 17 00:00:00 2001 From: Icebob Date: Wed, 4 Dec 2024 20:04:58 +0100 Subject: [PATCH] changelog --- CHANGELOG.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2417c4bc..f843ac5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,73 @@ + +# 0.11.0-beta1 (2024-12-04) + +## Changes + +### Using 0.15 new streaming solution + +The moleculer-web@0.11.x supports Moleculer v0.15.x including the new streaming solution. It means, it doesn't support 0.13 and 0.14 moleculer versions. + +Thanks for the new solution, the multipart fields and request parameters are sent via `ctx.params` instead of meta and the file stream is available in `ctx.stream` in action handlers. + +**Example** + +```js +module.exports = { + name: "file", + actions: { + save: { + handler(ctx) { + return new this.Promise((resolve, reject) => { + const filePath = path.join(uploadDir, ctx.params.$filename); + const f = fs.createWriteStream(filePath); + f.on("close", () => { + // File written successfully + this.logger.info(`Uploaded file stored in '${filePath}'`); + resolve({ filePath }); + }); + + ctx.stream.on("error", err => { + this.logger.info("File error received", err.message); + reject(err); + + // Destroy the local file + f.destroy(err); + }); + + f.on("error", () => { + // Remove the errored file. + fs.unlinkSync(filePath); + }); + + ctx.stream.pipe(f); + }); + } + } + } +}; +``` + +Example content of `ctx.params`: + +```json +{ + // Multipart file properties + $fieldname: "myfile", + $filename: "avatar.png", + $encoding: "7bit", + $mimetype: "image/png", + + // Other multipart fields + // e.g.: `` + name: "Test User", + + // Request path parameter, e.g.: `/upload/single/1234` + id: "1234" +} +``` + + +----------------------------- # 0.10.7 (2023-11-12) diff --git a/package.json b/package.json index ee451a3e..680e292f 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "webpack-dev-middleware": "^5.2.1" }, "peerDependencies": { - "moleculer": "^0.13.0 || ^0.14.0 || ^0.15.0" + "moleculer": "^0.15.0" }, "dependencies": { "@fastify/busboy": "^1.0.0",