Start sync with POST and show progress when a sync is running

Closes #1
This commit is contained in:
Sansan committed 2026-10-06 18:57:02 +02:00
1 parent f972b579fc
commit 2e7be01487
1 file changed
+8 -17
+8 -17
View File
@@ -46,25 +46,17 @@ export default {
}, },
async startSync() { async startSync() {
try { try {
// Start the sync await this.APIsyncSoundtracks();
const response = await this.APIsyncSoundtracks(); } catch (error) {
// Check if sync was actually started or if one is in progress // 423 means a sync is already running: show its progress
if (response && (response.status === 423 || (response.data && response.data.includes("in progress")))) { if (!error.response || error.response.status !== 423) {
// Sync is already in progress - show modal with polling console.error("Failed to start sync:", error);
this.syncInProgress = true; return;
} else { }
this.syncInProgress = true;
} }
// Show the modal which will poll for progress // Show the modal which will poll for progress
this.showSyncModal = true;
} catch (error) {
console.error("Failed to start sync:", error);
// If error is 423, sync is already in progress
if (error.response && error.response.status === 423) {
this.syncInProgress = true; this.syncInProgress = true;
this.showSyncModal = true; this.showSyncModal = true;
}
}
}, },
handleSyncButtonClick() { handleSyncButtonClick() {
// If we have a completed sync result, just show it // If we have a completed sync result, just show it
@@ -119,14 +111,13 @@ export default {
APIsyncSoundtracks() { APIsyncSoundtracks() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.axios({ this.axios({
method: "get", method: "post",
url: `${window.__RUNTIME_CONFIG__.API_HOSTNAME}/sync`, url: `${window.__RUNTIME_CONFIG__.API_HOSTNAME}/sync`,
}) })
.then((response) => { .then((response) => {
resolve(response); resolve(response);
}) })
.catch(function(error) { .catch(function(error) {
console.log(error);
reject(error); reject(error);
}); });
}); });