From d2369125106f323e827fcebb52537751465d1010 Mon Sep 17 00:00:00 2001 From: James Xylight Date: Wed, 3 Sep 2025 21:09:17 -0700 Subject: [PATCH] stage3: add piefed login --- src/lib/client/lemmy.svelte.ts | 13 ++++-- src/lib/client/piefed/piefed.ts | 23 +++++++--- src/lib/mono/forms/TextInput.svelte | 1 - src/lib/mono/forms/select/Select.svelte | 2 +- src/routes/login/+page.svelte | 59 +++++++++++++++++++++---- src/routes/login/guest/+page.svelte | 43 +++++++++++++++--- 6 files changed, 116 insertions(+), 25 deletions(-) diff --git a/src/lib/client/lemmy.svelte.ts b/src/lib/client/lemmy.svelte.ts index 0a7c0c6c..2678c376 100644 --- a/src/lib/client/lemmy.svelte.ts +++ b/src/lib/client/lemmy.svelte.ts @@ -71,7 +71,7 @@ export function client({ clientType = profile.current.client } - const jwt = auth ? auth : profile.current?.jwt + const jwt = auth ?? profile.current?.jwt const headers = jwt ? { authorization: `Bearer ${jwt}` } : {} @@ -95,11 +95,18 @@ export function getClient( return client({ instanceURL, func, auth }) } -export async function validateInstance(instance: string): Promise { +export async function validateInstance( + instance: string, + type: ClientType, +): Promise { if (instance == '') return false try { - await getClient(instance).getSite() + await client({ + instanceURL: instance, + clientType: type, + auth: '', + }).getSite() return true } catch { diff --git a/src/lib/client/piefed/piefed.ts b/src/lib/client/piefed/piefed.ts index 4caf3516..aa2f2dca 100644 --- a/src/lib/client/piefed/piefed.ts +++ b/src/lib/client/piefed/piefed.ts @@ -129,9 +129,12 @@ export class PiefedClient implements BaseClient { } } async likePost( - ...params: Parameters + params: Parameters[0], ): ReturnType { - throw new Error('Unimplemented') + // TODO remove any + return (await this.#client.POST('/post/like', { + body: { ...params }, + })) as any } async generateTotpSecret( @@ -225,9 +228,14 @@ export class PiefedClient implements BaseClient { throw new Error('Unimplemented') } async markPostAsRead( - ...params: Parameters + params: Parameters[0], ): ReturnType { - throw new Error('Unimplemented') + const response = await this.#client.POST('/post/mark_as_read', { + body: { ...params }, + }) + + // TODO remove any + return response.data as any } async hidePost( ...params: Parameters @@ -300,9 +308,12 @@ export class PiefedClient implements BaseClient { throw new Error('Unimplemented') } async likeComment( - ...params: Parameters + params: Parameters[0], ): ReturnType { - throw new Error('Unimplemented') + // TODO remove any + return (await this.#client.POST('/comment/like', { + body: { ...params }, + })) as any } async listCommentLikes( ...params: Parameters diff --git a/src/lib/mono/forms/TextInput.svelte b/src/lib/mono/forms/TextInput.svelte index 02f4edb3..e5d760b9 100644 --- a/src/lib/mono/forms/TextInput.svelte +++ b/src/lib/mono/forms/TextInput.svelte @@ -121,7 +121,6 @@ class={[ 'rounded-xl rounded-l-none text-slate-600 dark:text-zinc-400', inlineAffixes && 'bg-white dark:bg-zinc-900 pl-0', - sizeClass[size], ]} > {@render suffix?.()} diff --git a/src/lib/mono/forms/select/Select.svelte b/src/lib/mono/forms/select/Select.svelte index af79df15..f2bb770f 100644 --- a/src/lib/mono/forms/select/Select.svelte +++ b/src/lib/mono/forms/select/Select.svelte @@ -93,7 +93,7 @@ {#snippet selectTarget(attachment: Attachment)} -