🛣 Levenshtein distance between images WIP

This commit is contained in:
2021-07-31 12:02:47 -07:00
parent fcb922d52b
commit 51d8f94068
5 changed files with 408 additions and 4 deletions

View File

@@ -6,7 +6,13 @@ import {
ServiceSchema,
Errors,
} from "moleculer";
import { resizeImage } from "../utils/imagetransformation.utils";
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
@@ -52,6 +58,44 @@ 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: {},
},