From 3c364814df5c360da4f2d6f2003cde039beacf5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Wed, 22 Apr 2020 12:01:52 +0200 Subject: [PATCH] Only fetch published photos and locations - Globally for photos - For sitemap locations and photos --- src/routes/index.svelte | 2 +- src/routes/location/[country]/[place].svelte | 2 +- src/routes/sitemap.xml.js | 4 ++-- src/routes/viewer/[country]/[place]/[photo].svelte | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 242cc41..8e50b1b 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -11,7 +11,7 @@ 'location.country.name', 'location.country.slug' ] const sort = '?' // Random sort - const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`, { + const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&status=published&sort=${sort}&limit=${limit}`, { 'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN }) const photos = await req.json() diff --git a/src/routes/location/[country]/[place].svelte b/src/routes/location/[country]/[place].svelte index f48688d..5d1c7dd 100644 --- a/src/routes/location/[country]/[place].svelte +++ b/src/routes/location/[country]/[place].svelte @@ -12,7 +12,7 @@ ].join(',') const sort = ['-created_on', 'name'].join(',') const limit = -1 - const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields}&filter[location.slug][rlike]=%${page.params.place}%&limit=${limit}&sort=${sort}`, { + const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields}&status=published&filter[location.slug][rlike]=%${page.params.place}%&limit=${limit}&sort=${sort}`, { 'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN }) const photos = await req.json() diff --git a/src/routes/sitemap.xml.js b/src/routes/sitemap.xml.js index da8e216..9dfa188 100644 --- a/src/routes/sitemap.xml.js +++ b/src/routes/sitemap.xml.js @@ -47,13 +47,13 @@ export async function get (req, res, next) { baseURL = `http${(req.httpVersion >= 2) ? 's' : ''}://${req.headers.host}` // Get locations - const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on`) + const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published`) const locationsData = await locationsReq.json() const locations = locationsData.data // Add last modified date to each location from its last photo const updatedLocations = locations.map(async (location, i) => { - const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&filter[location.slug][rlike]=%${location.slug}`) + const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&status=published&filter[location.slug][rlike]=%${location.slug}`) const latestPhotoData = await latestPhotoReq.json() const latestPhoto = latestPhotoData.data[0] location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on diff --git a/src/routes/viewer/[country]/[place]/[photo].svelte b/src/routes/viewer/[country]/[place]/[photo].svelte index 19d421f..5e892b3 100644 --- a/src/routes/viewer/[country]/[place]/[photo].svelte +++ b/src/routes/viewer/[country]/[place]/[photo].svelte @@ -12,7 +12,7 @@ 'location.id', 'location.name', 'location.slug', 'location.country.name', 'location.country.slug' ] - const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&filter[location.slug][rlike]=%${page.params.place}%`, { + const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&status=published&filter[location.slug][rlike]=%${page.params.place}%`, { 'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN }) const photos = await req.json()