diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 047123c9..87050853 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -10,6 +10,12 @@ function buildUrl(inputUrl: URL): URL { return new URL(`${withoutCors}?${inputUrl.searchParams.toString()}`) } +export async function handleError() { + return { + message: 'The proxy failed to fetch from that URL', + } +} + export async function handle({ event, resolve }) { // annoying hack to fix lemmy's CORS if (event.url.pathname.startsWith('/cors')) { @@ -27,10 +33,20 @@ export async function handle({ event, resolve }) { // @ts-ignore this works, idk why typescript complains duplex: 'half', signal: AbortSignal.timeout(20 * 1000), - }) + }).catch((_) => undefined) + + if (!data) { + return new Response( + JSON.stringify({ + message: 'proxy failed to fetch', + }), + { + status: 500, + } + ) + } if (!data.ok) { - await resolve(event) return new Response( JSON.stringify({ message: await data.text(), @@ -44,23 +60,18 @@ export async function handle({ event, resolve }) { try { const json = await data.json() - await resolve(event) return new Response(JSON.stringify(json), { status: data.status, }) - } catch (err) { - await resolve(event) - return new Response( - JSON.stringify({ - message: 'Failed to fetch', - }), - { - status: data.status, - } - ) + } catch (error) { + console.log('Caught the thing') + + return new Response(JSON.stringify({ message: 'i hate everything' }), { + status: 500, + }) } } catch (error) { - await resolve(event) + console.log('caught it') return new Response( JSON.stringify({ message: 'the proxy failed to fetch from server', @@ -71,6 +82,7 @@ export async function handle({ event, resolve }) { ) } } + const response = await resolve(event) return response } diff --git a/src/routes/post/[id]/Post.svelte b/src/lib/components/lemmy/Post.svelte similarity index 69% rename from src/routes/post/[id]/Post.svelte rename to src/lib/components/lemmy/Post.svelte index 1c928b99..99a04316 100644 --- a/src/routes/post/[id]/Post.svelte +++ b/src/lib/components/lemmy/Post.svelte @@ -19,6 +19,8 @@ import CommunityLink from '$lib/components/community/CommunityLink.svelte' import { isImage } from '$lib/ui/image.js' import { authData, getClient } from '$lib/lemmy.js' + import PostVote from '$lib/components/lemmy/PostVote.svelte' + import FormattedNumber from '$lib/components/util/FormattedNumber.svelte' let postRes: PostView export { postRes as post } @@ -96,55 +98,22 @@ {/if}
+
{JSON.stringify($page.error)}
Retry
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 7407b4d8..957073bb 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -14,8 +14,8 @@
PencilSquare,
UserGroup,
} from 'svelte-hero-icons'
- import Avatar from '../lib/components/ui/Avatar.svelte'
- import Post from './post/[id]/Post.svelte'
+ import Avatar from '$lib/components/ui/Avatar.svelte'
+ import Post from '$lib/components/lemmy/Post.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
diff --git a/src/routes/+page.ts b/src/routes/+page.ts
index c37ec4e8..8b3db2b6 100644
--- a/src/routes/+page.ts
+++ b/src/routes/+page.ts
@@ -2,7 +2,7 @@ import { authData, getClient } from '$lib/lemmy.js'
import type { ListingType, SortType } from 'lemmy-js-client'
import { get } from 'svelte/store'
-export async function load({ url }) {
+export async function load({ url, params }) {
const page = Number(url.searchParams.get('page') || 1) || 1
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'Active'
diff --git a/src/routes/c/[name]/+page.svelte b/src/routes/c/[name]/+page.svelte
index 307b746e..3532ffad 100644
--- a/src/routes/c/[name]/+page.svelte
+++ b/src/routes/c/[name]/+page.svelte
@@ -4,7 +4,7 @@
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
import SvelteMarkdown from 'svelte-markdown'
import Avatar from '../../../lib/components/ui/Avatar.svelte'
- import Post from '../../post/[id]/Post.svelte'
+ import Post from '../../../lib/components/lemmy/Post.svelte'
import { goto } from '$app/navigation'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import {
diff --git a/src/routes/c/[name]/+page.ts b/src/routes/c/[name]/+page.ts
index cd1842cf..1d2293f1 100644
--- a/src/routes/c/[name]/+page.ts
+++ b/src/routes/c/[name]/+page.ts
@@ -9,7 +9,7 @@ export function load(req: any) {
(req.url.searchParams.get('sort') as SortType) || 'Active'
return {
- posts: getClient().getPosts({
+ posts: getClient(req.params).getPosts({
limit: 40,
community_name: req.params.name,
page: page,
diff --git a/src/routes/inbox/+page.svelte b/src/routes/inbox/+page.svelte
new file mode 100644
index 00000000..a7b4541a
--- /dev/null
+++ b/src/routes/inbox/+page.svelte
@@ -0,0 +1,18 @@
+
+
+Inbox
+
+ {#if !data.data || (data.data?.length ?? 0) == 0}
+
+ Wow, it's quite empty in here.
+
+ {:else}
+ {#each data.data as item}
+
+ {/each}
+ {/if}
+
diff --git a/src/routes/inbox/+page.ts b/src/routes/inbox/+page.ts
new file mode 100644
index 00000000..c1535d1e
--- /dev/null
+++ b/src/routes/inbox/+page.ts
@@ -0,0 +1,36 @@
+import { authData, getClient } from '$lib/lemmy.js'
+import { getInboxItemPublished } from '$lib/lemmy/inbox.js'
+import { get } from 'svelte/store'
+
+export async function load() {
+ const auth = get(authData)
+ if (!auth) return
+
+ const client = getClient()
+
+ const params = {
+ limit: 50,
+ page: 1,
+ auth: auth.token,
+ }
+
+ const [replies, mentions, privateMessages] = await Promise.all([
+ client.getReplies({
+ ...params,
+ sort: 'New',
+ }),
+ client.getPersonMentions({
+ ...params,
+ sort: 'New',
+ }),
+ client.getPrivateMessages(params),
+ ])
+
+ const data = [...replies.replies, ...mentions.mentions].sort(
+ (a, b) =>
+ Date.parse(getInboxItemPublished(b)) -
+ Date.parse(getInboxItemPublished(a))
+ )
+
+ return { data: data }
+}
diff --git a/src/routes/inbox/InboxItem.svelte b/src/routes/inbox/InboxItem.svelte
new file mode 100644
index 00000000..1b3788ca
--- /dev/null
+++ b/src/routes/inbox/InboxItem.svelte
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+ {item.creator.display_name ?? item.creator.name}
+
+ replied to you in
+
+ {item.post.name}
+
+
+
+
+ Jump
+
+
+
+
+
+
diff --git a/src/routes/post/[instance]/+page.ts b/src/routes/post/[instance]/+page.ts
new file mode 100644
index 00000000..2bb76f19
--- /dev/null
+++ b/src/routes/post/[instance]/+page.ts
@@ -0,0 +1,18 @@
+import { DEFAULT_INSTANCE_URL, authData } from '$lib/lemmy.js'
+import { error, redirect } from '@sveltejs/kit'
+import { get } from 'svelte/store'
+
+export function load({ params, url }) {
+ if (Number(params.instance)) {
+ const split = url.pathname.split('/')
+
+ split.splice(2, 0, `${get(authData)?.instance ?? DEFAULT_INSTANCE_URL}`)
+
+ const newUrl = new URL(url)
+ newUrl.pathname = split.join('/')
+
+ throw redirect(300, newUrl.toString())
+ }
+
+ throw error(404, 'Not found')
+}
diff --git a/src/routes/post/[id]/+page.svelte b/src/routes/post/[instance]/[id]/+page.svelte
similarity index 85%
rename from src/routes/post/[id]/+page.svelte
rename to src/routes/post/[instance]/[id]/+page.svelte
index b3d95787..7dc71197 100644
--- a/src/routes/post/[id]/+page.svelte
+++ b/src/routes/post/[instance]/[id]/+page.svelte
@@ -1,18 +1,16 @@