forked from coracle/flotilla
Remove space blossom detection
This commit is contained in:
@@ -1,49 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onDestroy} from "svelte"
|
import {getTags, getTagValue, tagsFromIMeta} from "@welshman/util"
|
||||||
import {now} from "@welshman/lib"
|
|
||||||
import {BLOSSOM_AUTH, makeEvent, getTags, getTagValue, tagsFromIMeta} from "@welshman/util"
|
|
||||||
import {signer} from "@welshman/app"
|
|
||||||
import {imgproxy} from "@app/state"
|
import {imgproxy} from "@app/state"
|
||||||
|
|
||||||
const {value, event, ...props} = $props()
|
const {value, event, ...props} = $props()
|
||||||
|
|
||||||
const url = value.url.toString()
|
const url = value.url.toString()
|
||||||
|
const meta = getTags("imeta", event.tags)
|
||||||
// If we fail to fetch the image, try authenticating if we have a blossom hash
|
.map(tagsFromIMeta)
|
||||||
const onerror = async () => {
|
.find(meta => getTagValue("url", meta) === url)
|
||||||
const meta = getTags("imeta", event.tags)
|
const src = imgproxy(url)
|
||||||
.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)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<img alt="" {src} {onerror} {...props} />
|
<img alt="" {src} {...props} />
|
||||||
|
|||||||
+5
-46
@@ -2,59 +2,18 @@ import {mount} from "svelte"
|
|||||||
import type {Writable} from "svelte/store"
|
import type {Writable} from "svelte/store"
|
||||||
import {get} from "svelte/store"
|
import {get} from "svelte/store"
|
||||||
import type {StampedEvent} from "@welshman/util"
|
import type {StampedEvent} from "@welshman/util"
|
||||||
import {makeEvent, getTagValues, getListTags, BLOSSOM_AUTH} from "@welshman/util"
|
import {getTagValues, getListTags} from "@welshman/util"
|
||||||
import {simpleCache, normalizeUrl, removeNil, now} from "@welshman/lib"
|
|
||||||
import {Router} from "@welshman/router"
|
import {Router} from "@welshman/router"
|
||||||
import {signer, profileSearch, userBlossomServers} from "@welshman/app"
|
import {signer, profileSearch, userBlossomServers} from "@welshman/app"
|
||||||
import {Editor, MentionSuggestion, WelshmanExtension} from "@welshman/editor"
|
import {Editor, MentionSuggestion, WelshmanExtension} from "@welshman/editor"
|
||||||
import {makeMentionNodeView} from "./MentionNodeView"
|
import {makeMentionNodeView} from "./MentionNodeView"
|
||||||
import ProfileSuggestion from "./ProfileSuggestion.svelte"
|
import ProfileSuggestion from "./ProfileSuggestion.svelte"
|
||||||
|
|
||||||
export const hasBlossomSupport = simpleCache(async ([url]: [string]) => {
|
export const getUploadUrl = () => {
|
||||||
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) => {
|
|
||||||
const userUrls = getTagValues("server", getListTags(userBlossomServers.get()))
|
const userUrls = getTagValues("server", getListTags(userBlossomServers.get()))
|
||||||
const allUrls = removeNil([spaceUrl, ...userUrls])
|
|
||||||
|
|
||||||
for (let url of allUrls) {
|
for (const url of userUrls) {
|
||||||
url = url.replace(/^ws/, "http")
|
return url.replace(/^ws/, "http")
|
||||||
|
|
||||||
if (await hasBlossomSupport(url)) {
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "https://cdn.satellite.earth"
|
return "https://cdn.satellite.earth"
|
||||||
@@ -98,7 +57,7 @@ export const makeEditor = async ({
|
|||||||
submit,
|
submit,
|
||||||
sign: signWithAssert,
|
sign: signWithAssert,
|
||||||
defaultUploadType: "blossom",
|
defaultUploadType: "blossom",
|
||||||
defaultUploadUrl: await getUploadUrl(url),
|
defaultUploadUrl: getUploadUrl(),
|
||||||
extensions: {
|
extensions: {
|
||||||
placeholder: {
|
placeholder: {
|
||||||
config: {
|
config: {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
|
import SpaceAuthError from "@app/components/SpaceAuthError.svelte"
|
||||||
import {pushToast} from "@app/toast"
|
import {pushToast} from "@app/toast"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {getUploadUrl} from "@app/editor"
|
|
||||||
import {setChecked} from "@app/notifications"
|
import {setChecked} from "@app/notifications"
|
||||||
import {checkRelayConnection, checkRelayAuth, checkRelayAccess} from "@app/commands"
|
import {checkRelayConnection, checkRelayAuth, checkRelayAccess} from "@app/commands"
|
||||||
import {decodeRelay, userRoomsByUrl} from "@app/state"
|
import {decodeRelay, userRoomsByUrl} from "@app/state"
|
||||||
@@ -53,9 +52,6 @@
|
|||||||
onMount(() => {
|
onMount(() => {
|
||||||
checkConnection()
|
checkConnection()
|
||||||
|
|
||||||
// Prime our cache so inputs show up quickly
|
|
||||||
getUploadUrl(url)
|
|
||||||
|
|
||||||
const relays = [url]
|
const relays = [url]
|
||||||
const since = ago(WEEK)
|
const since = ago(WEEK)
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
|
|||||||
Reference in New Issue
Block a user