misc: Tweak CORS

This commit is contained in:
Xyphyn committed 2023-07-09 12:29:41 -07:00
1 parent 740664d918
commit 981d1581a4
8 files changed
+39 -29

No files matched your search

@@ -74,14 +74,14 @@
<div class="max-w-full break-words text-sm leading-6">
<Markdown source={node.comment_view.comment.content} />
</div>
<div class="flex flex-row gap-2 items-center mt-1">
<div class="flex flex-row gap-2 items-center mt-1 h-[26px]">
<CommentVote
bind:score={node.comment_view.counts.score}
bind:vote={node.comment_view.my_vote}
commentId={node.comment_view.comment.id}
/>
<button
class="{Color.borderDark} px-2 py-1 flex flex-row items-center gap-1
class="{Color.borderDark} h-full px-2 flex flex-row items-center gap-1
rounded-md transition-colors"
on:click={() => (replying = !replying)}
>
@@ -57,12 +57,12 @@
</script>
<div
class="flex flex-row items-center rounded-md px-2 py-0.5 transition-colors
cursor-pointer {Color.borderDark}"
class="flex flex-row items-center rounded-md transition-colors
cursor-pointer h-full {Color.borderDark}"
>
<button
on:click={upvote}
class="pr-1.5 {vote == 1 ? 'text-orange-500' : ''}"
class="px-1.5 {vote == 1 ? 'text-orange-500' : ''}"
aria-label="Upvote"
>
<Icon src={ChevronUp} width={19} mini />
@@ -72,7 +72,7 @@
</span>
<button
on:click={downvote}
class="pl-1.5 {vote == -1 ? 'text-blue-500' : ''}"
class="px-1.5 {vote == -1 ? 'text-blue-500' : ''}"
aria-label="Downvote"
>
<Icon src={ChevronDown} width={19} mini />
@@ -67,17 +67,14 @@
<svelte:self {post} nodes={node.children} isParent={false} />
{/if}
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
<div class="m-1 w-full max-w-[9rem]">
<Button
loading={loadingChildren}
disabled={loadingChildren}
on:click={() => fetchChildren(node)}
large
>
<Icon src={ChevronDown} width={16} mini />
Load {node.comment_view.counts.child_count} more
</Button>
</div>
<Button
loading={loadingChildren}
disabled={loadingChildren}
on:click={() => fetchChildren(node)}
>
<Icon src={ChevronDown} width={16} mini />
Load {node.comment_view.counts.child_count} more
</Button>
{/if}
</Comment>
{/each}
+1 -3
View File
@@ -6,9 +6,7 @@
</script>
<img
src="{url ??
`https://api.dicebear.com/6.x/initials/svg?seed=${alt}`}?format=webp&thumbnail={width *
2}"
src="{url ?? `/img/logo-background.svg`}?format=webp&thumbnail={width * 2}"
{alt}
{width}
loading="lazy"
+1 -6
View File
@@ -17,12 +17,7 @@
href={linkFromCommunity(user)}
>
{#if avatar}
<Avatar
url={user.avatar ??
`https://api.dicebear.com/6.x/initials/svg?seed=${user.name}`}
alt={user.name}
width={avatarSize}
/>
<Avatar url={user.avatar} alt={user.name} width={avatarSize} />
{/if}
{user.name}
</a>
+1 -1
View File
@@ -1,6 +1,6 @@
<script lang="ts">
export let date: Date
export let relativeTo: Date | undefined
export let relativeTo: Date | undefined = undefined
function formatRelativeDate(date: Date) {
const now = relativeTo?.getTime() ?? Date.now()
+7 -2
View File
@@ -6,8 +6,9 @@ import {
import { get, writable } from 'svelte/store'
import { PUBLIC_PROXY_URL } from '$env/static/public'
export const DEFAULT_INSTANCE_URL = 'lemmy.world'
export const DEFAULT_INSTANCE_URL = 'lemmy.ml'
export let instance_url = writable(DEFAULT_INSTANCE_URL)
export let corsSupported = writable(true)
export function buildBaseUrl(instance?: string) {
if (!instance) {
@@ -22,7 +23,11 @@ export function getClient(instance?: string): LemmyHttp {
instance = get(authData)?.instance ?? DEFAULT_INSTANCE_URL
}
return new LemmyHttp(`${PUBLIC_PROXY_URL}/cors/${instance}`)
return new LemmyHttp(
get(corsSupported)
? `https://${instance}`
: `${PUBLIC_PROXY_URL}/cors/${instance}`
)
}
export const getInstance = () => get(authData)?.instance ?? DEFAULT_INSTANCE_URL
+15
View File
@@ -1,6 +1,9 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { page } from '$app/stores'
import Button from '$lib/components/input/Button.svelte'
import Link from '$lib/components/input/Link.svelte'
import { corsSupported } from '$lib/lemmy.js'
</script>
<div class="flex flex-col mx-auto gap-4 justify-center items-center">
@@ -9,8 +12,20 @@
Failed to fetch page. Most major lemmy instances are having quite a lot of
issues right now, this might be on their end.
</p>
<p>
This could be a CORS issue. The instance you're using must update to Lemmy
1.18.1 to fix CORS.
</p>
<code class="bg-slate-100 dark:bg-zinc-800 px-2 py-1 rounded-md">
{JSON.stringify($page.error)}
</code>
<Link href={$page.url.toString()}>Retry</Link>
<Button
on:click={() => {
corsSupported.set(false)
goto($page.url.toString())
}}
>
Retry through proxy
</Button>
</div>