feat: Add convert video container button

This commit is contained in:
こけっち 2022-03-13 16:11:08 +09:00
parent 84da9d4cd4
commit 74a80b3405
No known key found for this signature in database
GPG Key ID: 21460619C5FC4DD1
2 changed files with 22 additions and 66 deletions

View File

@ -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_);
});
}

View File

@ -94,8 +94,17 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
SOFTWARE.
*/
async function convertVideo(input) {
let sourceVideoFile = input;
Array.from(input.files).map(async file => {
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,29 +113,15 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
// @ts-ignore
let convertedVideoFile = new File([convertedVideoDataObj.data], convertedVideoDataObj.name + "." + convertedVideoDataObj.format);
os.upload(convertedVideoFile, defaultStore.state.uploadFolder, undefined, keepOriginal.value).then(res).catch(e => { 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]);
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<Driv
input.click();
};
const chooseFileFromDrive = () => {
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'