From d13d217979360bdfa11066e0fcb532cb170d13d9 Mon Sep 17 00:00:00 2001 From: Gagan Suie Date: Mon, 24 Jul 2023 21:24:12 -0500 Subject: [PATCH] Fix: edit channel edge cases --- .../Channel/Chat/DrawerEditChannel.svelte | 1 + .../Profile/DrawerEditProfile.svelte | 2 + .../channel/[channelId]/+page.server.ts | 40 +++---------------- src/routes/profile/[username]/+page.server.ts | 4 +- 4 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/lib/components/Channel/Chat/DrawerEditChannel.svelte b/src/lib/components/Channel/Chat/DrawerEditChannel.svelte index ca71c9f6..26557b07 100644 --- a/src/lib/components/Channel/Chat/DrawerEditChannel.svelte +++ b/src/lib/components/Channel/Chat/DrawerEditChannel.svelte @@ -158,6 +158,7 @@ bind:this={fileuploader} on:change={fileupload} type="file" + accept="image/png, image/jpeg" name="thumbnail" class="file-input file-input-bordered file-input-primary w-full mt-5" /> @@ -136,6 +137,7 @@ diff --git a/src/routes/channel/[channelId]/+page.server.ts b/src/routes/channel/[channelId]/+page.server.ts index 4ca374c3..ca399560 100644 --- a/src/routes/channel/[channelId]/+page.server.ts +++ b/src/routes/channel/[channelId]/+page.server.ts @@ -1,4 +1,4 @@ -import { patch, putImage } from '$lib/api' +import { putImage } from '$lib/api' import type { Actions } from './$types' const dataURLtoFile = (dataurl: string, filename: string) => { @@ -16,10 +16,6 @@ const dataURLtoFile = (dataurl: string, filename: string) => { export const actions = { 'edit-channel': async ({ request, locals }) => { const data: FormData = await request.formData() - const newChannel = {} - addPropertyIfDefined(data, 'description', newChannel) - addPropertyIfDefined(data, 'title', newChannel) - addPropertyIfDefined(data, 'category', newChannel) const thumbnail = data.get('thumbnail') as File const imageSrc = data.get('imageSrc') as string const channelId = data.get('channelId') as string @@ -28,36 +24,12 @@ export const actions = { ? thumbnail : dataURLtoFile(imageSrc, 'thumbnail-image') console.log(file) - if (file !== null && file.size > 0) { - const urlLocation = await putImage( - `channels/thumbnail?channelId=${channelId}&bucketName=thumbnails&originalName=${channelId}-thumbnail`, - file, - { - userId: locals.user.userId, - token: locals.user.token - } - ) - console.log(urlLocation) + if (file !== null && file.size > 0 && file.type !== '') { + await putImage(`channels/thumbnail?channelId=${channelId}&bucketName=thumbnails`, file, { + userId: locals.user.userId, + token: locals.user.token + }) } - - const updatedChannel = await patch(`channels?channelId=${channelId}`, newChannel, { - userId: locals.user.userId, - token: locals.user.token - }) - - console.log(updatedChannel) - return { success: true } } } satisfies Actions - -const addPropertyIfDefined = ( - data: FormData, - property: string, - newChannel: { [key: string]: unknown } -) => { - const propertyValue = data.get(property) - if (propertyValue !== null && propertyValue !== undefined) { - newChannel[property] = propertyValue - } -} diff --git a/src/routes/profile/[username]/+page.server.ts b/src/routes/profile/[username]/+page.server.ts index af913883..6942d8e1 100644 --- a/src/routes/profile/[username]/+page.server.ts +++ b/src/routes/profile/[username]/+page.server.ts @@ -31,7 +31,7 @@ export const actions = { if (data.get('avatar') !== null && avatar.size > 0) { const urlLocation = await putImage( - `users/current/avatar?bucketName=avatars&originalName=${locals.user.userId}-avatar`, + `users/current/avatar?bucketName=avatars`, data.get('avatar'), { userId: locals.user.userId, @@ -43,7 +43,7 @@ export const actions = { if (data.get('banner') !== null && banner.size > 0) { const urlLocation = await putImage( - `users/current/banner?bucketName=banners&originalName=${locals.user.userId}-banner`, + `users/current/banner?bucketName=banners`, data.get('banner'), { userId: locals.user.userId,