Files
Trilium/apps/client/src/services/sync.ts
T

31 lines
812 B
TypeScript
Raw Normal View History

2025-01-09 18:07:02 +02:00
import { t } from "./i18n.js";
import server from "./server.js";
2019-10-20 10:00:18 +02:00
import toastService from "./toast.js";
2024-12-19 20:58:50 +02:00
// TODO: De-duplicate with server once we have a commons.
interface SyncResult {
success: boolean;
message: string;
errorCode?: string;
}
async function syncNow(ignoreNotConfigured = false) {
2025-01-09 18:07:02 +02:00
const result = await server.post<SyncResult>("sync/now");
if (result.success) {
2024-10-20 02:06:08 +03:00
toastService.showMessage(t("sync.finished-successfully"));
2025-01-09 18:07:02 +02:00
} else {
2020-12-18 21:23:51 +01:00
if (result.message.length > 200) {
result.message = `${result.message.substr(0, 200)}...`;
}
2025-01-09 18:07:02 +02:00
if (!ignoreNotConfigured || result.errorCode !== "NOT_CONFIGURED") {
2024-10-20 02:06:08 +03:00
toastService.showError(t("sync.failed", { message: result.message }));
}
}
}
export default {
2023-07-29 21:59:20 +02:00
syncNow
};