feat: add embeds
This commit is contained in:
1 parent
ec72b62c0b
commit
869afbd0cb
8 files changed
+86
-24
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "1.16.7",
|
"version": "1.17.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -1,20 +1,27 @@
|
|||||||
<script lang="ts">
|
<script lang="ts" context="module">
|
||||||
export let href: string
|
export const parseURL = (href: string) => {
|
||||||
export let highlight: boolean = false
|
|
||||||
export let nowrap: boolean = false
|
|
||||||
|
|
||||||
const parseURL = (href: string) => {
|
|
||||||
try {
|
try {
|
||||||
return new URL(href)
|
return new URL(href)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: richURL = parseURL(href)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a {href} class="{highlight ? 'text-blue-500' : ''} hover:underline max-w-full">
|
<script lang="ts">
|
||||||
|
export let href: string
|
||||||
|
export let highlight: boolean = false
|
||||||
|
export let nowrap: boolean = false
|
||||||
|
|
||||||
|
$: richURL = $$slots.default ? undefined : parseURL(href)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<a
|
||||||
|
{href}
|
||||||
|
class="{highlight
|
||||||
|
? 'text-blue-500'
|
||||||
|
: ''} hover:underline max-w-full inline-flex items-center gap-1 {$$props.class}"
|
||||||
|
>
|
||||||
<slot name="icon" />
|
<slot name="icon" />
|
||||||
<slot>
|
<slot>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -137,12 +137,10 @@
|
|||||||
{:else if post.post.url}
|
{:else if post.post.url}
|
||||||
<PostLink
|
<PostLink
|
||||||
url={post.post.url}
|
url={post.post.url}
|
||||||
thumbnail_url={view == 'card'
|
thumbnail_url={post.post.thumbnail_url}
|
||||||
? post.post.thumbnail_url
|
|
||||||
? `${post.post.thumbnail_url}?format=webp&thumbnail=512`
|
|
||||||
: undefined
|
|
||||||
: undefined}
|
|
||||||
nsfw={post.post.nsfw}
|
nsfw={post.post.nsfw}
|
||||||
|
embed_description={post.post.embed_description}
|
||||||
|
embed_title={post.post.embed_title}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if post.post.body && !post.post.nsfw && view != 'compact'}
|
{#if post.post.body && !post.post.nsfw && view != 'compact'}
|
||||||
|
|||||||
@@ -1,14 +1,58 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link, { parseURL } from '$lib/components/input/Link.svelte'
|
||||||
|
import { Material } from 'mono-svelte'
|
||||||
|
import { Icon, Link as LinkIcon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let url: string
|
export let url: string
|
||||||
export let thumbnail_url: string | undefined = undefined
|
export let thumbnail_url: string | undefined = undefined
|
||||||
export let nsfw: boolean = false
|
export let nsfw: boolean = false
|
||||||
|
export let embed_title: string | undefined = undefined
|
||||||
|
export let embed_description: string | undefined = undefined
|
||||||
|
|
||||||
|
$: richURL = parseURL(url)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Link href={url} highlight nowrap />
|
{#if embed_title}
|
||||||
|
<Material class="flex flex-row gap-4">
|
||||||
{#if thumbnail_url}
|
<div class="flex flex-col gap-2">
|
||||||
|
{#if richURL}
|
||||||
|
<Link
|
||||||
|
href={url}
|
||||||
|
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs"
|
||||||
|
>
|
||||||
|
<Icon src={LinkIcon} size="12" mini slot="icon" />
|
||||||
|
{richURL.hostname}
|
||||||
|
</Link>
|
||||||
|
{/if}
|
||||||
|
<a href={url} class="font-medium text-base hover:underline">
|
||||||
|
{embed_title}
|
||||||
|
</a>
|
||||||
|
{#if embed_description}
|
||||||
|
<p
|
||||||
|
class="text-sm text-transparent bg-clip-text bg-gradient-to-b
|
||||||
|
from-slate-700 dark:from-zinc-400
|
||||||
|
via-slate-700 dark:via-zinc-400
|
||||||
|
to-slate-700/0 dark:to-zinc-400/0"
|
||||||
|
>
|
||||||
|
{embed_description.slice(0, 300)}
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{#if thumbnail_url}
|
||||||
|
<a href={url}>
|
||||||
|
<img
|
||||||
|
src={thumbnail_url}
|
||||||
|
class="rounded-lg max-w-[200px] w-full h-auto aspect-video object-cover bg-slate-200 dark:bg-zinc-800"
|
||||||
|
width={600}
|
||||||
|
height={400}
|
||||||
|
alt=""
|
||||||
|
class:blur-3xl={nsfw}
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
|
</Material>
|
||||||
|
{:else if thumbnail_url}
|
||||||
|
<Link href={url} highlight nowrap />
|
||||||
<a href={url}>
|
<a href={url}>
|
||||||
<img
|
<img
|
||||||
src={thumbnail_url}
|
src={thumbnail_url}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<svelte:window bind:scrollY={scroll} />
|
<svelte:window bind:scrollY={scroll} />
|
||||||
|
|
||||||
<div class="shell {$$props.class}">
|
<div class="shell {$$props.class}">
|
||||||
|
<slot />
|
||||||
<slot
|
<slot
|
||||||
name="navbar"
|
name="navbar"
|
||||||
class="sticky top-0 border-b border-slate-200 dark:border-zinc-900
|
class="sticky top-0 border-b border-slate-200 dark:border-zinc-900
|
||||||
|
|||||||
@@ -34,9 +34,13 @@ async function customFetch(
|
|||||||
const f = func ? func : fetch
|
const f = func ? func : fetch
|
||||||
|
|
||||||
if (init?.body && auth) {
|
if (init?.body && auth) {
|
||||||
|
try {
|
||||||
const json = JSON.parse(init.body.toString())
|
const json = JSON.parse(init.body.toString())
|
||||||
json.auth = auth
|
json.auth = auth
|
||||||
init.body = JSON.stringify(json)
|
init.body = JSON.stringify(json)
|
||||||
|
} catch (e) {
|
||||||
|
// It seems this isn't a JSON request. Ignore adding an auth parameter.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = toURL(input)
|
const url = toURL(input)
|
||||||
|
|||||||
+11
-1
@@ -4,6 +4,8 @@ import { userSettings } from '$lib/settings.js'
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
import type { SubscribedType } from 'lemmy-js-client'
|
import type { SubscribedType } from 'lemmy-js-client'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import { feature } from '$lib/version.js'
|
||||||
|
import { client, site } from '$lib/lemmy.js'
|
||||||
|
|
||||||
export const findClosestNumber = (numbers: number[], target: number): number =>
|
export const findClosestNumber = (numbers: number[], target: number): number =>
|
||||||
numbers.reduce((prev, curr) =>
|
numbers.reduce((prev, curr) =>
|
||||||
@@ -143,6 +145,14 @@ export async function uploadImage(
|
|||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('images[]', image)
|
formData.append('images[]', image)
|
||||||
|
|
||||||
|
if (feature('unproxiedImageUpload', get(site)?.version)) {
|
||||||
|
const res = await client({ auth: jwt, instanceURL: instance }).uploadImage({
|
||||||
|
image: image,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.url) return res.url
|
||||||
|
else throw new Error(`Failed to upload image. ${res.msg}`)
|
||||||
|
} else {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${
|
`${
|
||||||
window.location.origin
|
window.location.origin
|
||||||
@@ -160,13 +170,13 @@ export async function uploadImage(
|
|||||||
if (json.msg == 'ok') {
|
if (json.msg == 'ok') {
|
||||||
return `https://${instance}/pictrs/image/${json.files?.[0]?.file}`
|
return `https://${instance}/pictrs/image/${json.files?.[0]?.file}`
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${
|
`${
|
||||||
(await response.text().catch((_) => undefined)) ??
|
(await response.text().catch((_) => undefined)) ??
|
||||||
'Failed to upload image'
|
'Failed to upload image'
|
||||||
}: ${response.status}: ${response.statusText}`
|
}: ${response.status}: ${response.statusText}`
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const instanceToURL = (input: string) =>
|
export const instanceToURL = (input: string) =>
|
||||||
|
|||||||
@@ -74,10 +74,6 @@
|
|||||||
<Icon src={Forward} mini size="16" slot="prefix" />
|
<Icon src={Forward} mini size="16" slot="prefix" />
|
||||||
Skip Navigation
|
Skip Navigation
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Moderation />
|
|
||||||
<ToastContainer />
|
|
||||||
|
|
||||||
<Shell
|
<Shell
|
||||||
class="min-h-screen {$userSettings.font == 'inter'
|
class="min-h-screen {$userSettings.font == 'inter'
|
||||||
? 'font-inter'
|
? 'font-inter'
|
||||||
@@ -86,6 +82,8 @@
|
|||||||
: 'font-sans'}"
|
: 'font-sans'}"
|
||||||
route={$page.route}
|
route={$page.route}
|
||||||
>
|
>
|
||||||
|
<Moderation />
|
||||||
|
<ToastContainer />
|
||||||
<Navbar
|
<Navbar
|
||||||
slot="navbar"
|
slot="navbar"
|
||||||
let:style={s}
|
let:style={s}
|
||||||
|
|||||||
Reference in new issue
Block a user