Rework API calls and each loops

This commit is contained in:
2020-03-16 12:57:53 +01:00
parent ba5d1de780
commit 9965c9dec3
6 changed files with 36 additions and 17 deletions

View File

@@ -4,13 +4,18 @@
// Preload data
export async function preload (page, session) {
// Load random photos
const fields = [
'id', 'name', 'image.private_hash',
'location.id', 'location.name', 'location.slug', 'location.country.name'
]
const sort = '?'
const limit = 5
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=id,name,image.*,location.*,location.country.name&sort=?&limit=${limit}`)
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`)
const photos = await req.json()
if (req.ok) {
return { photos: photos.data }
}
this.error(404, 'Not found')
this.error(404, 'Not found')
}
</script>