Skip to content

Commit

Permalink
fix: remove URL.canParse
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Dec 11, 2024
1 parent b22f325 commit 8ce4702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions apps/renderer/src/atoms/player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getStorageNS } from "@follow/utils/ns"
import { parseSafeUrl } from "@follow/utils/utils"
import { noop } from "foxact/noop"
import { atomWithStorage, createJSONStorage } from "jotai/utils"
import type { SyncStorage } from "jotai/vanilla/utils/atomWithStorage"
Expand Down Expand Up @@ -80,10 +81,8 @@ export const AudioPlayer = {
show: true,
listId: routeParams.listId,
})
const currentUrl = URL.canParse(this.audio.src)
? new URL(this.audio.src).toString()
: this.audio.src
const newUrl = URL.canParse(v.src) ? new URL(v.src).toString() : v.src
const currentUrl = parseSafeUrl(this.audio.src)?.toString() ?? this.audio.src
const newUrl = parseSafeUrl(v.src)?.toString() ?? v.src

if (currentUrl !== newUrl) {
this.audio.src = v.src
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IconButton } from "@follow/components/ui/button/index.js"
import { Checkbox } from "@follow/components/ui/checkbox/index.jsx"
import { Popover, PopoverContent, PopoverTrigger } from "@follow/components/ui/popover/index.jsx"
import { getStorageNS } from "@follow/utils/ns"
import { parseSafeUrl } from "@follow/utils/utils"
import { Label } from "@radix-ui/react-label"
import { PopoverPortal } from "@radix-ui/react-popover"
import { atomWithStorage } from "jotai/utils"
Expand Down Expand Up @@ -37,11 +38,8 @@ const trustedDefaultLinks = new Set([
])

const getURLDomain = (url: string) => {
if (URL.canParse(url)) {
const urlObj = new URL(url)
return urlObj.hostname
}
return null
const urlObj = parseSafeUrl(url)
return urlObj?.hostname ?? null
}

const WarnGoToExternalLinkImpl = forwardRef<
Expand Down

0 comments on commit 8ce4702

Please sign in to comment.