1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-07-03 04:56:48 +01:00

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

View file

@ -28,6 +28,7 @@
"@vue-macros/nuxt": "^0.0.2", "@vue-macros/nuxt": "^0.0.2",
"@vueuse/nuxt": "^9.5.0", "@vueuse/nuxt": "^9.5.0",
"blurhash": "^2.0.4", "blurhash": "^2.0.4",
"browser-fs-access": "^0.31.1",
"eslint": "^8.27.0", "eslint": "^8.27.0",
"esno": "^0.16.3", "esno": "^0.16.3",
"floating-vue": "2.0.0-beta.20", "floating-vue": "2.0.0-beta.20",

View file

@ -15,6 +15,7 @@ specifiers:
'@vue-macros/nuxt': ^0.0.2 '@vue-macros/nuxt': ^0.0.2
'@vueuse/nuxt': ^9.5.0 '@vueuse/nuxt': ^9.5.0
blurhash: ^2.0.4 blurhash: ^2.0.4
browser-fs-access: ^0.31.1
eslint: ^8.27.0 eslint: ^8.27.0
esno: ^0.16.3 esno: ^0.16.3
floating-vue: 2.0.0-beta.20 floating-vue: 2.0.0-beta.20
@ -49,6 +50,7 @@ devDependencies:
'@vue-macros/nuxt': 0.0.2_nuxt@3.0.0 '@vue-macros/nuxt': 0.0.2_nuxt@3.0.0
'@vueuse/nuxt': 9.5.0_nuxt@3.0.0 '@vueuse/nuxt': 9.5.0_nuxt@3.0.0
blurhash: 2.0.4 blurhash: 2.0.4
browser-fs-access: 0.31.1
eslint: 8.27.0 eslint: 8.27.0
esno: 0.16.3 esno: 0.16.3
floating-vue: 2.0.0-beta.20 floating-vue: 2.0.0-beta.20
@ -2388,6 +2390,10 @@ packages:
fill-range: 7.0.1 fill-range: 7.0.1
dev: true dev: true
/browser-fs-access/0.31.1:
resolution: {integrity: sha512-jMz9f56DkLM7LyA8wZYO7CtpoF3RdUk1/FXrnRNybgV0R5eqk/fgFWR0k5IMjPYgK4jmZecytP/UDO5WBi9Dhg==}
dev: true
/browserslist/4.21.4: /browserslist/4.21.4:
resolution: {integrity: sha512-CBHJJdDmgjl3daYjN5Cp5kbTf1mUhZoS+beLklHIvkOWscs83YAhLlF3Wsh/lciQYAcbBJgTOD44VtG31ZM4Hw==} resolution: {integrity: sha512-CBHJJdDmgjl3daYjN5Cp5kbTf1mUhZoS+beLklHIvkOWscs83YAhLlF3Wsh/lciQYAcbBJgTOD44VtG31ZM4Hw==}
engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}