Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor: 💡 fix typo and imporve code quality
Jin2eeb376d24f7
diff --git a/db/schema.sql b/db/schema.sqlindex 2f6a18ef13..8bf9db1e7b 100644--- a/db/schema.sql+++ b/db/schema.sql@@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS "user_data"tmpID INT,username TEXT,email TEXT,- userIDEcnryptedDataKey TEXT,+ userIDEncryptedDataKey TEXT,userIDVerificationHash TEXT,salt TEXT,derivedKey TEXT,diff --git a/src/errors/open_id_error.ts b/src/errors/open_id_error.tsindex bf28e61df8..0206a17f34 100644--- a/src/errors/open_id_error.ts+++ b/src/errors/open_id_error.ts@@ -1,4 +1,4 @@-class OpenIDrror {+class OpenIdError {message: string;constructor(message: string) {@@ -6,4 +6,4 @@ class OpenIDrror {}}-export default OpenIDrror;\ No newline at end of file+export default OpenIdError;\ No newline at end of filediff --git a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_code_type_widget.tsindex dc6184ada3..69bc38bd7f 100644--- a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts+++ b/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts@@ -50,13 +50,6 @@ export default class AbstractCodeTypeWidget extends TypeWidget {matchTags: { bothTags: true },highlightSelectionMatches: { showToken: false, annotateScrollbar: false },lineNumbers: true,- keyMap: "default",- lint: false,- gutters: [],- tabindex: 0,- dragDrop: true,- placeholder: "",- readOnly: false,// we line wrap partly also because without it horizontal scrollbar displays only when you scroll// all the way to the bottom of the note. With line wrap, there's no horizontal scrollbar so no problemlineWrapping: options.is("codeLineWrapEnabled"),diff --git a/src/public/app/widgets/type_widgets/options/multi_factor_authentication.ts b/src/public/app/widgets/type_widgets/options/multi_factor_authentication.tsindex 7d7389c066..b1ff1e0709 100644--- a/src/public/app/widgets/type_widgets/options/multi_factor_authentication.ts+++ b/src/public/app/widgets/type_widgets/options/multi_factor_authentication.ts@@ -6,7 +6,7 @@ import { t } from "../../../services/i18n.js";import utils from "../../../services/utils.js";import dialogService from "../../../services/dialog.js";-const TPL_WEB = `+const TPL = `<div class="options-section"><h4>${t("multi_factor_authentication.title")}</h4><p class="form-text">${t("multi_factor_authentication.description")}</p>@@ -147,7 +147,7 @@ export default class MultiFactorAuthenticationOptions extends OptionsWidget {private $missingVars!: JQuery<HTMLElement>;doRender() {- const template = utils.isElectron() ? TPL_ELECTRON : TPL_WEB;+ const template = utils.isElectron() ? TPL_ELECTRON : TPL;this.$widget = $(template);if (!utils.isElectron()) {diff --git a/src/services/encryption/my_scrypt.ts b/src/services/encryption/my_scrypt.tsindex 1fa0404abe..d1bd9a5361 100644--- a/src/services/encryption/my_scrypt.ts+++ b/src/services/encryption/my_scrypt.ts@@ -21,38 +21,38 @@ function getScryptHash(password: crypto.BinaryLike, salt: crypto.BinaryLike) {}function getSubjectIdentifierVerificationHash(- guessedUserId: string | crypto.BinaryLike,- salt?: string+ guessedUserId: string | crypto.BinaryLike,+ salt?: string) {- if (salt != null) return getScryptHash(guessedUserId, salt);+ if (salt != null) return getScryptHash(guessedUserId, salt);- const savedSalt = sql.getValue("SELECT salt FROM user_data;");- if (savedSalt === undefined || savedSalt === null) {- console.log("User salt undefined!");- return undefined;- }- return getScryptHash(guessedUserId, savedSalt.toString());+ const savedSalt = sql.getValue("SELECT salt FROM user_data;");+ if (!savedSalt) {+ console.error("User salt undefined!");+ return undefined;+ }+ return getScryptHash(guessedUserId, savedSalt.toString());}function getSubjectIdentifierDerivedKey(- subjectIdentifer: crypto.BinaryLike,- givenSalt?: string+ subjectIdentifer: crypto.BinaryLike,+ givenSalt?: string) {- if (givenSalt !== undefined) {- return getScryptHash(subjectIdentifer, givenSalt.toString());- }+ if (givenSalt !== undefined) {+ return getScryptHash(subjectIdentifer, givenSalt.toString());+ }- const salt = sql.getValue("SELECT salt FROM user_data;");- if (salt === undefined || salt === null) return undefined;+ const salt = sql.getValue("SELECT salt FROM user_data;");+ if (!salt) return undefined;- return getScryptHash(subjectIdentifer, salt.toString());+ return getScryptHash(subjectIdentifer, salt.toString());}function createSubjectIdentifierDerivedKey(- subjectIdentifer: string | crypto.BinaryLike,- salt: string | crypto.BinaryLike+ subjectIdentifer: string | crypto.BinaryLike,+ salt: string | crypto.BinaryLike) {- return getScryptHash(subjectIdentifer, salt);+ return getScryptHash(subjectIdentifer, salt);}export default {diff --git a/src/services/encryption/open_id_encryption.ts b/src/services/encryption/open_id_encryption.tsindex b30d5edea4..5dad9c06ba 100644--- a/src/services/encryption/open_id_encryption.ts+++ b/src/services/encryption/open_id_encryption.ts@@ -3,7 +3,7 @@ import utils from "../utils.js";import dataEncryptionService from "./data_encryption.js";import sql from "../sql.js";import sqlInit from "../sql_init.js";-import OpenIDError from "../../errors/open_id_error.js";+import OpenIdError from "../../errors/open_id_error.js";function saveUser(subjectIdentifier: string, name: string, email: string) {if (isUserSaved()) return false;@@ -15,8 +15,8 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {subjectIdentifier,verificationSalt);- if (verificationHash === undefined) {- throw new OpenIDError("Verification hash undefined!")+ if (!verificationHash) {+ throw new OpenIdError("Verification hash undefined!")}const userIDEncryptedDataKey = setDataKey(@@ -25,8 +25,8 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {verificationSalt);- if (userIDEncryptedDataKey === undefined || userIDEncryptedDataKey === null) {- console.log("USERID ENCRYPTED DATA KEY NULL");+ if (!userIDEncryptedDataKey) {+ console.error("UserID encrypted data key null");return undefined;}@@ -35,7 +35,7 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {userIDVerificationHash: utils.toBase64(verificationHash),salt: verificationSalt,derivedKey: derivedKeySalt,- userIDEcnryptedDataKey: userIDEncryptedDataKey,+ userIDEncryptedDataKey: userIDEncryptedDataKey,isSetup: "true",username: name,email: email@@ -46,7 +46,7 @@ function saveUser(subjectIdentifier: string, name: string, email: string) {}function isSubjectIdentifierSaved() {- const value = sql.getValue("SELECT userIDEcnryptedDataKey FROM user_data;");+ const value = sql.getValue("SELECT userIDEncryptedDataKey FROM user_data;");if (value === undefined || value === null || value === "") return false;return true;}@@ -58,7 +58,7 @@ function isUserSaved() {function verifyOpenIDSubjectIdentifier(subjectIdentifier: string) {if (!sqlInit.isDbInitialized()) {- throw new OpenIDError("Database not initialized!");+ throw new OpenIdError("Database not initialized!");}if (isUserSaved()) {@@ -100,7 +100,7 @@ function setDataKey(myScryptService.getSubjectIdentifierDerivedKey(subjectIdentifier, salt);if (subjectIdentifierDerivedKey === undefined) {- console.log("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");+ console.error("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");return undefined;}const newEncryptedDataKey = dataEncryptionService.encrypt(@@ -116,16 +116,16 @@ function getDataKey(subjectIdentifier: string) {myScryptService.getSubjectIdentifierDerivedKey(subjectIdentifier);const encryptedDataKey = sql.getValue(- "SELECT userIDEcnryptedDataKey FROM user_data"+ "SELECT userIDEncryptedDataKey FROM user_data");- if (encryptedDataKey === undefined || encryptedDataKey === null) {- console.log("Encrypted data key empty!");+ if (!encryptedDataKey) {+ console.error("Encrypted data key empty!");return undefined;}- if (subjectIdentifierDerivedKey === undefined) {- console.log("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");+ if (!subjectIdentifierDerivedKey) {+ console.error("SOMETHING WENT WRONG SAVING USER ID DERIVED KEY");return undefined;}const decryptedDataKey = dataEncryptionService.decrypt(diff --git a/src/services/open_id.ts b/src/services/open_id.tsindex 992eeb9d07..e45ed65997 100644--- a/src/services/open_id.ts+++ b/src/services/open_id.ts@@ -126,14 +126,12 @@ function generateOAuthConfig() {return session;}- // 保存用户信息openIDEncryption.saveUser(req.oidc.user.sub.toString(),req.oidc.user.name.toString(),req.oidc.user.email.toString());- // 设置登录状态req.session.loggedIn = true;req.session.lastAuthState = {totpEnabled: false,diff --git a/src/services/sql_init.ts b/src/services/sql_init.tsindex 12b93801a2..afe8324e1b 100644--- a/src/services/sql_init.ts+++ b/src/services/sql_init.ts@@ -52,7 +52,7 @@ async function initDbConnection() {tmpID INT,username TEXT,email TEXT,- userIDEcnryptedDataKey TEXT,+ userIDEncryptedDataKey TEXT,userIDVerificationHash TEXT,salt TEXT,derivedKey TEXT,