Skip to content

Commit

Permalink
Merge pull request #13 from Zuoqiu-Yingyi/dev
Browse files Browse the repository at this point in the history
chore: release v0.2.0
  • Loading branch information
Zuoqiu-Yingyi authored Oct 22, 2023
2 parents b8ff2b3 + f2201fa commit 93ea564
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:

env:
PACKAGE_NAME: keepass
PACKAGE_VERSION: 0.1.4
PACKAGE_VERSION: 0.2.0

jobs:
release-please:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "keepass",
"private": true,
"version": "0.1.4",
"version": "0.2.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
17 changes: 12 additions & 5 deletions public/keeweb/app/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/keeweb/app/update.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.18.7",
"date": "2023-10-21"
"date": "2023-10-22"
}
2 changes: 1 addition & 1 deletion public/keeweb/plugins/siyuan/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.4",
"version": "0.2.0",
"manifestVersion": "0.1.0",
"name": "siyuan",
"description": "Establish a connection between KeeWeb and SiYuan",
Expand Down
2 changes: 1 addition & 1 deletion public/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "keepass",
"author": "Zuoqiu Yingyi",
"url": "https://github.com/Zuoqiu-Yingyi/siyuan-plugin-keepass",
"version": "0.1.4",
"version": "0.2.0",
"minAppVersion": "2.10.3",
"backends": [
"all"
Expand Down
49 changes: 28 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import type { IConfig } from "./types/config";
import type {
ILocalStoragePlugins,
ILocalStoragePlugin,
ILocalStoragePluginManifest,
IPluginManifest,
} from "./types/keeweb";
import type {
IDBSchema,
Expand Down Expand Up @@ -136,7 +136,7 @@ export default class KeepassPlugin extends siyuan.Plugin {

protected readonly keewebTab: ReturnType<siyuan.Plugin["addTab"]>;

protected manifest!: ILocalStoragePluginManifest;
protected manifest!: IPluginManifest;
protected config: IConfig = mergeIgnoreArray(DEFAULT_CONFIG);
protected local: TLocal = {};
protected idb!: IDB;
Expand Down Expand Up @@ -381,7 +381,7 @@ export default class KeepassPlugin extends siyuan.Plugin {
this.idb.FilesCache.clear(KeepassPlugin.IDB_SCHEMA.FilesCache.stores.files.name),
this.idb.PluginFiles.clear(KeepassPlugin.IDB_SCHEMA.PluginFiles.stores.files.name),
]);

/* 同步删除插件对应的数据 */
await Promise.allSettled([
this.saveLocalStorage(),
Expand Down Expand Up @@ -411,12 +411,18 @@ export default class KeepassPlugin extends siyuan.Plugin {
* - `this.local`: 加载成功
* - `undefined`: 加载失败
*/
public async loadLocalStorage(): Promise<TLocal | void> {
const local = await this.loadLocal();
if (local) {
this.setLocalStorageItems(local);
}
return local;
public async loadLocalStorage(): Promise<TLocal> {
const local_siyuan = await this.loadLocal();
const local_storage = this.getLocalStorageItems();

const local_siyuan_keys = Object.keys(local_siyuan);
const local_storage_keys = Object.keys(local_storage);

const entries = sync1<string>(local_siyuan_keys, local_storage_keys);
this.logger.debug(entries);
entries.delete.forEach(entry => globalThis.localStorage.removeItem(entry));
this.setLocalStorageItems(this.local);
return local_siyuan;
}

/**
Expand All @@ -426,8 +432,8 @@ export default class KeepassPlugin extends siyuan.Plugin {
* - `false`: 保存失败
*/
public async saveLocalStorage(): Promise<boolean> {
const local = this.getLocalStorageItems();
return this.saveLocal(local);
this.local = this.getLocalStorageItems();
return this.saveLocal(this.local);
}

/**
Expand All @@ -436,16 +442,17 @@ export default class KeepassPlugin extends siyuan.Plugin {
* - `this.local`: 加载成功
* - `undefined`: 加载失败
*/
public async loadLocal(): Promise<TLocal | void> {
public async loadLocal(): Promise<TLocal> {
try {
const local = await this.loadData(KeepassPlugin.LOCAL_STORAGE_NAME);
if (local) {
this.local = local;
return this.local;
}
this.local = (local instanceof Object)
? local
: {};
return this.local;
}
catch (error) {
this.logger.error(error);
throw error;
}
}

Expand Down Expand Up @@ -499,13 +506,13 @@ export default class KeepassPlugin extends siyuan.Plugin {
* 获取 KeeWeb 相关的 localStorage 项
*/
public getLocalStorageItems(): TLocal {
this.local = {};
const local: TLocal = {};
for (const [key, value] of Object.entries(globalThis.localStorage)) {
if (this.isLocalStorageKey(key)) {
this.local[key] = JSON.parse(value);
local[key] = JSON.parse(value);
}
}
return this.local;
return local;
}

/**
Expand Down Expand Up @@ -671,15 +678,15 @@ export default class KeepassPlugin extends siyuan.Plugin {
/**
* 加载 keeweb 思源插件的配置清单文件
*/
protected async loadKeeWebPluginManifest(): Promise<ILocalStoragePluginManifest> {
protected async loadKeeWebPluginManifest(): Promise<IPluginManifest> {
if (!this.manifest) {
this.manifest = await this.client.getFile({
path: join(
this.PLUGIN_INSTALL_PATH,
"keeweb/plugins/siyuan",
"manifest.json",
),
}, "json") as ILocalStoragePluginManifest;
}, "json") as IPluginManifest;
}
return this.manifest;
}
Expand Down
13 changes: 8 additions & 5 deletions src/keeweb/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"siyuan": "SiYuan",
"siyuanBaseURL": "SiYuan service base URL",
"siyuan": "SiYuan Note",
"siyuanBaseURL": "SiYuan Note service base URL",
"siyuanFileOpenDefaultPath": "Default file open directory",
"siyuanPath": "Default *.kdbx file storage directory",
"siyuanToken": "SiYuan service token",
"siyuanTokenPlaceholder": "This field needs to be configured only when you are not logged in SiYuan service",
"siyuanWorkspaceRootDirectory": "Root directory of SiYuan workspace"
"siyuanStorageDesc": "SiYuan Note storage settings",
"siyuanStorageDescAuthorize": "Access authorization to SiYuan Note service is not obtained. Please correctly set the token of the SiYuan Note service.",
"siyuanStorageDescConnect": "Unable to access the SiYuan Note service. Please correctly set the base URL of the SiYuan Note service.",
"siyuanToken": "SiYuan Note service token",
"siyuanTokenPlaceholder": "This field needs to be configured only when you are not logged in SiYuan Note service",
"siyuanWorkspaceRootDirectory": "Root directory of SiYuan Note workspace"
}
11 changes: 7 additions & 4 deletions src/keeweb/i18n/zh-Hans.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"siyuan": "思源笔记",
"siyuanBaseURL": "思源服务 URL 地址",
"siyuanBaseURL": "思源笔记服务地址 (base URL)",
"siyuanFileOpenDefaultPath": "默认的文件打开目录",
"siyuanPath": "默认 *.kdbx 文件存放目录",
"siyuanToken": "思源服务 Token",
"siyuanTokenPlaceholder": "仅在未登录思源服务状态下配置该字段",
"siyuanWorkspaceRootDirectory": "思源工作空间的根目录"
"siyuanStorageDesc": "思源笔记存储设置",
"siyuanStorageDescAuthorize": "未获得思源笔记服务的访问授权,请正确设置思源笔记服务的令牌 (Token)",
"siyuanStorageDescConnect": "无法访问思源笔记服务,请正确设置思源笔记服务的地址 (base URL)",
"siyuanToken": "思源笔记服务令牌 (Token)",
"siyuanTokenPlaceholder": "仅在未登录思源笔记服务状态下配置该字段",
"siyuanWorkspaceRootDirectory": "思源笔记工作空间的根目录"
}
11 changes: 7 additions & 4 deletions src/keeweb/i18n/zh-Hant.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"siyuan": "思源筆記",
"siyuanBaseURL": "思源服務 URL 地址",
"siyuanBaseURL": "思源筆記服務 URL 地址 (base URL)",
"siyuanFileOpenDefaultPath": "默認的文件打開目錄",
"siyuanPath": "默認 *.kdbx 文件存放目錄",
"siyuanToken": "思源服務 Token",
"siyuanTokenPlaceholder": "僅在未登錄思源服務狀態下配置該字段",
"siyuanWorkspaceRootDirectory": "思源工作空間的根目錄"
"siyuanStorageDesc": "思源筆記存儲設置",
"siyuanStorageDescAuthorize": "未獲得思源筆記服務的訪問授權,請正確設置思源筆記服務的令牌 (Token)",
"siyuanStorageDescConnect": "無法訪問思源筆記服務,請正確設置思源筆記服務的地址 (base URL)",
"siyuanToken": "思源筆記服務 Token",
"siyuanTokenPlaceholder": "僅在未登錄思源筆記服務狀態下配置該字段",
"siyuanWorkspaceRootDirectory": "思源筆記工作空間的根目錄"
}
78 changes: 71 additions & 7 deletions src/keeweb/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,108 @@
import zh_Hans from "./i18n/zh-Hans.json";
import type sdk from "@siyuan-community/siyuan-sdk";
import type { SiyuanStorage } from "./storage";
import type { IPluginManifest } from "@/types/keeweb";

export type I18N = typeof zh_Hans;

export interface IBaseSetting<T> {
/**
* 插件设置项
*
* 模板文件: app/templates/settings/settings-plugins.hbs
*/
//#region plugin-setting
export interface IPluginBaseSetting<T> {
name: string;
label: string;
type: string;
label: string;
value: T;
}
export interface ITextSetting extends IBaseSetting<string> {
export interface IPluginTextSetting extends IPluginBaseSetting<string> {
type: "text";
maxlength?: number;
placeholder?: string;
}
export interface ISelectSetting extends IBaseSetting<string> {
export interface IPluginSelectSetting extends IPluginBaseSetting<string> {
type: "select";
options: {
value: string;
label: string;
}[];
}
export interface ICheckboxSetting extends IBaseSetting<boolean> {
export interface IPluginCheckboxSetting extends IBaseSetting<boolean> {
type: "checkbox";
}
export type TSetting = ITextSetting
export type TPluginSetting = ITextSetting
| ISelectSetting
| ICheckboxSetting;
//#endregion plugin-setting

/**
* 储存打开设置项
*
* 模板文件: app/templates/open-config.hbs
*/
//#region storage-open-config
export interface IStorageOpenConfigField {
id: string;
type: string; // input.type
title: string;
desc?: string;
placeholder?: string;
required?: boolean;
pattern?: string;
}
export interface IStorageOpenConfig {
desc?: string;
fields: IStorageOpenConfigField[];
}
//#region storage-open-config

/**
* 储存设置项
*
* 模板文件: app/templates/settings/settings-prv.hbs
*/
export interface IStorageBaseSettings<T> {
id: string;
type: string;
title: string;
value: T;
}
export interface IStorageSelectSetting extends IStorageBaseSettings<string> {
type: "select";
options: Record<string, string>;
}
export interface IStorageCheckboxSetting extends IStorageBaseSettings<boolean> {
type: "checkbox";
desc?: string;
}
export interface IStorageInputSetting<T> extends IStorageBaseSettings<T> {
desc?: string;
required?: boolean;
pattern?: string;
placeholder?: string;
}
export type TStorageSttingField<T = string | number> = IStorageInputSetting<T>
| IStorageCheckboxSetting
| IStorageSelectSetting;
export interface IStorageSettingsConfig {
desc?: string;
fields: TStorageSttingField[];
}

export type TFileOpenSchema = "path" | "root";

export interface IContext {
path: string;
type: "fetch";
client: InstanceType<typeof sdk.Client>;
baseURL: string;
manifest: IPluginManifest;
defaultPath: string; // 默认文件存放目录
fileOpenPath: string; // 文件打开路径
storage?: InstanceType<typeof SiyuanStorage>;
lang?: string;
i18n?: I18N;
settings?: TSetting[];
settings?: TPluginSetting[];
}
Loading

0 comments on commit 93ea564

Please sign in to comment.