From 8a0774499eeaf33981b521b4248cf74e5643808b Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 21 Jul 2022 23:43:47 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/5478 --- app/appearance/langs/en_US.json | 1 + app/appearance/langs/es_ES.json | 1 + app/appearance/langs/fr_FR.json | 1 + app/appearance/langs/zh_CHT.json | 1 + app/appearance/langs/zh_CN.json | 1 + app/src/config/about.ts | 35 ++++++++++++++++++++++++++++++++ 6 files changed, 40 insertions(+) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 8b5ba4b16..5dbf00b4b 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -28,6 +28,7 @@ "keyPlaceholder": "Please paste the key string here", "key": "Key", "genKey": "Generate key", + "genKeyByPW": "Generate key from password", "dataRepoKeyTip1": "The data repo is used to encrypt and save data snapshots. Snapshots can be created and rolled back in the data history", "dataRepoKeyTip2": "After the key is initialized, other devices need to import the key. If the device keys don't match, you won't be able to sync data in the cloud, so be sure to use the same key on all devices", "dataRepoKey": "Data repo key", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 20d555338..59bff16e2 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -28,6 +28,7 @@ "keyPlaceholder": "Por favor, pegue la cadena de claves aquí", "key": "Clave", "genKey": "Generación de la clave", + "genKeyByPW": "Generar clave a partir de contraseña", "dataRepoKeyTip1": "El repositorio de datos se utiliza para cifrar y guardar instantáneas de datos. Las instantáneas pueden crearse y revertirse en el historial de datos", "dataRepoKeyTip2": "Después de inicializar la clave, otros dispositivos deben importar la clave. Si las claves del dispositivo no coinciden, no podrá sincronizar datos en la nube, así que asegúrese de usar la misma clave en todos los dispositivos", "dataRepoKey": "Clave del repositorio de datos", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 376c48704..ac6782e83 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -28,6 +28,7 @@ "keyPlaceholder": "Veuillez coller la chaîne de clé ici", "clé": "Clé", "genKey": "Générer la clé", + "genKeyByPW": "Générer la clé à partir du mot de passe", "dataRepoKeyTip1": "Le référentiel de données est utilisé pour chiffrer et enregistrer des instantanés de données. Des instantanés peuvent être créés et restaurés dans l'historique des données", "dataRepoKeyTip2": "Une fois la clé initialisée, d'autres appareils doivent importer la clé. Si les clés de l'appareil ne correspondent pas, vous ne pourrez pas synchroniser les données dans le cloud, alors assurez-vous d'utiliser la même clé sur tous les appareils", "dataRepoKey": "Clé de référentiel de données", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 160b40329..f72539398 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -28,6 +28,7 @@ "keyPlaceholder": "請在此處粘貼密鑰字符串", "key": "密鑰", "genKey": "生成密鑰", + "genKeyByPW": "從密碼生成密鑰", "dataRepoKeyTip1": "數據倉庫用於加密保存數據快照,可在數據歷史中可創建快照和回滾快照", "dataRepoKeyTip2": "初始化密鑰以後其他設備需要導入該密鑰。如果設備密鑰不一致,則無法雲端同步數據,所以請務必在所有設備上使用相同的密鑰", "dataRepoKey": "數據倉庫密鑰", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index ce8379b40..ace0d5e23 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -28,6 +28,7 @@ "keyPlaceholder": "请在此处粘贴密钥字符串", "key": "密钥", "genKey": "生成密钥", + "genKeyByPW": "根据密码生成密钥", "dataRepoKeyTip1": "数据仓库用于加密保存数据快照,可在数据历史中可创建快照和回滚快照", "dataRepoKeyTip2": "初始化密钥以后其他设备需要导入该密钥。如果设备密钥不一致,则无法云端同步数据,所以请务必在所有设备上使用相同的密钥", "dataRepoKey": "数据仓库密钥", diff --git a/app/src/config/about.ts b/app/src/config/about.ts index 9ecafad8a..a9b416ee4 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -95,6 +95,10 @@ export const about = { ${window.siyuan.languages.genKey}
+ +
@@ -252,6 +256,37 @@ export const about = { }); }); }); + about.element.querySelector("#initKeyByPW").addEventListener("click", () => { + const initDialog = new Dialog({ + title: "🔑 " + window.siyuan.languages.genKeyByPW, + content: `
+ +
+
+
+ +
`, + width: "520px", + }); + const inputElement = initDialog.element.querySelector(".b3-text-field") as HTMLInputElement; + inputElement.focus(); + const btnsElement = initDialog.element.querySelectorAll(".b3-button"); + initDialog.bindInput(inputElement, () => { + (btnsElement[1] as HTMLButtonElement).click(); + }); + btnsElement[0].addEventListener("click", () => { + initDialog.destroy(); + }); + btnsElement[1].addEventListener("click", () => { + confirmDialog("🔑 " + window.siyuan.languages.genKeyByPW, window.siyuan.languages.initRepoKeyTip, () => { + fetchPost("/api/repo/InitRepoKeyFromPassphrase", {pass: inputElement.value}, (response) => { + window.siyuan.config.repo.key = response.data.key; + importKeyElement.parentElement.classList.add("fn__none"); + importKeyElement.parentElement.nextElementSibling.classList.remove("fn__none"); + }); + }); + }); + }); about.element.querySelector("#copyKey").addEventListener("click", () => { showMessage(window.siyuan.languages.copied); writeText(window.siyuan.config.repo.key);