-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IPortal } from "@esri/arcgis-rest-portal"; | ||
import { getPortalUrl } from "../urls/get-portal-url"; | ||
|
||
/** | ||
* Construct a the full url to a portal thumbnail | ||
* | ||
* - If the portal has a thumbnail, construct the full url | ||
* - If the portal is not public, append on the token | ||
* @param portal | ||
* @param token | ||
* @returns | ||
*/ | ||
export function getOrgThumbnailUrl(portal: IPortal, token?: string): string { | ||
let thumbnailUrl = null; | ||
if (portal?.thumbnail) { | ||
const portalUrl = getPortalUrl(portal); | ||
thumbnailUrl = `${portalUrl}/sharing/rest/portals/${portal.id}/resources/${portal.thumbnail}`; | ||
if (token && portal.access !== "public") { | ||
thumbnailUrl = `${thumbnailUrl}?token=${token}`; | ||
} | ||
} | ||
return thumbnailUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/common/test/resources/get-portal-thumbnail-url.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getOrgThumbnailUrl } from "../../src"; | ||
import { IPortal } from "@esri/arcgis-rest-portal"; | ||
|
||
describe("getPortalThumbnailUrl:", () => { | ||
const token = "FAKE_TOKEN"; | ||
it("returns null if no thumbnail present", () => { | ||
const portal = {} as IPortal; | ||
expect(getOrgThumbnailUrl(portal, token)).toBeNull(); | ||
}); | ||
it("constructs url without token for public portals", () => { | ||
const portal = { | ||
id: "abc123", | ||
access: "public", | ||
thumbnail: "photo.jpg", | ||
isPortal: true, | ||
name: "jsmith", | ||
} as IPortal; | ||
expect(getOrgThumbnailUrl(portal, token)).toEqual( | ||
"https://www.arcgis.com/sharing/rest/portals/abc123/resources/photo.jpg" | ||
); | ||
}); | ||
it("constructs url with token for non-public portals", () => { | ||
const portal = { | ||
id: "abc123", | ||
access: "org", | ||
thumbnail: "photo.jpg", | ||
isPortal: true, | ||
name: "jsmith", | ||
} as IPortal; | ||
expect(getOrgThumbnailUrl(portal, token)).toEqual( | ||
"https://www.arcgis.com/sharing/rest/portals/abc123/resources/photo.jpg?token=FAKE_TOKEN" | ||
); | ||
}); | ||
}); |