Revert "fix: hash all indexed keys"

This reverts commit 4a5daf2a8d.
This commit is contained in:
thecodrr
2020-11-16 15:00:24 +05:00
parent 20a3d1ab20
commit fd0d84b3ab
5 changed files with 14 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
import SparkMD5 from "spark-md5";
import { sendCheckUserStatusEvent } from "../common.js";
import Hashes from "jshashes";
const md5 = new Hashes.MD5();
const invalidKeys = ["user", "t", "lastBackupTime"];
const validTypes = ["mobile", "web", "node"];
@@ -48,8 +49,8 @@ export default class Backup {
type,
date: Date.now(),
data,
hash: SparkMD5.hash(JSON.stringify(data)),
hash_type: "spark-md5",
hash: md5.hex(JSON.stringify(data)),
hash_type: "md5",
});
}
@@ -105,8 +106,8 @@ export default class Backup {
_verify(backup) {
const { hash, hash_type, data: db } = backup;
switch (hash_type) {
case "spark-md5": {
return hash === SparkMD5.hash(JSON.stringify(db));
case "md5": {
return hash === md5.hex(JSON.stringify(db));
}
default: {
return false;

View File

@@ -1,6 +1,5 @@
import Storage from "./storage";
import Indexer from "./indexer";
import SparkMD5 from "spark-md5";
export default class PersistentCachedMap {
/**
@@ -20,7 +19,6 @@ export default class PersistentCachedMap {
}
async set(key, value) {
key = SparkMD5.hash(key);
this.map.set(key, value);
await this.indexer.write(key, value);
await this.indexer.index(key);
@@ -33,12 +31,10 @@ export default class PersistentCachedMap {
}
get(key) {
key = SparkMD5.hash(key);
return this.map.get(key);
}
has(key) {
key = SparkMD5.hash(key);
return this.map.has(key);
}

View File

@@ -1,6 +1,5 @@
import Indexer from "./indexer";
import Storage from "./storage";
import SparkMD5 from "spark-md5";
export default class PersistentMap {
/**
@@ -18,7 +17,6 @@ export default class PersistentMap {
}
async set(key, value) {
key = SparkMD5.hash(key);
await this.indexer.write(key, value);
await this.indexer.index(key);
}
@@ -29,12 +27,10 @@ export default class PersistentMap {
}
get(key) {
key = SparkMD5.hash(key);
return this.indexer.read(key);
}
has(key) {
key = SparkMD5.hash(key);
return this.indexer.exists(key);
}

View File

@@ -24,11 +24,11 @@
"fast-sort": "^2.0.1",
"fuzzysearch": "^1.0.3",
"hypersearch": "https://github.com/streetwriters/hypersearch",
"jshashes": "^1.0.8",
"no-internet": "^1.5.2",
"qclone": "^1.0.4",
"quill-delta-to-html": "^0.12.0",
"quill-delta-to-markdown": "https://github.com/streetwriters/quill-delta-to-markdown",
"spark-md5": "^3.0.1",
"transfun": "^1.0.2"
}
}

View File

@@ -2704,8 +2704,8 @@ http-signature@~1.2.0:
sshpk "^1.7.0"
"hypersearch@https://github.com/streetwriters/hypersearch":
version "0.1.0"
resolved "https://github.com/streetwriters/hypersearch#fa5d2b8435c1b7bca4b5f8059054da848fe1631f"
version "0.0.4"
resolved "https://github.com/streetwriters/hypersearch#9cad0f7c2d93f19bf06d7fa6602357b89cdba38d"
iconv-lite@0.4.24:
version "0.4.24"
@@ -3406,6 +3406,11 @@ jsesc@~0.5.0:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d"
integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=
jshashes@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/jshashes/-/jshashes-1.0.8.tgz#f60d837428383abf73ab022e1542e6614bd75514"
integrity sha512-btmQZ/w1rj8Lb6nEwvhjM7nBYoj54yaEFo2PWh3RkxZ8qNwuvOxvQYN/JxVuwoMmdIluL+XwYVJ+pEEZoSYybQ==
json-parse-better-errors@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
@@ -4515,11 +4520,6 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
spark-md5@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/spark-md5/-/spark-md5-3.0.1.tgz#83a0e255734f2ab4e5c466e5a2cfc9ba2aa2124d"
integrity sha512-0tF3AGSD1ppQeuffsLDIOWlKUd3lS92tFxcsrh5Pe3ZphhnoK+oXIBTzOAThZCiuINZLvpiLH/1VS1/ANEJVig==
spdx-correct@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.0.tgz#fb83e504445268f154b074e218c87c003cd31df4"