fix over 100 file drop
This commit is contained in:
parent
57cd712064
commit
27020cb211
|
@ -72,6 +72,7 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||||
|
import * as Misskey from 'misskey-js';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||||
import { fromDriveFile, GridItem, RegisterLogItem } from '@/pages/admin/custom-emojis-grid.impl.js';
|
import { fromDriveFile, GridItem, RegisterLogItem } from '@/pages/admin/custom-emojis-grid.impl.js';
|
||||||
|
@ -96,7 +97,7 @@ import {
|
||||||
GridRowContextMenuEvent,
|
GridRowContextMenuEvent,
|
||||||
} from '@/components/grid/grid-event.js';
|
} from '@/components/grid/grid-event.js';
|
||||||
import { ColumnSetting } from '@/components/grid/column.js';
|
import { ColumnSetting } from '@/components/grid/column.js';
|
||||||
import { extractDroppedItems, flattenDroppedFiles } from '@/scripts/file-drop.js';
|
import { DroppedFile, extractDroppedItems, flattenDroppedFiles } from '@/scripts/file-drop.js';
|
||||||
import { optInGridUtils } from '@/components/grid/optin-utils.js';
|
import { optInGridUtils } from '@/components/grid/optin-utils.js';
|
||||||
import XRegisterLogs from '@/pages/admin/custom-emojis-grid.register.logs.vue';
|
import XRegisterLogs from '@/pages/admin/custom-emojis-grid.register.logs.vue';
|
||||||
|
|
||||||
|
@ -212,21 +213,35 @@ async function onClearClicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onDrop(ev: DragEvent) {
|
async function onDrop(ev: DragEvent) {
|
||||||
const droppedFiles = await extractDroppedItems(ev).then(it => flattenDroppedFiles(it));
|
isDragOver.value = false;
|
||||||
const uploadedItems = await Promise.all(
|
|
||||||
droppedFiles.map(async (it) => ({
|
const uploadedItems = Array.of<{ droppedFile: DroppedFile, driveFile: Misskey.entities.DriveFile }>();
|
||||||
droppedFile: it,
|
try {
|
||||||
driveFile: await os.promiseDialog(
|
const droppedFiles = await extractDroppedItems(ev).then(it => flattenDroppedFiles(it));
|
||||||
uploadFile(
|
uploadedItems.push(
|
||||||
it.file,
|
...await os.promiseDialog(
|
||||||
selectedFolderId.value,
|
Promise.all(
|
||||||
it.file.name.replace(/\.[^.]+$/, ''),
|
droppedFiles.map(async (it) => ({
|
||||||
keepOriginalUploading.value,
|
droppedFile: it,
|
||||||
|
driveFile: await uploadFile(
|
||||||
|
it.file,
|
||||||
|
selectedFolderId.value,
|
||||||
|
it.file.name.replace(/\.[^.]+$/, ''),
|
||||||
|
keepOriginalUploading.value,
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
() => {
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
},
|
||||||
),
|
),
|
||||||
}),
|
);
|
||||||
),
|
} catch (err: any) {
|
||||||
);
|
// ダイアログは共通部品側で出ているはずなので何もしない
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const items = uploadedItems.map(({ droppedFile, driveFile }) => {
|
const items = uploadedItems.map(({ droppedFile, driveFile }) => {
|
||||||
const item = fromDriveFile(driveFile);
|
const item = fromDriveFile(driveFile);
|
||||||
|
@ -323,7 +338,9 @@ function onGridCellContextMenu(event: GridCellContextMenuEvent, currentState: Gr
|
||||||
|
|
||||||
function onGridCellValueChange(event: GridCellValueChangeEvent, currentState: GridCurrentState) {
|
function onGridCellValueChange(event: GridCellValueChangeEvent, currentState: GridCurrentState) {
|
||||||
const { row, column, newValue } = event;
|
const { row, column, newValue } = event;
|
||||||
gridItems.value[row.index][column.setting.bindTo] = newValue;
|
if (gridItems.value.length > row.index && column.setting.bindTo in gridItems.value[row.index]) {
|
||||||
|
gridItems.value[row.index][column.setting.bindTo] = newValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState) {
|
function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState) {
|
||||||
|
|
|
@ -76,11 +76,18 @@ export async function readDataTransferItems(itemList: DataTransferItemList): Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
function readDirectory(fileSystemDirectoryEntry: FileSystemDirectoryEntry): Promise<DroppedItem[]> {
|
function readDirectory(fileSystemDirectoryEntry: FileSystemDirectoryEntry): Promise<DroppedItem[]> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
fileSystemDirectoryEntry.createReader().readEntries(
|
const allEntries = Array.of<FileSystemEntry>();
|
||||||
async (entries) => resolve(await Promise.all(entries.map(readEntry))),
|
const reader = fileSystemDirectoryEntry.createReader();
|
||||||
reject,
|
while (true) {
|
||||||
);
|
const entries = await new Promise<FileSystemEntry[]>((res, rej) => reader.readEntries(res, rej));
|
||||||
|
if (entries.length === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
allEntries.push(...entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(await Promise.all(allEntries.map(readEntry)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +109,7 @@ export async function readDataTransferItems(itemList: DataTransferItemList): Pro
|
||||||
* {@link DroppedItem}のリストからディレクトリを再帰的に検索し、ファイルのリストを取得する。
|
* {@link DroppedItem}のリストからディレクトリを再帰的に検索し、ファイルのリストを取得する。
|
||||||
*/
|
*/
|
||||||
export function flattenDroppedFiles(items: DroppedItem[]): DroppedFile[] {
|
export function flattenDroppedFiles(items: DroppedItem[]): DroppedFile[] {
|
||||||
|
console.log(items);
|
||||||
const result = Array.of<DroppedFile>();
|
const result = Array.of<DroppedFile>();
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (item.isFile) {
|
if (item.isFile) {
|
||||||
|
|
Loading…
Reference in New Issue