fix over 100 file drop

This commit is contained in:
samunohito 2024-02-03 20:11:11 +09:00
parent 57cd712064
commit 27020cb211
2 changed files with 45 additions and 20 deletions

View File

@ -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) {
isDragOver.value = false;
const uploadedItems = Array.of<{ droppedFile: DroppedFile, driveFile: Misskey.entities.DriveFile }>();
try {
const droppedFiles = await extractDroppedItems(ev).then(it => flattenDroppedFiles(it)); const droppedFiles = await extractDroppedItems(ev).then(it => flattenDroppedFiles(it));
const uploadedItems = await Promise.all( uploadedItems.push(
...await os.promiseDialog(
Promise.all(
droppedFiles.map(async (it) => ({ droppedFiles.map(async (it) => ({
droppedFile: it, droppedFile: it,
driveFile: await os.promiseDialog( driveFile: await uploadFile(
uploadFile(
it.file, it.file,
selectedFolderId.value, selectedFolderId.value,
it.file.name.replace(/\.[^.]+$/, ''), it.file.name.replace(/\.[^.]+$/, ''),
keepOriginalUploading.value, 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,8 +338,10 @@ 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;
if (gridItems.value.length > row.index && column.setting.bindTo in gridItems.value[row.index]) {
gridItems.value[row.index][column.setting.bindTo] = newValue; gridItems.value[row.index][column.setting.bindTo] = newValue;
} }
}
function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState) { function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState) {
optInGridUtils.defaultKeyDownHandler(gridItems, event, currentState); optInGridUtils.defaultKeyDownHandler(gridItems, event, currentState);

View File

@ -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) {