change menu
This commit is contained in:
parent
90158790e6
commit
fd5b9aa5d0
@ -47,7 +47,7 @@
|
||||
<XNotePreview v-if="showPreview" class="preview" :text="text"/>
|
||||
<footer>
|
||||
<button v-tooltip="i18n.locale.attachFile" class="_button" @click="chooseFileFrom"><i class="fas fa-photo-video"></i></button>
|
||||
<button v-tooltip="i18n.locale.attachVideoFile" class="_button" @click="chooseFileFrom"><i class="far fa-file-video"></i></button>
|
||||
<button v-tooltip="i18n.locale.attachVideoFile" class="_button" @click="chooseFileFromEnc"><i class="far fa-file-video"></i></button>
|
||||
<button v-tooltip="i18n.locale.poll" class="_button" :class="{ active: poll }" @click="togglePoll"><i class="fas fa-poll-h"></i></button>
|
||||
<button v-tooltip="i18n.locale.useCw" class="_button" :class="{ active: useCw }" @click="useCw = !useCw"><i class="fas fa-eye-slash"></i></button>
|
||||
<button v-tooltip="i18n.locale.mention" class="_button" @click="insertMention"><i class="fas fa-at"></i></button>
|
||||
@ -82,6 +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 { defaultStore, notePostInterruptors, postFormActions } from '@/store';
|
||||
import { throttle } from 'throttle-debounce';
|
||||
import MkInfo from '@/components/ui/info.vue';
|
||||
@ -350,6 +351,14 @@ function chooseFileFrom(ev) {
|
||||
});
|
||||
}
|
||||
|
||||
function chooseFileFrom(ev) {
|
||||
selectFilesEnc(ev.currentTarget || ev.target, i18n.locale.attachFile).then(files_ => {
|
||||
for (const file of files_) {
|
||||
files.push(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function detachFile(id) {
|
||||
files = files.filter(x => x.id != id);
|
||||
}
|
||||
|
90
packages/client/src/scripts/select-file-enc.ts
Normal file
90
packages/client/src/scripts/select-file-enc.ts
Normal file
@ -0,0 +1,90 @@
|
||||
import * as os from '@/os';
|
||||
import { stream } from '@/stream';
|
||||
import { i18n } from '@/i18n';
|
||||
import { defaultStore } from '@/store';
|
||||
import { DriveFile } from 'misskey-js/built/entities';
|
||||
|
||||
function select(src: any, label: string | null, multiple: boolean): Promise<DriveFile | DriveFile[]> {
|
||||
return new Promise((res, rej) => {
|
||||
const chooseFileFromPc = () => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.multiple = multiple;
|
||||
input.onchange = () => {
|
||||
const promises = Array.from(input.files).map(file => os.upload(file, defaultStore.state.uploadFolder));
|
||||
|
||||
Promise.all(promises).then(driveFiles => {
|
||||
res(multiple ? driveFiles : driveFiles[0]);
|
||||
}).catch(e => {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: e
|
||||
});
|
||||
});
|
||||
|
||||
// 一応廃棄
|
||||
(window as any).__misskey_input_ref__ = null;
|
||||
};
|
||||
|
||||
// https://qiita.com/fukasawah/items/b9dc732d95d99551013d
|
||||
// iOS Safari で正常に動かす為のおまじない
|
||||
(window as any).__misskey_input_ref__ = input;
|
||||
|
||||
input.click();
|
||||
};
|
||||
|
||||
const chooseFileFromDrive = () => {
|
||||
os.selectDriveFile(multiple).then(files => {
|
||||
res(files);
|
||||
});
|
||||
};
|
||||
|
||||
const chooseFileFromUrl = () => {
|
||||
os.inputText({
|
||||
title: i18n.locale.uploadFromUrl,
|
||||
type: 'url',
|
||||
placeholder: i18n.locale.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.locale.uploadFromUrlRequested,
|
||||
text: i18n.locale.uploadFromUrlMayTakeTime
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
os.popupMenu([label ? {
|
||||
text: label,
|
||||
type: 'label'
|
||||
} : undefined, {
|
||||
text: i18n.locale.upload,
|
||||
icon: 'fas fa-upload',
|
||||
action: chooseFileFromPc
|
||||
}], src);
|
||||
});
|
||||
}
|
||||
|
||||
export function selectFile(src: any, label: string | null = null): Promise<DriveFile> {
|
||||
return select(src, label, false) as Promise<DriveFile>;
|
||||
}
|
||||
|
||||
export function selectFiles(src: any, label: string | null = null): Promise<DriveFile[]> {
|
||||
return select(src, label, true) as Promise<DriveFile[]>;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user