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";
|
2017-11-04 21:21:09 -04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 20:22:50 +01:00
|
|
|
async function syncNow(ignoreNotConfigured = false) {
|
2025-01-09 18:07:02 +02:00
|
|
|
const result = await server.post<SyncResult>("sync/now");
|
2017-11-28 20:52:38 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
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) {
|
2022-12-21 15:19:05 +01:00
|
|
|
result.message = `${result.message.substr(0, 200)}...`;
|
2018-03-24 23:58:58 -04:00
|
|
|
}
|
2018-03-25 11:09:17 -04:00
|
|
|
|
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 }));
|
2022-01-13 20:22:50 +01:00
|
|
|
}
|
2017-11-28 20:52:38 -05:00
|
|
|
}
|
2018-03-25 11:09:17 -04:00
|
|
|
}
|
2017-12-30 21:44:26 -05:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
export default {
|
2023-07-29 21:59:20 +02:00
|
|
|
syncNow
|
2020-06-13 10:23:36 +02:00
|
|
|
};
|