feat: Add post and comment editing (#12)

* feat: Add editing

* feat: Add comment badges

* fix: make loading more consistent

* misc: remove prop drilling

* feat: Add post editing

* misc: update version

* feat: Add comment deletion
This commit is contained in:
Xylight authored and GitHub committed 2023-07-25 11:12:15 -07:00
1 parent 0327ae4aed
commit 7b1ad247f9
16 files changed
+417 -192

No files matched your search

+32 -1
View File
@@ -4,7 +4,7 @@ import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import { userSettings } from '$lib/settings.js'
import { env } from '$env/dynamic/public'
export const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.world'
export const DEFAULT_INSTANCE_URL = env.PUBLIC_INSTANCE_URL || 'lemmy.ml'
export let instance = writable(DEFAULT_INSTANCE_URL)
export let corsSupported = writable(true)
@@ -111,3 +111,34 @@ export async function validateInstance(instance: string): Promise<boolean> {
return false
}
}
export async function uploadImage(
image: File | null | undefined
): Promise<string | undefined> {
if (!image || !get(authData)) return
const formData = new FormData()
formData.append('images[]', image)
const response = await fetch(
`${
window.location.origin
}/cors/${getInstance()}/pictrs/image?${new URLSearchParams({
auth: get(authData)!.token,
})}`,
{
method: 'POST',
body: formData,
}
)
const json = await response.json()
if (json.msg == 'ok') {
return `https://${get(authData)?.instance}/pictrs/image/${
json.files?.[0]?.file
}`
}
throw new Error(`error uploading image: ${response.status}`)
}