Merge pull request #1655 from TriliumNext/type_sql-transactional

types: use type variable for sql.transactional's return value
This commit is contained in:
Elian Doran 2025-04-09 12:07:57 +03:00 committed by GitHub
commit c603efb44b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 9 deletions

View File

@ -34,12 +34,10 @@ function getUsedRecoveryCodes() {
const dateRegex = RegExp(/^\d{4}\/\d{2}\/\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/gm);
const recoveryCodes = recovery_codes.getRecoveryCodes();
const usedStatus: string[] = [];
recoveryCodes.forEach((recoveryKey: string) => {
if (dateRegex.test(recoveryKey)) usedStatus.push(recoveryKey);
else usedStatus.push(recoveryCodes.indexOf(recoveryKey));
});
const usedStatus = recoveryCodes.map(recoveryKey => {
return (dateRegex.test(recoveryKey)) ? recoveryKey : String(recoveryCodes.indexOf(recoveryKey))
})
return {
success: true,

View File

@ -27,7 +27,7 @@ function getRecoveryCodes() {
return []
}
return sql.transactional(() => {
return sql.transactional<string[]>(() => {
const iv = Buffer.from(optionService.getOption('recoveryCodeInitialVector'), 'hex');
const securityKey = Buffer.from(optionService.getOption('recoveryCodeSecurityKey'), 'hex');
const encryptedRecoveryCodes = optionService.getOption('recoveryCodesEncrypted');
@ -41,7 +41,7 @@ function getRecoveryCodes() {
}
function removeRecoveryCode(usedCode: string) {
const oldCodes: string[] = getRecoveryCodes();
const oldCodes = getRecoveryCodes();
const today = new Date();
oldCodes[oldCodes.indexOf(usedCode)] = today.toJSON().replace(/-/g, '/');
setRecoveryCodes(oldCodes.toString());
@ -55,7 +55,7 @@ function verifyRecoveryCode(recoveryCodeGuess: string) {
const recoveryCodes = getRecoveryCodes();
let loginSuccess = false;
recoveryCodes.forEach((recoveryCode: string) => {
recoveryCodes.forEach((recoveryCode) => {
if (recoveryCodeGuess === recoveryCode) {
removeRecoveryCode(recoveryCode);
loginSuccess = true;

View File

@ -278,7 +278,7 @@ function transactional<T>(func: (statement: Statement) => T) {
ws.sendTransactionEntityChangesToAllClients();
}
return ret;
return ret as T;
} catch (e) {
console.warn("Got error ", e);
const entityChangeIds = cls.getAndClearEntityChangeIds();