diff --git a/src/components/avatarUploader.tsx b/src/components/avatarUploader.tsx new file mode 100644 index 00000000..5ee0b62a --- /dev/null +++ b/src/components/avatarUploader.tsx @@ -0,0 +1,78 @@ +import { createBlobFromFile } from '@utils/createBlobFromFile'; + +import { open } from '@tauri-apps/api/dialog'; +import { Body, fetch } from '@tauri-apps/api/http'; +import { Plus } from 'iconoir-react'; +import { useState } from 'react'; + +export const ImagePicker = () => { + const [loading, setLoading] = useState(false); + const [value, setValue] = useState(''); + + const openFileDialog = async () => { + const selected: any = await open({ + multiple: false, + filters: [ + { + name: 'Image', + extensions: ['png', 'jpeg', 'jpg', 'gif'], + }, + ], + }); + if (Array.isArray(selected)) { + // user selected multiple files + } else if (selected === null) { + // user cancelled the selection + } else { + setLoading(true); + + const filename = selected.split('/').pop(); + const file = await createBlobFromFile(selected); + const buf = await file.arrayBuffer(); + + const res: { data: { file: { id: string } } } = await fetch('https://void.cat/upload?cli=false', { + method: 'POST', + timeout: 5, + headers: { + accept: '*/*', + 'Content-Type': 'application/octet-stream', + 'V-Filename': filename, + 'V-Description': 'Upload from https://lume.nu', + 'V-Strip-Metadata': 'true', + }, + body: Body.bytes(buf), + }); + const webpImage = 'https://void.cat/d/' + res.data.file.id + '.webp'; + + setValue(webpImage); + setLoading(false); + } + }; + + console.log(value); + + return ( + + ); +}; diff --git a/src/components/navigation/channels.tsx b/src/components/navigation/channels.tsx index 9a4a31f2..87b62906 100644 --- a/src/components/navigation/channels.tsx +++ b/src/components/navigation/channels.tsx @@ -22,7 +22,7 @@ export default function Channels() {

Channels

- }> + }>