feat: use browser-fs-access polyfill for other browsers (#43)

This commit is contained in:
Daniel Roe 2022-11-24 11:44:24 +00:00 committed by GitHub
parent 823f4c960a
commit 00c9314580
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 15 deletions

View file

@ -1,5 +1,6 @@
<script setup lang="ts">
import type { CreateStatusParams, StatusVisibility } from 'masto'
import { fileOpen } from 'browser-fs-access'
const {
draftKey,
@ -37,22 +38,24 @@ async function handlePaste(evt: ClipboardEvent) {
}
async function pickAttachments() {
if (!globalThis.showOpenFilePicker)
// TODO: FireFox & Safari don't support it.
return
const handles = await showOpenFilePicker({
multiple: true,
types: [{
const files = await fileOpen([
{
description: 'Attachments',
accept: {
'image/*': ['.png', '.gif', '.jpeg', '.jpg', '.webp', '.avif', '.heic', '.heif'],
'video/*': ['.webm', '.mp4', '.m4v', '.mov', '.ogv', '.3gp'],
'audio/*': ['.mp3', '.ogg', '.oga', '.wav', '.flac', '.opus', '.aac', '.m4a', '.3gp', '.wma'],
},
}],
})
const files = await Promise.all(handles.map(handle => handle.getFile()))
multiple: true,
mimeTypes: ['image/*'],
extensions: ['.png', '.gif', '.jpeg', '.jpg', '.webp', '.avif', '.heic', '.heif'],
},
{
description: 'Attachments',
mimeTypes: ['video/*'],
extensions: ['.webm', '.mp4', '.m4v', '.mov', '.ogv', '.3gp'],
},
{
description: 'Attachments',
mimeTypes: ['audio/*'],
extensions: ['.mp3', '.ogg', '.oga', '.wav', '.flac', '.opus', '.aac', '.m4a', '.3gp', '.wma'],
},
])
await uploadAttachments(files)
}