feat: snapshot realization update for polling usage

This commit is contained in:
2025-11-24 16:16:57 +03:00
parent 85c71563c1
commit 04a9ac452e
5 changed files with 70 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
import { authInstance } from "@shared";
import { v4 as uuidv4 } from "uuid";
import { makeAutoObservable, runInAction } from "mobx";
import {
articlesStore,
@@ -25,9 +25,18 @@ type Snapshot = {
CreationTime: string;
};
type SnapshotStatus = {
ID: string;
Status: string;
Progress: number;
Error: string;
};
class SnapshotStore {
snapshots: Snapshot[] = [];
snapshot: Snapshot | null = null;
lastRequestId: string | null = null;
snapshotStatus: SnapshotStatus | null = null;
constructor() {
makeAutoObservable(this);
@@ -266,7 +275,27 @@ class SnapshotStore {
};
createSnapshot = async (name: string) => {
await authInstance.post(`/snapshots`, { name });
this.lastRequestId = uuidv4();
const response = await authInstance.post(
`/snapshots`,
{ name },
{ headers: { "X-Request-ID": this.lastRequestId } }
);
// Не ждем здесь, так как статус будет загружен в компоненте
// this.getSnapshotStatus(response.data.ID);
return response.data.ID;
};
getSnapshotStatus = async (id: string) => {
const response = await authInstance.get(`/snapshots/status/${id}`);
console.log(response.data);
runInAction(() => {
this.snapshotStatus = response.data;
});
};
}