🔼 Bumped moleculer to 0.14.23
This commit is contained in:
@@ -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: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user