diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue index 2b2ff24dd..c0a7028b2 100644 --- a/packages/client/src/components/post-form.vue +++ b/packages/client/src/components/post-form.vue @@ -82,7 +82,7 @@ import { Autocomplete } from '@/scripts/autocomplete'; import * as os from '@/os'; import { stream } from '@/stream'; import { selectFiles } from '@/scripts/select-file'; -import { selectFilesEnc } from '@/scripts/select-file-enc'; +import {selectFileEnc, selectFilesEnc} from '@/scripts/select-file-enc'; import { defaultStore, notePostInterruptors, postFormActions } from '@/store'; import { throttle } from 'throttle-debounce'; import MkInfo from '@/components/ui/info.vue'; @@ -350,7 +350,7 @@ function focus() { } function chooseFileFrom(ev) { - selectFiles(ev.currentTarget ?? ev.target, i18n.ts.attachFile).then(files_ => { + selectFiles(ev.currentTarget ?? ev.target, i18n.ts.attachVideoFile).then(files_ => { for (const file of files_) { files.push(file); } @@ -358,10 +358,8 @@ function chooseFileFrom(ev) { } function chooseFileFromEnc(ev) { - selectFilesEnc(ev.currentTarget ?? ev.target, i18n.ts.attachVideoFile).then(files_ => { - for (const file of files_) { - files.push(file); - } + selectFileEnc(ev.currentTarget ?? ev.target, i18n.ts.attachFile).then(files_ => { + files.push(files_); }); } diff --git a/packages/client/src/scripts/select-file-enc.ts b/packages/client/src/scripts/select-file-enc.ts index 1b23e0717..eae57aa00 100644 --- a/packages/client/src/scripts/select-file-enc.ts +++ b/packages/client/src/scripts/select-file-enc.ts @@ -94,8 +94,17 @@ function select(src: any, label: string | null, multiple: boolean): Promise { + if (file.type.indexOf('video') == -1) { + os.toast('It is not video file'); + return + } + + console.log('convert video'); + os.toast('Try convert to mp4'); + //convertVideo(file); + let sourceVideoFile = file; let targetVideoFormat = 'mp4' console.log('start convert video'); let convertedVideoDataObj = await VideoConverter(sourceVideoFile, targetVideoFormat); @@ -104,27 +113,13 @@ function select(src: any, label: string | null, multiple: boolean): Promise { os.alert({ type: 'error', text: e }) }); - } - - const promises = Array.from(input.files).map(file => { - if (file.type.indexOf('video') !== -1) { - console.log('convert video'); - os.toast('Try convert to mp4'); - convertVideo(file); - } else { - os.toast('It is not video file'); - os.upload(file, defaultStore.state.uploadFolder, undefined, keepOriginal.value).then(res).catch(e => { os.alert({ type: 'error', text: e }) }); - } - }); - - - Promise.all(promises).then(driveFiles => { - res(multiple ? driveFiles : driveFiles[0]); - }).catch(e => { - os.alert({ - type: 'error', - text: e + os.upload(convertedVideoFile, defaultStore.state.uploadFolder).then(driveFiles => { + res(driveFiles); + }).catch(e => { + os.alert({ + type: 'error', + text: e + }); }); }); @@ -140,43 +135,6 @@ function select(src: any, label: string | null, multiple: boolean): Promise { - os.selectDriveFile(multiple).then(files => { - res(files); - }); - }; - - const chooseFileFromUrl = () => { - os.inputText({ - title: i18n.ts.uploadFromUrl, - type: 'url', - placeholder: i18n.ts.uploadFromUrlDescription - }).then(({ canceled, result: url }) => { - if (canceled) return; - - const marker = Math.random().toString(); // TODO: UUIDとか使う - - const connection = stream.useChannel('main'); - connection.on('urlUploadFinished', data => { - if (data.marker === marker) { - res(multiple ? [data.file] : data.file); - connection.dispose(); - } - }); - - os.api('drive/files/upload-from-url', { - url: url, - folderId: defaultStore.state.uploadFolder, - marker - }); - - os.alert({ - title: i18n.ts.uploadFromUrlRequested, - text: i18n.ts.uploadFromUrlMayTakeTime - }); - }); - }; - os.popupMenu([label ? { text: label, type: 'label'