Rework API calls and each loops
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user