From b840e9fa7fa0aa7f77b43f0bb341ab6544947344 Mon Sep 17 00:00:00 2001 From: bcdax110 Date: Sat, 2 Mar 2024 00:19:00 +0800 Subject: [PATCH 1/3] feat: Add field id_base62 to Highlight --- package.json | 3 ++- src/models.ts | 1 + src/parser/parseSyncResponse.ts | 14 +++++++++++++- src/settingsTab/templateInstructions.html | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6c7172b..dc9cad0 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "typescript": "^4.2.4", "webpack": "^5.30.0", "webpack-cli": "^4.6.0", - "webpack-node-externals": "^2.5.2" + "webpack-node-externals": "^2.5.2", + "base-x": "^4.0.0" } } \ No newline at end of file diff --git a/src/models.ts b/src/models.ts index c39a7a0..d347b44 100644 --- a/src/models.ts +++ b/src/models.ts @@ -14,6 +14,7 @@ export type Metadata = { export type Highlights = { id?: string; + id_base62?: string; created: string; updated: string; text: string; diff --git a/src/parser/parseSyncResponse.ts b/src/parser/parseSyncResponse.ts index 75a1527..b038b1a 100644 --- a/src/parser/parseSyncResponse.ts +++ b/src/parser/parseSyncResponse.ts @@ -2,8 +2,12 @@ import md5 from 'crypto-js/md5'; import { moment } from 'obsidian'; import { settingsStore } from '~/store'; import { get } from 'svelte/store'; +import basex from 'base-x'; import type { Article, Highlights } from '../models' +const BASE62_CHARSET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; +const base62 = basex(BASE62_CHARSET); + const parseAuthorUrl = (url: string) => { const domain = (new URL(url)); const author = domain.hostname.replace('www.', ''); @@ -52,8 +56,16 @@ const parseHighlight = (annotationData, groupName: string, momentFormat: string) } } + const id = annotationData['id']; + let id_base62 = null; + if(id != null){ + const uint8Array = Buffer.from(id, 'utf-8'); + id_base62 = base62.encode(uint8Array); + } + return { - id: annotationData['id'], + id, + id_base62, created: moment(annotationData['created']).format(momentFormat), updated: moment(annotationData['updated']).format(momentFormat), text: highlightText && cleanTextSelectorHighlight(highlightText), diff --git a/src/settingsTab/templateInstructions.html b/src/settingsTab/templateInstructions.html index 43dc0fd..e939344 100644 --- a/src/settingsTab/templateInstructions.html +++ b/src/settingsTab/templateInstructions.html @@ -16,7 +16,8 @@ Highlight