Repository navigation
Task 4639 panoramax support #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { resolveStreetImageUrl, streetImageUrl } from '~/util/street-images'; | ||
|
|
||
| describe('streetImageUrl', () => { | ||
| it('extracts trimmed ext:street_images tag value', () => { | ||
| expect(streetImageUrl({ 'ext:street_images': ' https://panoramax.example.com/api/pictures/1/hd.jpg ' })) | ||
| .toBe('https://panoramax.example.com/api/pictures/1/hd.jpg'); | ||
| }); | ||
|
|
||
| it('extracts trimmed ext:kartaview_url tag value', () => { | ||
| expect(streetImageUrl({ 'ext:kartaview_url': ' https://example.com/img.jpg ' })) | ||
| .toBe('https://example.com/img.jpg'); | ||
| }); | ||
|
|
||
| it('returns undefined when tag is missing or empty', () => { | ||
| expect(streetImageUrl(undefined)).toBeUndefined(); | ||
| expect(streetImageUrl({})).toBeUndefined(); | ||
| expect(streetImageUrl({ 'ext:street_images': ' ' })).toBeUndefined(); | ||
| expect(streetImageUrl({ 'ext:kartaview_url': ' ' })).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('resolveStreetImageUrl', () => { | ||
| it('returns self-hosted Panoramax URLs unchanged', () => { | ||
| const panoramaxUrl = 'https://panoramax-dev-faaadghgcfgwcchk.westus2-01.azurewebsites.net/api/pictures/018ce3ad-d8ed-4c50-846b-a255f6af64ae/hd.jpg'; | ||
| expect(resolveStreetImageUrl(panoramaxUrl)).toBe(panoramaxUrl); | ||
| }); | ||
|
|
||
| it('returns existing KartaView CDN URLs unchanged', () => { | ||
| const cdnUrl = 'https://cdn.kartaview.org/pr:sharp/aHR0cHM6Ly9zdG9yYWdlMTMub3BlbnN0cmVldGNhbS5vcmcvZmlsZXMvcGhvdG8vMS5qcGc'; | ||
| expect(resolveStreetImageUrl(cdnUrl)).toBe(cdnUrl); | ||
| }); | ||
|
|
||
| it('converts legacy OpenStreetCam and KartaView storage URLs to CDN-proxied base64 URLs', () => { | ||
| const legacyOscUrl = 'https://storage13.openstreetcam.org/files/photo/1.jpg'; | ||
| expect(resolveStreetImageUrl(legacyOscUrl)).toBe( | ||
| 'https://cdn.kartaview.org/pr:sharp/aHR0cHM6Ly9zdG9yYWdlMTMub3BlbnN0cmVldGNhbS5vcmcvZmlsZXMvcGhvdG8vMS5qcGc' | ||
| ); | ||
|
|
||
| const legacyKvUrl = 'https://storage.kartaview.org/files/photo/2.jpg'; | ||
| expect(resolveStreetImageUrl(legacyKvUrl)).toBe( | ||
| 'https://cdn.kartaview.org/pr:sharp/aHR0cHM6Ly9zdG9yYWdlLmthcnRhdmlldy5vcmcvZmlsZXMvcGhvdG8vMi5qcGc' | ||
| ); | ||
| }); | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,44 @@ | ||
| import type { OsmTags } from '~/types/osm'; | ||
|
|
||
| export const STREET_IMAGES_TAG = 'ext:street_images'; | ||
| export const KARTAVIEW_URL_TAG = 'ext:kartaview_url'; | ||
|
|
||
| const KARTAVIEW_CDN_PREFIX = 'https://cdn.kartaview.org/pr:sharp/'; | ||
| const LEGACY_KARTAVIEW_HOSTS = ['kartaview.org', 'openstreetcam.org']; | ||
|
|
||
| function isLegacyKartaViewUrl(url: string): boolean { | ||
| try { | ||
| const { hostname } = new URL(url); | ||
| return LEGACY_KARTAVIEW_HOSTS.some( | ||
| domain => hostname === domain || hostname.endsWith(`.${domain}`) | ||
| ); | ||
| } | ||
| catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extracts a street-level image URL from an element's tags (`ext:street_images` | ||
| * or `ext:kartaview_url`) if present. | ||
| */ | ||
| export function streetImageUrl(tags: OsmTags | undefined): string | undefined { | ||
| const value = tags?.[STREET_IMAGES_TAG]?.trim() || tags?.[KARTAVIEW_URL_TAG]?.trim(); | ||
| return value || undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves a street-level image URL for display. Returns standard image URLs | ||
| * (such as self-hosted Panoramax URLs or KartaView CDN URLs) unchanged, and | ||
| * converts legacy KartaView/OpenStreetCam storage URLs to the CDN-proxied form. | ||
| */ | ||
| export function resolveStreetImageUrl(url: string): string { | ||
| const cleanUrl = url.trim(); | ||
| if (cleanUrl.startsWith(KARTAVIEW_CDN_PREFIX) || !isLegacyKartaViewUrl(cleanUrl)) { | ||
| return cleanUrl; | ||
| } | ||
| const bytes = new TextEncoder().encode(cleanUrl); | ||
| const binaryStr = Array.from(bytes, b => String.fromCharCode(b)).join(''); | ||
| const base64 = btoa(binaryStr).replace(/=+$/, ''); | ||
| return `${KARTAVIEW_CDN_PREFIX}${base64}`; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: TaskarCenterAtUW/workspaces-frontend
Length of output: 6750
Preserve KartaView CDN URLs that use an uppercase host or an explicit
:443port.resolveStreetImageUrldetects CDN URLs with a case-sensitive string prefix. Legacy detection uses the parsed hostname. The URL parser lowercases the host and drops the default port, sohttps://CDN.KARTAVIEW.ORG/pr:sharp/…andhttps://cdn.kartaview.org:443/pr:sharp/…fail the prefix check. Their hostname still ends with.kartaview.org, so they are wrapped in a new CDN URL. The function documentation says KartaView CDN URLs are returned unchanged.Add a parsed CDN check and keep the literal check, so existing inputs keep their current result. Add test cases for the uppercase-host and
:443forms.Suggested fix
export function resolveStreetImageUrl(url: string): string { const cleanUrl = url.trim(); - if (cleanUrl.startsWith(KARTAVIEW_CDN_PREFIX) || !isLegacyKartaViewUrl(cleanUrl)) { + if (cleanUrl.startsWith(KARTAVIEW_CDN_PREFIX) || isKartaViewCdnUrl(cleanUrl) || !isLegacyKartaViewUrl(cleanUrl)) { return cleanUrl; }