From c7d431343ddb337f14d5b7aae82b7b40b99bdf5f Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 6 Sep 2021 23:21:33 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fixes=20to=20missing=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 11 +---------- utils/imagetransformation.utils.ts | 20 ++++++++++++++++++++ utils/searchmatchscorer.utils.ts | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0700987..3fd47fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "threetwo-library-service", "version": "1.0.0", "dependencies": { "@root/walk": "^1.1.0", @@ -11628,11 +11629,6 @@ "node": ">=8" } }, - "node_modules/string-similarity": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz", - "integrity": "sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ==" - }, "node_modules/string-width": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", @@ -21892,11 +21888,6 @@ "strip-ansi": "^5.2.0" } }, - "string-similarity": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz", - "integrity": "sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ==" - }, "string-width": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", diff --git a/utils/imagetransformation.utils.ts b/utils/imagetransformation.utils.ts index e3e7bcf..9361f90 100644 --- a/utils/imagetransformation.utils.ts +++ b/utils/imagetransformation.utils.ts @@ -1,6 +1,9 @@ const sharp = require("sharp"); import { logger } from "./logger.utils"; import { ISharpResizedImageStats } from "threetwo-ui-typings"; +const imghash = require("imghash"); +const leven = require("leven"); +import { isNull, reject } from "lodash"; export const extractMetadataFromImage = async ( imageFilePath: string @@ -35,3 +38,20 @@ export const resizeImage = async ( }); }); }; + +export const calculateLevenshteinDistance = async ( + imagePath1: string, + imagePath2: string +): Promise> => { + console.log("AGANTUK", imagePath1) + const hash1 = await imghash.hash(imagePath1); + const hash2 = await imghash.hash(imagePath2); + console.log("HASHISH", hash1) + if (!isNull(hash1) && !isNull(hash2)) { + return new Promise((resolve, reject) => { + resolve({ levenshteinDistance: leven(hash1, hash2) }); + }); + } else { + reject("Can't calculate the Levenshtein distance") + } +}; diff --git a/utils/searchmatchscorer.utils.ts b/utils/searchmatchscorer.utils.ts index d0aac91..213b599 100644 --- a/utils/searchmatchscorer.utils.ts +++ b/utils/searchmatchscorer.utils.ts @@ -31,7 +31,7 @@ SOFTWARE. * Initial: 2021/07/29 Rishi Ghan */ -import { each, map, isUndefined, isNull, assign } from "lodash"; +import { each, isNull } from "lodash"; import stringSimilarity from "string-similarity"; import https from "https"; import { createWriteStream } from "fs";