Refactor decryption logic to handle empty fields consistently across services

This commit is contained in:
natreex
2026-03-22 15:50:36 -04:00
parent 32d2b0fa5a
commit e8aaef108b
26 changed files with 226 additions and 120 deletions

View File

@@ -1,4 +1,5 @@
import React, {useContext, useState} from "react";
import * as tauri from '@/lib/tauri';
import {ChapterProps, chapterVersions} from "@/lib/models/Chapter";
import {ChapterContext} from "@/context/ChapterContext";
import {BookContext} from "@/context/BookContext";
@@ -39,11 +40,16 @@ export default function ScribeControllerBar() {
async function handleChapterVersionChanged(version: number) {
try {
const response: ChapterProps = await System.authGetQueryToServer<ChapterProps>(`chapter/whole`, session.accessToken, lang, {
bookid: book?.bookId,
id: chapter?.chapterId,
version: version,
});
let response: ChapterProps | null;
if (isCurrentlyOffline() || book?.localBook) {
response = await tauri.getWholeChapter(chapter?.chapterId ?? '', version, book?.bookId ?? '');
} else {
response = await System.authGetQueryToServer<ChapterProps>(`chapter/whole`, session.accessToken, lang, {
bookid: book?.bookId,
id: chapter?.chapterId,
version: version,
});
}
if (!response) {
errorMessage(t("controllerBar.chapterNotFound"));
return;

View File

@@ -204,11 +204,9 @@ export default function AddNewBookForm({setCloseForm}: { setCloseForm: Dispatch<
setIsAddingBook(false);
setCloseForm(false)
} catch (e: unknown) {
if (e instanceof Error) {
errorMessage(e.message);
} else {
errorMessage(t('addNewBookForm.error.addingBook'));
}
console.error('[AddBook] Raw error:', e, typeof e, JSON.stringify(e));
const msg = e instanceof Error ? e.message : typeof e === 'object' && e !== null && 'message' in e ? String((e as {message:string}).message) : typeof e === 'string' ? e : t('addNewBookForm.error.addingBook');
errorMessage(msg);
setIsAddingBook(false);
}
}
@@ -250,7 +248,7 @@ export default function AddNewBookForm({setCloseForm}: { setCloseForm: Dispatch<
return (
<div
className="fixed inset-0 flex items-center justify-center bg-black/60 z-50 backdrop-blur-md animate-fadeIn">
className="fixed inset-0 flex items-center justify-center bg-black/60 z-40 backdrop-blur-md animate-fadeIn">
<div ref={modalRef}
className="bg-tertiary/95 backdrop-blur-sm text-text-primary rounded-2xl border border-secondary/50 shadow-2xl md:w-3/4 xl:w-1/4 lg:w-2/4 sm:w-11/12 max-h-[85vh] flex flex-col">
<div className="flex justify-between items-center bg-primary px-6 py-4 rounded-t-2xl shadow-lg">