diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-12-27 14:36:33 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-12-27 14:36:33 +0900 |
| commit | 9384f5399da39e53855beb8e7f8ded1aa56bf72e (patch) | |
| tree | ce5959571a981b9c4047da3c7b3fd080aa44222c /packages/client/src/scripts/select-file.ts | |
| parent | wip: retention for dashboard (diff) | |
| download | sharkey-9384f5399da39e53855beb8e7f8ded1aa56bf72e.tar.gz sharkey-9384f5399da39e53855beb8e7f8ded1aa56bf72e.tar.bz2 sharkey-9384f5399da39e53855beb8e7f8ded1aa56bf72e.zip | |
rename: client -> frontend
Diffstat (limited to 'packages/client/src/scripts/select-file.ts')
| -rw-r--r-- | packages/client/src/scripts/select-file.ts | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/packages/client/src/scripts/select-file.ts b/packages/client/src/scripts/select-file.ts deleted file mode 100644 index ec5f8f65e9..0000000000 --- a/packages/client/src/scripts/select-file.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { ref } from 'vue'; -import { DriveFile } from 'misskey-js/built/entities'; -import * as os from '@/os'; -import { stream } from '@/stream'; -import { i18n } from '@/i18n'; -import { defaultStore } from '@/store'; -import { uploadFile } from '@/scripts/upload'; - -function select(src: any, label: string | null, multiple: boolean): Promise<DriveFile | DriveFile[]> { - return new Promise((res, rej) => { - const keepOriginal = ref(defaultStore.state.keepOriginalUploading); - - const chooseFileFromPc = () => { - const input = document.createElement('input'); - input.type = 'file'; - input.multiple = multiple; - input.onchange = () => { - const promises = Array.from(input.files).map(file => uploadFile(file, defaultStore.state.uploadFolder, undefined, keepOriginal.value)); - - Promise.all(promises).then(driveFiles => { - res(multiple ? driveFiles : driveFiles[0]); - }).catch(err => { - // アップロードのエラーは uploadFile 内でハンドリングされているためアラートダイアログを出したりはしてはいけない - }); - - // 一応廃棄 - (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.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', urlResponse => { - if (urlResponse.marker === marker) { - res(multiple ? [urlResponse.file] : urlResponse.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', - } : undefined, { - type: 'switch', - text: i18n.ts.keepOriginalUploading, - ref: keepOriginal, - }, { - text: i18n.ts.upload, - icon: 'ti ti-upload', - action: chooseFileFromPc, - }, { - text: i18n.ts.fromDrive, - icon: 'ti ti-cloud', - action: chooseFileFromDrive, - }, { - text: i18n.ts.fromUrl, - icon: 'ti ti-link', - action: chooseFileFromUrl, - }], 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[]>; -} |