mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-11 03:17:02 +00:00
Remove space blossom detection
This commit is contained in:
@@ -1,49 +1,14 @@
|
||||
<script lang="ts">
|
||||
import {onDestroy} from "svelte"
|
||||
import {now} from "@welshman/lib"
|
||||
import {BLOSSOM_AUTH, makeEvent, getTags, getTagValue, tagsFromIMeta} from "@welshman/util"
|
||||
import {signer} from "@welshman/app"
|
||||
import {getTags, getTagValue, tagsFromIMeta} from "@welshman/util"
|
||||
import {imgproxy} from "@app/state"
|
||||
|
||||
const {value, event, ...props} = $props()
|
||||
|
||||
const url = value.url.toString()
|
||||
|
||||
// If we fail to fetch the image, try authenticating if we have a blossom hash
|
||||
const onerror = async () => {
|
||||
const meta = getTags("imeta", event.tags)
|
||||
.map(tagsFromIMeta)
|
||||
.find(meta => getTagValue("url", meta) === url)
|
||||
const hash = meta ? getTagValue("x", meta) : undefined
|
||||
|
||||
if (hash && $signer) {
|
||||
const event = await signer.get().sign(
|
||||
makeEvent(BLOSSOM_AUTH, {
|
||||
tags: [
|
||||
["t", "get"],
|
||||
["x", hash],
|
||||
["expiration", String(now() + 30)],
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
Authorization: `Nostr ${btoa(JSON.stringify(event))}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (res.status === 200) {
|
||||
src = URL.createObjectURL(await res.blob())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let src = $state(imgproxy(url))
|
||||
|
||||
onDestroy(() => {
|
||||
URL.revokeObjectURL(src)
|
||||
})
|
||||
const meta = getTags("imeta", event.tags)
|
||||
.map(tagsFromIMeta)
|
||||
.find(meta => getTagValue("url", meta) === url)
|
||||
const src = imgproxy(url)
|
||||
</script>
|
||||
|
||||
<img alt="" {src} {onerror} {...props} />
|
||||
<img alt="" {src} {...props} />
|
||||
|
||||
@@ -2,59 +2,18 @@ import {mount} from "svelte"
|
||||
import type {Writable} from "svelte/store"
|
||||
import {get} from "svelte/store"
|
||||
import type {StampedEvent} from "@welshman/util"
|
||||
import {makeEvent, getTagValues, getListTags, BLOSSOM_AUTH} from "@welshman/util"
|
||||
import {simpleCache, normalizeUrl, removeNil, now} from "@welshman/lib"
|
||||
import {getTagValues, getListTags} from "@welshman/util"
|
||||
import {Router} from "@welshman/router"
|
||||
import {signer, profileSearch, userBlossomServers} from "@welshman/app"
|
||||
import {Editor, MentionSuggestion, WelshmanExtension} from "@welshman/editor"
|
||||
import {makeMentionNodeView} from "./MentionNodeView"
|
||||
import ProfileSuggestion from "./ProfileSuggestion.svelte"
|
||||
|
||||
export const hasBlossomSupport = simpleCache(async ([url]: [string]) => {
|
||||
const $signer = signer.get()
|
||||
const headers: Record<string, string> = {
|
||||
"X-Content-Type": "text/plain",
|
||||
"X-Content-Length": "1",
|
||||
"X-SHA-256": "73cb3858a687a8494ca3323053016282f3dad39d42cf62ca4e79dda2aac7d9ac",
|
||||
}
|
||||
|
||||
try {
|
||||
if ($signer) {
|
||||
const event = await signer.get().sign(
|
||||
makeEvent(BLOSSOM_AUTH, {
|
||||
tags: [
|
||||
["t", "upload"],
|
||||
["server", url],
|
||||
["expiration", String(now() + 30)],
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
||||
headers.Authorization = `Nostr ${btoa(JSON.stringify(event))}`
|
||||
}
|
||||
|
||||
const res = await fetch(normalizeUrl(url) + "/upload", {method: "head", headers})
|
||||
|
||||
return res.status === 200
|
||||
} catch (e) {
|
||||
if (!String(e).includes("Failed to fetch")) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
export const getUploadUrl = async (spaceUrl?: string) => {
|
||||
export const getUploadUrl = () => {
|
||||
const userUrls = getTagValues("server", getListTags(userBlossomServers.get()))
|
||||
const allUrls = removeNil([spaceUrl, ...userUrls])
|
||||
|
||||
for (let url of allUrls) {
|
||||
url = url.replace(/^ws/, "http")
|
||||
|
||||
if (await hasBlossomSupport(url)) {
|
||||
return url
|
||||
}
|
||||
for (const url of userUrls) {
|
||||
return url.replace(/^ws/, "http")
|
||||
}
|
||||
|
||||
return "https://cdn.satellite.earth"
|
||||
@@ -98,7 +57,7 @@ export const makeEditor = async ({
|
||||
submit,
|
||||
sign: signWithAssert,
|
||||
defaultUploadType: "blossom",
|
||||
defaultUploadUrl: await getUploadUrl(url),
|
||||
defaultUploadUrl: getUploadUrl(),
|
||||
extensions: {
|
||||
placeholder: {
|
||||
config: {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
|
||||
import {pushToast} from "@app/toast"
|
||||
import {pushModal} from "@app/modal"
|
||||
import {getUploadUrl} from "@app/editor"
|
||||
import {setChecked} from "@app/notifications"
|
||||
import {checkRelayConnection, checkRelayAuth, checkRelayAccess} from "@app/commands"
|
||||
import {decodeRelay, userRoomsByUrl} from "@app/state"
|
||||
@@ -53,9 +52,6 @@
|
||||
onMount(() => {
|
||||
checkConnection()
|
||||
|
||||
// Prime our cache so inputs show up quickly
|
||||
getUploadUrl(url)
|
||||
|
||||
const relays = [url]
|
||||
const since = ago(WEEK)
|
||||
const controller = new AbortController()
|
||||
|
||||
Reference in New Issue
Block a user