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
feat(react/settings): port integrity check
Elian Dorana04f6e38587a
diff --git a/apps/client/src/widgets/type_widgets/content_widget.tsx b/apps/client/src/widgets/type_widgets/content_widget.tsxindex a5178c372e..e3ff15330d 100644--- a/apps/client/src/widgets/type_widgets/content_widget.tsx+++ b/apps/client/src/widgets/type_widgets/content_widget.tsx@@ -21,8 +21,6 @@ import RevisionsSnapshotIntervalOptions from "./options/other/revisions_snapshotimport RevisionSnapshotsLimitOptions from "./options/other/revision_snapshots_limit.js";import NetworkConnectionsOptions from "./options/other/network_connections.js";import HtmlImportTagsOptions from "./options/other/html_import_tags.js";-import AdvancedSyncOptions from "./options/advanced/sync.js";-import DatabaseIntegrityCheckOptions from "./options/advanced/database_integrity_check.js";import VacuumDatabaseOptions from "./options/advanced/vacuum_database.js";import DatabaseAnonymizationOptions from "./options/advanced/database_anonymization.js";import BackendLogWidget from "./content/backend_log.js";diff --git a/apps/client/src/widgets/type_widgets/options/advanced.tsx b/apps/client/src/widgets/type_widgets/options/advanced.tsxindex e2d8ec1c2c..51667bc624 100644--- a/apps/client/src/widgets/type_widgets/options/advanced.tsx+++ b/apps/client/src/widgets/type_widgets/options/advanced.tsx@@ -1,12 +1,15 @@+import { DatabaseCheckIntegrityResponse } from "@triliumnext/commons";import { t } from "../../../services/i18n";import server from "../../../services/server";import toast from "../../../services/toast";import Button from "../../react/Button";+import FormText from "../../react/FormText";import OptionsSection from "./components/OptionsSection"export default function AdvancedSettings() {return <><AdvancedSyncOptions />+ <DatabaseIntegrityOptions /></>;}@@ -31,4 +34,36 @@ function AdvancedSyncOptions() {/></OptionsSection>);+}++function DatabaseIntegrityOptions() {+ return (+ <OptionsSection title={t("database_integrity_check.title")}>+ <FormText>{t("database_integrity_check.description")}</FormText>++ <Button+ text={t("database_integrity_check.check_button")}+ onClick={async () => {+ toast.showMessage(t("database_integrity_check.checking_integrity"));++ const { results } = await server.get<DatabaseCheckIntegrityResponse>("database/check-integrity");++ if (results.length === 1 && results[0].integrity_check === "ok") {+ toast.showMessage(t("database_integrity_check.integrity_check_succeeded"));+ } else {+ toast.showMessage(t("database_integrity_check.integrity_check_failed", { results: JSON.stringify(results, null, 2) }), 15000);+ }+ }}+ />++ <Button+ text={t("consistency_checks.find_and_fix_button")}+ onClick={async () => {+ toast.showMessage(t("consistency_checks.finding_and_fixing_message"));+ await server.post("database/find-and-fix-consistency-issues");+ toast.showMessage(t("consistency_checks.issues_fixed_message"));+ }}+ />+ </OptionsSection>+ )}\ No newline at end of filediff --git a/apps/client/src/widgets/type_widgets/options/advanced/database_integrity_check.ts b/apps/client/src/widgets/type_widgets/options/advanced/database_integrity_check.tsdeleted file mode 100644index 02eaba69c1..0000000000--- a/apps/client/src/widgets/type_widgets/options/advanced/database_integrity_check.ts+++ /dev/null@@ -1,53 +0,0 @@-import OptionsWidget from "../options_widget.js";-import toastService from "../../../../services/toast.js";-import server from "../../../../services/server.js";-import { t } from "../../../../services/i18n.js";--const TPL = /*html*/`-<div class="options-section">- <h4>${t("database_integrity_check.title")}</h4>-- <p class="form-text">${t("database_integrity_check.description")}</p>-- <button class="check-integrity-button btn btn-secondary">${t("database_integrity_check.check_button")}</button>- <button class="find-and-fix-consistency-issues-button btn btn-secondary">${t("consistency_checks.find_and_fix_button")}</button>-</div>-`;--// TODO: Deduplicate with server-interface Response {- results: {- integrity_check: string;- }[];-}--export default class DatabaseIntegrityCheckOptions extends OptionsWidget {-- private $checkIntegrityButton!: JQuery<HTMLElement>;- private $findAndFixConsistencyIssuesButton!: JQuery<HTMLElement>;-- doRender() {- this.$widget = $(TPL);- this.$checkIntegrityButton = this.$widget.find(".check-integrity-button");- this.$checkIntegrityButton.on("click", async () => {- toastService.showMessage(t("database_integrity_check.checking_integrity"));-- const { results } = await server.get<Response>("database/check-integrity");-- if (results.length === 1 && results[0].integrity_check === "ok") {- toastService.showMessage(t("database_integrity_check.integrity_check_succeeded"));- } else {- toastService.showMessage(t("database_integrity_check.integrity_check_failed", { results: JSON.stringify(results, null, 2) }), 15000);- }- });-- this.$findAndFixConsistencyIssuesButton = this.$widget.find(".find-and-fix-consistency-issues-button");- this.$findAndFixConsistencyIssuesButton.on("click", async () => {- toastService.showMessage(t("consistency_checks.finding_and_fixing_message"));-- await server.post("database/find-and-fix-consistency-issues");-- toastService.showMessage(t("consistency_checks.issues_fixed_message"));- });- }-}diff --git a/apps/server/src/routes/api/database.ts b/apps/server/src/routes/api/database.tsindex 6d2856c23c..515bf0bca5 100644--- a/apps/server/src/routes/api/database.ts+++ b/apps/server/src/routes/api/database.ts@@ -9,6 +9,7 @@ import type { Request } from "express";import ValidationError from "../../errors/validation_error.js";import sql_init from "../../services/sql_init.js";import becca_loader from "../../becca/becca_loader.js";+import { DatabaseCheckIntegrityResponse } from "@triliumnext/commons";function getExistingBackups() {return backupService.getExistingBackups();@@ -48,13 +49,13 @@ async function anonymize(req: Request) {}function checkIntegrity() {- const results = sql.getRows("PRAGMA integrity_check");+ const results = sql.getRows<{ integrity_check: string }>("PRAGMA integrity_check");log.info(`Integrity check result: ${JSON.stringify(results)}`);return {results- };+ } satisfies DatabaseCheckIntegrityResponse;}export default {diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 7f0e30d67b..ce520db836 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -61,3 +61,9 @@ export interface RecentChangeRow {export interface BulkActionAffectedNotes {affectedNoteCount: number;}++export interface DatabaseCheckIntegrityResponse {+ results: {+ integrity_check: string;+ }[];+}