impr: use svelte/reactivity classes for URL, Map, Set

This commit is contained in:
James Xylight committed 2025-08-01 14:18:59 -07:00
1 parent 4680c251d2
commit d1bad1b64e
8 files changed
+21 -38

No files matched your search

+4 -27
View File
@@ -7,6 +7,7 @@ import { toast } from 'mono-svelte'
import { t } from './i18n/translations'
import { site } from './lemmy.svelte'
import { errorMessage } from './lemmy/error'
import { SvelteURL } from 'svelte/reactivity'
// Despite the name, this will round up
// Example: findClosestNumber([8, 16, 32, 64, 128], 76) will return 128
@@ -29,7 +30,7 @@ export const searchParam = (
}
export const fullCommunityName = (name: string, actorId: string) =>
`${name}@${new URL(actorId).hostname}`
`${name}@${new SvelteURL(actorId).hostname}`
export const placeholders = {
url: ['https://example.com'],
@@ -133,30 +134,6 @@ export async function uploadImage(
if (res.url) return res.url
else throw new Error(`Failed to upload image. ${res.msg}`)
} else {
const response = await fetch(
`${
window.location.origin
}/cors/${instance}/pictrs/image?${new URLSearchParams({
auth: jwt,
})}`,
{
method: 'POST',
body: formData,
},
)
const json = await response.json()
if (json.msg == 'ok') {
return `https://${instance}/pictrs/image/${json.files?.[0]?.file}`
}
throw new Error(
`${
(await response.text().catch(() => undefined)) ??
'Failed to upload image'
}: ${response.status}: ${response.statusText}`,
)
}
}
@@ -167,7 +144,7 @@ export const instanceToURL = (input: string) =>
export function canParseUrl(url: string): boolean {
try {
new URL(url)
new SvelteURL(url)
return true
} catch {
return false
@@ -175,7 +152,7 @@ export function canParseUrl(url: string): boolean {
}
export function instanceId(actorId: string) {
return new URL(actorId).hostname
return new SvelteURL(actorId).hostname
}
export function escapeHtml(input: string): string {