-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #601 from da7a90-backup/thumbnails
Feat: added screenshoting and setting the channel thumbnail
- Loading branch information
Showing
6 changed files
with
152 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke-width="1.5" | ||
stroke="currentColor" | ||
class="w-8 h-8"> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z" /> | ||
</svg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,63 @@ | ||
import { patch, putImage } from '$lib/api' | ||
import type { Actions } from './$types' | ||
|
||
const dataURLtoFile = (dataurl: string, filename: string) => { | ||
const arr = dataurl.split(',') | ||
const mime = (arr[0] && arr[0].match(/:(.*?);/)?.[1]) || '' | ||
const bstr = atob(arr[1]) | ||
let n = bstr.length | ||
const u8arr = new Uint8Array(n) | ||
while (n--) { | ||
u8arr[n] = bstr.charCodeAt(n) | ||
} | ||
return new File([u8arr], filename, { type: mime }) | ||
} | ||
|
||
export const actions = { | ||
'edit-channel': async () => { | ||
'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 | ||
const file = | ||
thumbnail !== null && thumbnail.size > 0 | ||
? 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) | ||
} | ||
|
||
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 | ||
} | ||
} |