From 2eeb376d24f76007e7d16e3b66a300fea0b9914a Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Sat, 29 Mar 2025 01:00:08 +0100
Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20fix=20typo=20and=20i?=
=?UTF-8?q?mporve=20code=20quality?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
db/schema.sql | 2 +-
src/errors/open_id_error.ts | 4 +-
.../type_widgets/abstract_code_type_widget.ts | 7 ----
.../options/multi_factor_authentication.ts | 4 +-
src/services/encryption/my_scrypt.ts | 40 +++++++++----------
src/services/encryption/open_id_encryption.ts | 28 ++++++-------
src/services/open_id.ts | 2 -
src/services/sql_init.ts | 2 +-
8 files changed, 40 insertions(+), 49 deletions(-)
diff --git a/db/schema.sql b/db/schema.sql
index 2f6a18ef1..8bf9db1e7 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.ts
index bf28e61df..0206a17f3 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 file
diff --git a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts
index dc6184ada..69bc38bd7 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 problem
lineWrapping: 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.ts
index 7d7389c06..b1ff1e070 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 = `
${t("multi_factor_authentication.title")}
${t("multi_factor_authentication.description")}
@@ -147,7 +147,7 @@ export default class MultiFactorAuthenticationOptions extends OptionsWidget {
private $missingVars!: JQuery
;
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.ts
index 1fa0404ab..d1bd9a536 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.ts
index b30d5edea..5dad9c06b 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.ts
index 992eeb9d0..e45ed6599 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.ts
index 12b93801a..afe8324e1 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,