mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
fix: derive consistent md5 ids from tag title
This commit is contained in:
@@ -14,6 +14,7 @@ class Migrations {
|
||||
async init() {
|
||||
this.dbVersion =
|
||||
(await this._db.context.read("v")) || CURRENT_DATABASE_VERSION;
|
||||
this._db.context.write("v", this.dbVersion);
|
||||
}
|
||||
|
||||
async migrate() {
|
||||
|
||||
@@ -75,10 +75,10 @@ class Settings {
|
||||
.notebook(pin.data.notebookId)
|
||||
.topics.topic(pin.data.id)._topic;
|
||||
} else if (pin.type === "tag") {
|
||||
item =
|
||||
this._db.tags.tag(pin.data.id) || this._db.tags.tag(pin.data.title);
|
||||
item = this._db.tags.tag(pin.data.id);
|
||||
}
|
||||
if (item) prev.push(item);
|
||||
else this.unpin(pin.data.id); // TODO risky.
|
||||
return prev;
|
||||
}, []);
|
||||
}
|
||||
|
||||
@@ -145,15 +145,24 @@ export default class Notes extends Collection {
|
||||
}
|
||||
|
||||
tagged(tagId) {
|
||||
const tag = this._db.tags.tag(tagId);
|
||||
if (!tag || tag.noteIds.length <= 0) return [];
|
||||
return tag.noteIds.map((id) => this._collection.getItem(id));
|
||||
return this._getTagItems(tagId, "tags");
|
||||
}
|
||||
|
||||
colored(colorId) {
|
||||
const color = this._db.colors.tag(colorId);
|
||||
if (!color || color.noteIds.length <= 0) return [];
|
||||
return color.noteIds.map((id) => this._collection.getItem(id));
|
||||
return this._getTagItems(colorId, "colors");
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_getTagItems(tagId, collection) {
|
||||
const tag = this._db[collection].tag(tagId);
|
||||
if (!tag || tag.noteIds.length <= 0) return [];
|
||||
return tag.noteIds.reduce((arr, id) => {
|
||||
const item = this._collection.getItem(id);
|
||||
if (item) arr.push(item);
|
||||
return arr;
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import Collection from "./collection";
|
||||
import getId from "../utils/id";
|
||||
import { qclone } from "qclone";
|
||||
import set from "../utils/set";
|
||||
|
||||
export default class Tags extends Collection {
|
||||
tag(id) {
|
||||
@@ -20,7 +18,7 @@ export default class Tags extends Collection {
|
||||
title: tagId,
|
||||
};
|
||||
|
||||
let id = tag.id || getId();
|
||||
let id = tag.id || makeId(tag.title);
|
||||
let notes = tag.noteIds || [];
|
||||
|
||||
if (notes.find((id) => id === noteId)) return id;
|
||||
|
||||
@@ -32,4 +32,4 @@ export const EVENTS = {
|
||||
noteRemoved: "note:removed",
|
||||
};
|
||||
|
||||
export const CURRENT_DATABASE_VERSION = 5.1;
|
||||
export const CURRENT_DATABASE_VERSION = 5.2;
|
||||
|
||||
@@ -94,6 +94,7 @@ export default class Backup {
|
||||
switch (version) {
|
||||
case CURRENT_DATABASE_VERSION:
|
||||
case 5.0:
|
||||
case 5.1:
|
||||
case 4:
|
||||
case 4.1:
|
||||
case 4.2:
|
||||
|
||||
@@ -60,7 +60,8 @@ export const migrations = {
|
||||
return item;
|
||||
},
|
||||
},
|
||||
5.1: {
|
||||
5.1: {},
|
||||
5.2: {
|
||||
note: false,
|
||||
notebook: false,
|
||||
tag: false,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import SparkMD5 from "spark-md5";
|
||||
/**
|
||||
*
|
||||
* @param {number} size
|
||||
@@ -25,3 +26,7 @@ function cryptoRandom(size, type) {
|
||||
export default function () {
|
||||
return cryptoRandom(12, "hex");
|
||||
}
|
||||
|
||||
export function makeId(text) {
|
||||
return SparkMD5.hash(text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user