fix: only handle supported file types

This commit is contained in:
ShittyKopper 2023-12-28 23:38:59 +03:00
parent c625dd2eac
commit ae6a428e91
1 changed files with 7 additions and 2 deletions

View File

@ -20,7 +20,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkTextarea v-model="caption" autofocus :placeholder="i18n.ts.inputNewDescription"> <MkTextarea v-model="caption" autofocus :placeholder="i18n.ts.inputNewDescription">
<template #label>{{ i18n.ts.caption }}</template> <template #label>{{ i18n.ts.caption }}</template>
</MkTextarea> </MkTextarea>
<div v-if="file.type.startsWith('image/')" :class="$style.ocr"> <div v-if="canOcr" :class="$style.ocr">
<span :class="$style.ocrHeader">{{ i18n.ts._ocr.header }}</span> <span :class="$style.ocrHeader">{{ i18n.ts._ocr.header }}</span>
<div :class="$style.ocrForm"> <div :class="$style.ocrForm">
<MkSelect v-model="ocrLanguage"> <MkSelect v-model="ocrLanguage">
@ -34,7 +34,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { shallowRef, ref } from 'vue'; import { shallowRef, ref, computed } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import * as ocrLanguages from 'tesseract.js/src/constants/languages.js'; import * as ocrLanguages from 'tesseract.js/src/constants/languages.js';
import MkModalWindow from '@/components/MkModalWindow.vue'; import MkModalWindow from '@/components/MkModalWindow.vue';
@ -59,6 +59,11 @@ const emit = defineEmits<{
const dialog = shallowRef<InstanceType<typeof MkModalWindow>>(); const dialog = shallowRef<InstanceType<typeof MkModalWindow>>();
const caption = ref(props.default); const caption = ref(props.default);
// https://github.com/naptha/tesseract.js/blob/master/docs/image-format.md
const OCR_SUPPORTED_FILETYPES = ['image/bmp', 'image/jpeg', 'image/png', 'image/webp'];
const canOcr = computed(() => OCR_SUPPORTED_FILETYPES.includes(props.file.type));
const ocrLanguage = ref('eng'); const ocrLanguage = ref('eng');
async function ok() { async function ok() {