Skip to content
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

don't be so fragile when comparing marketplace URLs #2040

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/projects/shared/src/util/misc.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export function removeTrailingSlash(word: string): string {
return word.replace(/\/+$/, '')
}

export function sameUrl(u1: string, u2: string): boolean {
return new URL(u1).toString() === new URL(u2).toString()
}

export function isValidHttpUrl(string: string): boolean {
try {
const _ = new URL(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PipeTransform,
} from '@angular/core'
import { ConfigService } from 'src/app/services/config.service'
import { sameUrl } from '@start9labs/shared'

@Component({
selector: 'store-icon',
Expand All @@ -26,9 +27,9 @@ export class GetIconPipe implements PipeTransform {
transform(url: string): string | null {
const { start9, community } = this.config.marketplace

if (url === start9) {
if (sameUrl(url, start9)) {
return 'assets/img/icon.png'
} else if (url === community) {
} else if (sameUrl(url, community)) {
return 'assets/img/community-store.png'
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ModalController,
} from '@ionic/angular'
import { ActionSheetButton } from '@ionic/core'
import { ErrorToastService } from '@start9labs/shared'
import { ErrorToastService, sameUrl } from '@start9labs/shared'
import { AbstractMarketplaceService } from '@start9labs/marketplace'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { ValueSpecObject } from 'src/app/pkg-config/config-types'
Expand All @@ -31,7 +31,7 @@ export class MarketplaceSettingsPage {
map(([stores, selected]) => {
const toSlice = stores.map(s => ({
...s,
selected: s.url === selected.url,
selected: sameUrl(s.url, selected.url),
}))
// 0 and 1 are prod and community
const standard = toSlice.slice(0, 1)
Expand Down
5 changes: 3 additions & 2 deletions frontend/projects/ui/src/app/pages/updates/updates.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
MarketplacePkg,
StoreIdentity,
} from '@start9labs/marketplace'
import { Emver, isEmptyObject } from '@start9labs/shared'
import { Emver, isEmptyObject, sameUrl } from '@start9labs/shared'
import { Pipe, PipeTransform } from '@angular/core'
import { combineLatest, Observable } from 'rxjs'
import { PrimaryRendering } from '../../services/pkg-status-rendering.service'
Expand Down Expand Up @@ -194,7 +194,8 @@ export function marketplaceSame(
local: Record<string, PackageDataEntry>,
url: string,
): boolean {
return local[id]?.installed?.['marketplace-url'] === url
const localUrl = local[id]?.installed?.['marketplace-url'] || ''
return sameUrl(localUrl, url)
}

export function versionLower(
Expand Down
3 changes: 2 additions & 1 deletion frontend/projects/ui/src/app/services/marketplace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
tap,
} from 'rxjs/operators'
import { ConfigService } from './config.service'
import { sameUrl } from '@start9labs/shared'

@Injectable()
export class MarketplaceService implements AbstractMarketplaceService {
Expand Down Expand Up @@ -68,7 +69,7 @@ export class MarketplaceService implements AbstractMarketplaceService {
startWith<StoreIdentity[]>([]),
pairwise(),
mergeMap(([prev, curr]) =>
curr.filter(c => !prev.find(p => c.url === p.url)),
curr.filter(c => !prev.find(p => sameUrl(c.url, p.url))),
),
mergeMap(({ url, name }) =>
this.fetchStore$(url).pipe(
Expand Down