diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts
index 191e3a9..5564da4 100644
--- a/apps/api/src/server.ts
+++ b/apps/api/src/server.ts
@@ -126,22 +126,19 @@ export const app = new Elysia()
.group("/sync", (app) =>
app
// Sync status
- .get("/", async ({ }) => await productSyncer.getState())
+ .get("/", async ({ }) => ({
+ state: await productSyncer.getState(),
+ isRunning: await productSyncer.isRunning()
+ }))
// Full sync
.post("/", async ({ }) => {
- const syncState = await productSyncer.getState();
- if (syncState.isSyncing)
+ if (!await productSyncer.sync())
throw status(409, "Sync already in progress");
-
- await productSyncer.sync();
})
// Per-product sync
.post("/:printfulProductId", async ({ params }) => {
- const syncState = await productSyncer.getState();
- if (syncState.isSyncing)
+ if (!await productSyncer.sync(params.printfulProductId))
throw status(409, "Sync already in progress");
-
- await productSyncer.sync(params.printfulProductId);
}, { params: z.object({ printfulProductId: z.coerce.number() }) }),
)
.get("/:printfulProductId", async ({ params }) => {
diff --git a/apps/portal/src/routes/commerce/+page.svelte b/apps/portal/src/routes/commerce/+page.svelte
index b46ee3d..cd1ade3 100644
--- a/apps/portal/src/routes/commerce/+page.svelte
+++ b/apps/portal/src/routes/commerce/+page.svelte
@@ -6,21 +6,22 @@
const { data } = $props();
const synchronizer = $state({
- isSyncing: false,
- syncingIds: [] as number[],
+ isRunning: false,
+ printfulProductIds: [] as number[],
poll: async function () {
const res = (await (
await fetch(`${PUBLIC_API_URL}/products/sync`)
).json()) as any;
if (res.data) {
- synchronizer.isSyncing = res.data.isSyncing;
- synchronizer.syncingIds = res.data.syncingIds;
+ synchronizer.isRunning = res.data.isRunning;
+ synchronizer.printfulProductIds =
+ res.data.state.printfulProductIds;
}
},
startPolling: () => {
const intervalId = setInterval(async () => {
await synchronizer.poll();
- if (!synchronizer.isSyncing) clearInterval(intervalId);
+ if (!synchronizer.isRunning) clearInterval(intervalId);
}, 100);
},
syncAll: async () => {
@@ -40,7 +41,7 @@
onMount(async () => {
await synchronizer.poll();
- if (synchronizer.isSyncing) {
+ if (synchronizer.isRunning) {
synchronizer.startPolling();
}
});
@@ -59,11 +60,11 @@
Loading...
{:then printfulProducts}