feat: Add convert video container button
This commit is contained in:
parent
84da9d4cd4
commit
74a80b3405
@ -82,7 +82,7 @@ import { Autocomplete } from '@/scripts/autocomplete';
|
|||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import { stream } from '@/stream';
|
import { stream } from '@/stream';
|
||||||
import { selectFiles } from '@/scripts/select-file';
|
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 { defaultStore, notePostInterruptors, postFormActions } from '@/store';
|
||||||
import { throttle } from 'throttle-debounce';
|
import { throttle } from 'throttle-debounce';
|
||||||
import MkInfo from '@/components/ui/info.vue';
|
import MkInfo from '@/components/ui/info.vue';
|
||||||
@ -350,7 +350,7 @@ function focus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function chooseFileFrom(ev) {
|
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_) {
|
for (const file of files_) {
|
||||||
files.push(file);
|
files.push(file);
|
||||||
}
|
}
|
||||||
@ -358,10 +358,8 @@ function chooseFileFrom(ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function chooseFileFromEnc(ev) {
|
function chooseFileFromEnc(ev) {
|
||||||
selectFilesEnc(ev.currentTarget ?? ev.target, i18n.ts.attachVideoFile).then(files_ => {
|
selectFileEnc(ev.currentTarget ?? ev.target, i18n.ts.attachFile).then(files_ => {
|
||||||
for (const file of files_) {
|
files.push(files_);
|
||||||
files.push(file);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +94,17 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
|
|||||||
SOFTWARE.
|
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'
|
let targetVideoFormat = 'mp4'
|
||||||
console.log('start convert video');
|
console.log('start convert video');
|
||||||
let convertedVideoDataObj = await VideoConverter(sourceVideoFile, targetVideoFormat);
|
let convertedVideoDataObj = await VideoConverter(sourceVideoFile, targetVideoFormat);
|
||||||
@ -104,27 +113,13 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let convertedVideoFile = new File([convertedVideoDataObj.data], convertedVideoDataObj.name + "." + convertedVideoDataObj.format);
|
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 }) });
|
os.upload(convertedVideoFile, defaultStore.state.uploadFolder).then(driveFiles => {
|
||||||
}
|
res(driveFiles);
|
||||||
|
}).catch(e => {
|
||||||
const promises = Array.from(input.files).map(file => {
|
os.alert({
|
||||||
if (file.type.indexOf('video') !== -1) {
|
type: 'error',
|
||||||
console.log('convert video');
|
text: e
|
||||||
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
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -140,43 +135,6 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
|
|||||||
input.click();
|
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 ? {
|
os.popupMenu([label ? {
|
||||||
text: label,
|
text: label,
|
||||||
type: 'label'
|
type: 'label'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user