🔼 Bumped moleculer to 0.14.23

This commit is contained in:
2022-08-18 00:29:25 -07:00
parent b0a7e42461
commit d2c171ab5e
8 changed files with 550 additions and 608 deletions

View File

@@ -20,76 +20,68 @@ export default class ImageTransformation extends Service {
schema: ServiceSchema<{}> = { name: "imagetransformation" }
) {
super(broker);
this.parseServiceSchema(
Service.mergeSchemas(
{
name: "imagetransformation",
mixins: [],
settings: {
// Available fields in the responses
fields: ["_id", "name", "quantity", "price"],
this.parseServiceSchema({
name: "imagetransformation",
mixins: [],
settings: {
// Available fields in the responses
fields: ["_id", "name", "quantity", "price"],
// Validator for the `create` & `insert` actions.
entityValidator: {
name: "string|min:3",
price: "number|positive",
},
},
hooks: {},
actions: {
resize: {
rest: "POST /resizeImage",
params: {},
async handler(
ctx: Context<{
imageFile: string | Buffer;
newWidth: number;
newHeight: number;
outputPath: string;
}>
) {
const resizeResult = await resizeImage(
ctx.params.imageFile,
ctx.params.outputPath,
ctx.params.newWidth,
ctx.params.newHeight
);
return { resizeOperationStatus: resizeResult };
},
},
analyze: {
rest: "POST /analyze",
params: {},
handler: async (
ctx: Context<{ imageFilePath: string }>
) => {
const url = new URL(ctx.params.imageFilePath);
const pathName = url.pathname;
const decodedImageFileURI = decodeURI(pathName);
const finalImagePath = path.resolve(
"." + decodedImageFileURI
);
const analyzedData = await analyze(
finalImagePath
);
const colorHistogramData =
await getColorHistogramData(
finalImagePath,
false
);
return {
analyzedData,
colorHistogramData,
};
},
},
},
methods: {},
// Validator for the `create` & `insert` actions.
entityValidator: {
name: "string|min:3",
price: "number|positive",
},
schema
)
);
},
hooks: {},
actions: {
resize: {
rest: "POST /resizeImage",
params: {},
async handler(
ctx: Context<{
imageFile: string | Buffer;
newWidth: number;
newHeight: number;
outputPath: string;
}>
) {
const resizeResult = await resizeImage(
ctx.params.imageFile,
ctx.params.outputPath,
ctx.params.newWidth,
ctx.params.newHeight
);
return { resizeOperationStatus: resizeResult };
},
},
analyze: {
rest: "POST /analyze",
params: {},
handler: async (
ctx: Context<{ imageFilePath: string }>
) => {
const url = new URL(ctx.params.imageFilePath);
const pathName = url.pathname;
const decodedImageFileURI = decodeURI(pathName);
const finalImagePath = path.resolve(
"." + decodedImageFileURI
);
const analyzedData = await analyze(finalImagePath);
const colorHistogramData = await getColorHistogramData(
finalImagePath,
false
);
return {
analyzedData,
colorHistogramData,
};
},
},
},
methods: {},
});
}
}