Skip to content

Commit

Permalink
fix(getItemApiUrl): fix missing ?f=json
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/hub-common

ISSUES CLOSED: #330
  • Loading branch information
tomwayson committed Aug 25, 2020
1 parent 1a250d8 commit 083ee02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 3 additions & 9 deletions packages/common/src/urls/get-item-api-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ export const getItemApiUrl = (
typeof portalOrUrl === "string" ? portalOrUrl : getPortalUrl(portalOrUrl);
// TODO: handle case where Portal API url is passed in?
// const portalUrl = parsePortalUrl(portalRestUrl);
const path = `/sharing/rest/content/items/${id}`;
// TODO: append f param based on item.type?
let query;
let url = `${host}/sharing/rest/content/items/${id}?f=json`;
if (access !== "public") {
query = { token };
url = `${url}&token=${token}`;
}
return buildUrl({
host,
path,
query
});
return url;
};
8 changes: 5 additions & 3 deletions packages/common/src/urls/get-item-data-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const getItemDataUrl = (
token?: string
) => {
const url = getItemApiUrl(item, portalOrUrl, token);
const segment = `/${item.id}`;
const regExp = new RegExp(segment);
return url && url.replace(regExp, `${segment}/data`);
const pattern = `\\/${item.id}\\?f=json`;
const regExp = new RegExp(pattern);
return (
url && url.replace(regExp, `/${item.id}/data`).replace(/\&token/, "?token")
);
};

0 comments on commit 083ee02

Please sign in to comment.