⌨️ Added a type for image stats

This commit is contained in:
2021-08-03 22:11:58 -07:00
parent 51d8f94068
commit 29851c5736
3 changed files with 21 additions and 77 deletions

View File

@@ -8,12 +8,7 @@ import {
} from "moleculer";
import {
resizeImage,
calculateLevenshteinDistance,
} from "../utils/imagetransformation.utils";
import https from "https";
import fs from "fs";
import path from "path";
export default class ProductsService extends Service {
// @ts-ignore
public constructor(
@@ -58,44 +53,6 @@ export default class ProductsService extends Service {
return { resizeOperationStatus: resizeResult };
},
},
calculateLevenshteinDistance: {
rest: "POST /calculateLevenshteinDistance",
params: {},
async handler(
ctx: Context<{
imagePath: string;
imagePath2: string;
options: {
match_id: string,
};
}>
) {
const fileName = ctx.params.options.match_id + "_" + path.basename(
ctx.params.imagePath
);
return new Promise((resolve, reject) => {
https.get(ctx.params.imagePath2, (response) => {
const fileStream = response.pipe(
fs.createWriteStream(
`./userdata/temporary/${fileName}`
)
);
fileStream.on("finish", async () => {
const levenshteinDistance = await calculateLevenshteinDistance(
ctx.params.imagePath,
path.resolve(
`./userdata/temporary/${fileName}`
)
);
resolve(levenshteinDistance);
});
}).end();
});
},
},
},
methods: {},
},