diff --git a/apps/client/src/widgets/type_widgets/content_widget.tsx b/apps/client/src/widgets/type_widgets/content_widget.tsx index a5178c372..e3ff15330 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_snapshot import 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.tsx index e2d8ec1c2..51667bc62 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 <> + ; } @@ -31,4 +34,36 @@ function AdvancedSyncOptions() { /> ); +} + +function DatabaseIntegrityOptions() { + return ( + + {t("database_integrity_check.description")} + + - - -`; - -// TODO: Deduplicate with server -interface Response { - results: { - integrity_check: string; - }[]; -} - -export default class DatabaseIntegrityCheckOptions extends OptionsWidget { - - private $checkIntegrityButton!: JQuery; - private $findAndFixConsistencyIssuesButton!: JQuery; - - 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("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.ts index 6d2856c23..515bf0bca 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.ts index 7f0e30d67..ce520db83 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; + }[]; +}