2024-06-25 04:31:44 +00:00
|
|
|
import { coreApiClient } from "@halo-dev/api-client";
|
2024-06-26 10:42:50 +00:00
|
|
|
import { nextTick, ref, watch, type Ref } from "vue";
|
2023-08-25 16:18:16 +00:00
|
|
|
|
|
|
|
interface SnapshotContent {
|
|
|
|
version: Ref<number>;
|
|
|
|
handleFetchSnapshot: () => Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useContentSnapshot(
|
|
|
|
snapshotName: Ref<string | undefined>
|
|
|
|
): SnapshotContent {
|
|
|
|
const version = ref(0);
|
|
|
|
watch(snapshotName, () => {
|
|
|
|
nextTick(() => {
|
|
|
|
handleFetchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleFetchSnapshot = async () => {
|
|
|
|
if (!snapshotName.value) {
|
|
|
|
return;
|
|
|
|
}
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } = await coreApiClient.content.snapshot.getSnapshot({
|
|
|
|
name: snapshotName.value,
|
|
|
|
});
|
2023-08-25 16:18:16 +00:00
|
|
|
version.value = data.metadata.version || 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
version,
|
|
|
|
handleFetchSnapshot,
|
|
|
|
};
|
|
|
|
}
|