feature: Digitization Workstation UI
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { computed, watch, onUnmounted, type Ref } from 'vue'
|
||||
import { useIntervalFn } from '@vueuse/core'
|
||||
import { useBatchStore } from '../stores/batches'
|
||||
|
||||
const PRESIGNED_URL_TTL_MS = 15 * 60 * 1000
|
||||
const REFRESH_BUFFER_MS = 60_000
|
||||
|
||||
export function usePresignedUrl(batchId: Ref<string | undefined>) {
|
||||
const batchStore = useBatchStore()
|
||||
|
||||
const documentUrl = computed(() => batchStore.documentUrl)
|
||||
|
||||
async function refreshUrl(): Promise<void> {
|
||||
if (batchId.value) {
|
||||
await batchStore.getBatch(batchId.value)
|
||||
}
|
||||
}
|
||||
|
||||
const { pause, resume } = useIntervalFn(
|
||||
() => { void refreshUrl() },
|
||||
PRESIGNED_URL_TTL_MS - REFRESH_BUFFER_MS,
|
||||
{ immediate: false }
|
||||
)
|
||||
|
||||
watch(
|
||||
batchId,
|
||||
async (id) => {
|
||||
pause()
|
||||
if (id) {
|
||||
await refreshUrl()
|
||||
resume()
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
onUnmounted(pause)
|
||||
|
||||
return { documentUrl, refreshUrl }
|
||||
}
|
||||
Reference in New Issue
Block a user