import { useContext } from 'preact/hooks'; import styles from './Attachment.module.scss'; import IconButton from '../../../ui/IconButton'; import { Attachment } from "revolt.js/dist/api/objects"; import { determineFileSize } from '../../../../lib/fileSize'; import { AppContext } from '../../../../context/revoltjs/RevoltClient'; import { Download, LinkExternal, File, Headphone, Video } from '@styled-icons/boxicons-regular'; interface Props { attachment: Attachment; } export default function AttachmentActions({ attachment }: Props) { const client = useContext(AppContext); const { filename, metadata, size } = attachment; const url = client.generateFileURL(attachment)!; const open_url = `${url}/${filename}`; const download_url = url.replace('attachments', 'attachments/download') // for some reason revolt.js says the size is a string even though it's a number const filesize = determineFileSize(size as unknown as number); switch (metadata.type) { case 'Image': return (
) case 'Audio': return ( ) case 'Video': return ( ) default: return ( ) } }