Moved consts to folder
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ApiResponse } from '@/types/Api'
|
||||
import type { BikeParking } from '@/types/Bikes'
|
||||
import { API_BASE_URL, API_LIMIT } from '@/utils/const'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const BASE_URL = 'https://data.rennesmetropole.fr/api/explore/v2.1/catalog/datasets/parkings_velos_sur_rennes_metropole/records'
|
||||
const LIMIT = 100
|
||||
|
||||
const res = ref<BikeParking[]>([])
|
||||
|
||||
const firstPage = await fetch(`${BASE_URL}?limit=${LIMIT}`).then(r => r.json()) as ApiResponse
|
||||
const firstPage = await fetch(`${API_BASE_URL}?limit=${API_LIMIT}`).then(r => r.json()) as ApiResponse
|
||||
const { total_count } = firstPage
|
||||
|
||||
const remainingPages = await Promise.all(
|
||||
Array.from(
|
||||
{ length: Math.ceil((total_count - LIMIT) / LIMIT) },
|
||||
(_, i) => fetch(`${BASE_URL}?limit=${LIMIT}&offset=${(i + 1) * LIMIT}`).then(r => r.json()) as Promise<ApiResponse>
|
||||
{ length: Math.ceil((total_count - API_LIMIT) / API_LIMIT) },
|
||||
(_, i) => fetch(`${API_BASE_URL}?limit=${API_LIMIT}&offset=${(i + 1) * API_LIMIT}`).then(r => r.json()) as Promise<ApiResponse>
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
3
src/utils/const.ts
Normal file
3
src/utils/const.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const API_BASE_URL =
|
||||
'https://data.rennesmetropole.fr/api/explore/v2.1/catalog/datasets/parkings_velos_sur_rennes_metropole/records'
|
||||
export const API_LIMIT = 100
|
||||
Reference in New Issue
Block a user