fix: load complete temporal dataset inventory
This commit is contained in:
@@ -20,9 +20,35 @@ import type {
|
||||
OrthophotoProductRead,
|
||||
} from '../../types'
|
||||
|
||||
const DATASET_PAGE_SIZE = 200
|
||||
|
||||
async function listProjectDatasets(projectId: string): Promise<DatasetListResponse> {
|
||||
const items: DatasetCreateResponse[] = []
|
||||
let offset = 0
|
||||
let total: number | null = null
|
||||
do {
|
||||
const page = await apiGet<DatasetListResponse>(
|
||||
`/api/v1/projects/${projectId}/datasets?limit=${DATASET_PAGE_SIZE}&offset=${offset}`,
|
||||
)
|
||||
if (total === null) {
|
||||
total = page.total
|
||||
} else if (page.total !== total) {
|
||||
throw new Error('De datasetlijst wijzigde tijdens het laden. Vernieuw de werkruimte.')
|
||||
}
|
||||
items.push(...page.items)
|
||||
if (page.items.length === 0) {
|
||||
break
|
||||
}
|
||||
offset += page.items.length
|
||||
} while (offset < (total ?? 0))
|
||||
if (total !== null && items.length !== total) {
|
||||
throw new Error(`Niet alle datasets konden worden geladen (${items.length}/${total}).`)
|
||||
}
|
||||
return { items, total: total ?? 0, limit: items.length, offset: 0 }
|
||||
}
|
||||
|
||||
export const datasetsApi = {
|
||||
list: (projectId: string): Promise<DatasetListResponse> =>
|
||||
apiGet<DatasetListResponse>(`/api/v1/projects/${projectId}/datasets`),
|
||||
list: listProjectDatasets,
|
||||
upload: (
|
||||
projectId: string,
|
||||
payload: {
|
||||
|
||||
Reference in New Issue
Block a user