Skip to content

Commit

Permalink
WIP: fix url
Browse files Browse the repository at this point in the history
  • Loading branch information
wri7tno committed Nov 2, 2023
1 parent e5c92af commit b13905a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion components/widgets/land-cover/fao-cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export default {
})
);
},
getDataURL: ({ params }) => [getFAOExtent({ ...params, download: true })],
getDataURL: async ({ params }) => [
await getFAOExtent({ ...params, download: true }),
],
getWidgetProps,
};
15 changes: 9 additions & 6 deletions services/forest-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cartoRequest, dataRequest, DATA_API_URL } from 'utils/request';
import { cartoRequest, dataRequest } from 'utils/request';
import { PROXIES } from 'utils/proxies';

import globalLandCoverCategories from 'data/global-land-cover-categories.json';

Expand Down Expand Up @@ -45,17 +46,19 @@ const getLocationQuery = (adm0, adm1, adm2) =>
}`;

export const getFAOExtent = async ({ adm0, faoYear = 2020, download }) => {
const target = download ? 'csv' : 'json';
const target = download ? 'download/csv' : 'query/json';

const url =
`/dataset/fao_forest_extent/v2020/query/${target}?sql=${NEW_SQL_QUERIES.faoExtent}`
.replace('{location}', adm0 ? `iso = '${adm0}'` : '1 = 1')
.replace('{year}', faoYear);
`/dataset/fao_forest_extent/v2020/${target}?sql=${NEW_SQL_QUERIES.faoExtent}`
.replace(/{location}/g, adm0 ? `iso = '${adm0}'` : '1 = 1')
.replace(/{year}/g, faoYear);

if (download) {
return {
name: 'fao_treecover_extent__ha',
url: `${DATA_API_URL}${url}`,
url: new URL(
`${window.location.origin}${PROXIES.DATA_API}${url}`
).toString(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ENVIRONMENT = process.env.NEXT_PUBLIC_FEATURE_ENV;
const GFW_API_URL = ENVIRONMENT === 'staging' ? GFW_STAGING_API : GFW_API;
const GFW_METADATA_API_URL =
ENVIRONMENT === 'staging' ? GFW_STAGING_METADATA_API : GFW_METADATA_API;
export const DATA_API_URL =
const DATA_API_URL =
ENVIRONMENT === 'staging' ? GFW_STAGING_DATA_API : GFW_DATA_API;

// We never use the `staging-api.resourcewatch.org`.
Expand Down

0 comments on commit b13905a

Please sign in to comment.