Fix some note rendering bugs, throw error when dufflepud is not configured

This commit is contained in:
Jon Staab 2024-06-19 11:16:30 -07:00
parent c80988882b
commit c6cdcfb2f8
5 changed files with 24 additions and 49 deletions

View File

@ -16,7 +16,6 @@
isAddress,
isNewline,
} from "@welshman/content"
import MediaSet from "src/partials/MediaSet.svelte"
import QRCode from "src/partials/QRCode.svelte"
import NoteContentNewline from "src/app/shared/NoteContentNewline.svelte"
import NoteContentEllipsis from "src/app/shared/NoteContentEllipsis.svelte"
@ -44,13 +43,13 @@
const isBoundary = i => {
const parsed = shortContent[i]
if (!parsed || isBoundary(parsed)) return true
if (!parsed || isNewline(parsed)) return true
if (isText(parsed)) return parsed.value.match(/^\s+$/)
return false
}
const isStartOrEnd = i => Boolean(isBoundary(i - 1) || isBoundary(i + 1))
const isStartOrEnd = i => Boolean(isBoundary(i - 1) && isBoundary(i + 1))
const getLinks = content =>
content.filter(x => isLink(x) && x.value.isMedia).map(x => x.value.url.toString())
@ -67,7 +66,6 @@
)
$: links = getLinks(shortContent)
$: extraLinks = without(links, getLinks(fullContent))
$: ellipsize = expandable && shortContent.find(isEllipsis)
</script>
@ -107,9 +105,6 @@
{/if}
{/each}
</div>
{#if showMedia && extraLinks.length > 0}
<MediaSet links={extraLinks} />
{/if}
</div>
{#if ellipsize}

View File

@ -10,6 +10,8 @@
const url = value.url.toString()
const coracleRegexp = /^(https?:\/\/)?(app\.)?coracle.social/
const close = () => {
hidden = true
}
@ -17,18 +19,16 @@
let hidden = false
</script>
{#if url.includes('coracle.social/')}
{#if url.match(coracleRegexp)}
<Anchor
modal
stopPropagation
class="overflow-hidden text-ellipsis whitespace-nowrap underline"
href={url.replace(/(https?:\/\/)?(app\.)?coracle.social/, '')}>
href={url.replace(coracleRegexp, '')}>
{displayUrl(url)}
</Anchor>
{:else if showMedia && value.isMedia && !hidden}
<div class="py-2">
<Media url={url} onClose={close} />
</div>
{:else if showMedia && !hidden}
<Media url={url} onClose={close} />
{:else if isShareableRelayUrl(url)}
<Anchor
modal

View File

@ -255,7 +255,15 @@ export const imgproxy = (url: string, {w = 640, h = 1024} = {}) => {
}
}
export const dufflepud = (path: string) => `${getSetting("dufflepud_url")}/${path}`
export const dufflepud = (path: string) => {
const base = getSetting("dufflepud_url")
if (!base) {
throw new Error("Dufflepud is not enabled")
}
return `${base}/${path}`
}
export const session = new Derived(
[pubkey, sessions],
@ -1999,16 +2007,19 @@ class IndexedDBAdapter {
const removedRecords = prev.filter(r => !currentIds.has(r[key]))
if (newRecords.length > 0) {
console.log('putting', name, newRecords.length, current.length)
await storage.bulkPut(name, newRecords)
}
if (removedRecords.length > 0) {
console.log('deleting', name, removedRecords.length, current.length)
await storage.bulkDelete(name, removedRecords.map(prop(key)))
}
// If we have much more than our limit, prune our store. This will get persisted
// the next time around.
if (current.length > limit * 1.5) {
console.log('pruning', name, current.length)
set((sort ? sort(current) : current).slice(0, limit))
}

View File

@ -7,7 +7,7 @@
import Image from "src/partials/Image.svelte"
import Anchor from "src/partials/Anchor.svelte"
import Spinner from "src/partials/Spinner.svelte"
import {dufflepud, imgproxy} from "src/engine"
import {getSetting, dufflepud, imgproxy} from "src/engine"
export let url
export let imeta = Tags.wrap([["url", url]])
@ -18,8 +18,8 @@
const loadPreview = async () => {
const json = await Fetch.postJson(dufflepud("link/preview"), {url})
if (!json.title && !json.image) {
throw new Error("Unable to load preview")
if (!json?.title && !json?.image) {
throw new Error("Failed to load link preview")
}
return json
@ -81,7 +81,7 @@
</div>
{/if}
{:catch}
<p class="mb-1 px-12 py-24 text-center text-neutral-600">
<p class="mb-1 p-12 text-center text-neutral-600">
Unable to load a preview for {url}
</p>
{/await}

View File

@ -1,31 +0,0 @@
<script lang="ts">
import Media from "src/partials/Media.svelte"
import Anchor from "src/partials/Anchor.svelte"
import Modal from "src/partials/Modal.svelte"
export let links
let showModal = false
const openModal = () => {
showModal = true
}
const closeModal = () => {
showModal = false
}
</script>
<div class="my-8 flex justify-center">
<Anchor button on:click={openModal}>
<i class="fa fa-plus" /> Show all {links.length} link previews
</Anchor>
</div>
{#if showModal}
<Modal onEscape={closeModal}>
{#each links as url}
<Media {url} />
{/each}
</Modal>
{/if}