mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 11:56:01 +01:00
feat(react/settings): port sync test
This commit is contained in:
@@ -7,8 +7,21 @@ import FormTextBox, { FormTextBoxWithUnit } from "../../react/FormTextBox";
|
|||||||
import RawHtml from "../../react/RawHtml";
|
import RawHtml from "../../react/RawHtml";
|
||||||
import OptionsSection from "./components/OptionsSection";
|
import OptionsSection from "./components/OptionsSection";
|
||||||
import { useTriliumOptions } from "../../react/hooks";
|
import { useTriliumOptions } from "../../react/hooks";
|
||||||
|
import FormText from "../../react/FormText";
|
||||||
|
import server from "../../../services/server";
|
||||||
|
import toast from "../../../services/toast";
|
||||||
|
import { SyncTestResponse } from "@triliumnext/commons";
|
||||||
|
|
||||||
export default function SyncOptions() {
|
export default function SyncOptions() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SyncConfiguration />
|
||||||
|
<SyncTest />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SyncConfiguration() {
|
||||||
const [ options, setOptions ] = useTriliumOptions("syncServerHost", "syncServerTimeout", "syncProxy");
|
const [ options, setOptions ] = useTriliumOptions("syncServerHost", "syncServerTimeout", "syncProxy");
|
||||||
const syncServerHost = useRef(options.syncServerHost);
|
const syncServerHost = useRef(options.syncServerHost);
|
||||||
const syncServerTimeout = useRef(options.syncServerTimeout);
|
const syncServerTimeout = useRef(options.syncServerTimeout);
|
||||||
@@ -60,3 +73,23 @@ export default function SyncOptions() {
|
|||||||
</OptionsSection>
|
</OptionsSection>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function SyncTest() {
|
||||||
|
return (
|
||||||
|
<OptionsSection title={t("sync_2.test_title")}>
|
||||||
|
<FormText>{t("sync_2.test_description")}</FormText>
|
||||||
|
<Button
|
||||||
|
text={t("sync_2.test_button")}
|
||||||
|
onClick={async () => {
|
||||||
|
const result = await server.post<SyncTestResponse>("sync/test");
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.showMessage(result.message);
|
||||||
|
} else {
|
||||||
|
toast.showError(t("sync_2.handshake_failed", { message: result.error }));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</OptionsSection>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -16,8 +16,9 @@ import type { EntityChange } from "../../services/entity_changes_interface.js";
|
|||||||
import ValidationError from "../../errors/validation_error.js";
|
import ValidationError from "../../errors/validation_error.js";
|
||||||
import consistencyChecksService from "../../services/consistency_checks.js";
|
import consistencyChecksService from "../../services/consistency_checks.js";
|
||||||
import { t } from "i18next";
|
import { t } from "i18next";
|
||||||
|
import { SyncTestResponse } from "@triliumnext/commons";
|
||||||
|
|
||||||
async function testSync() {
|
async function testSync(): Promise<SyncTestResponse> {
|
||||||
try {
|
try {
|
||||||
if (!syncOptions.isSyncSetup()) {
|
if (!syncOptions.isSyncSetup()) {
|
||||||
return { success: false, message: t("test_sync.not-configured") };
|
return { success: false, message: t("test_sync.not-configured") };
|
||||||
|
|||||||
@@ -77,3 +77,11 @@ export interface AnonymizedDbResponse {
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SyncTestResponse = {
|
||||||
|
success: true;
|
||||||
|
message: string;
|
||||||
|
} | {
|
||||||
|
success: false;
|
||||||
|
error: string;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user