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">
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import * as Misskey from 'misskey-js';
import { onMounted, ref } from 'vue';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { fromDriveFile, GridItem, RegisterLogItem } from '@/pages/admin/custom-emojis-grid.impl.js';
@ -96,7 +97,7 @@ import {
GridRowContextMenuEvent,
} from '@/components/grid/grid-event.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 XRegisterLogs from '@/pages/admin/custom-emojis-grid.register.logs.vue';
@ -212,21 +213,35 @@ async function onClearClicked() {
}
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 uploadedItems = await Promise.all(
uploadedItems.push(
...await os.promiseDialog(
Promise.all(
droppedFiles.map(async (it) => ({
droppedFile: it,
driveFile: await os.promiseDialog(
uploadFile(
driveFile: await uploadFile(
it.file,
selectedFolderId.value,
it.file.name.replace(/\.[^.]+$/, ''),
keepOriginalUploading.value,
),
),
}),
),
),
() => {
},
() => {
},
),
);
} catch (err: any) {
//
return;
}
const items = uploadedItems.map(({ droppedFile, driveFile }) => {
const item = fromDriveFile(driveFile);
@ -323,7 +338,9 @@ function onGridCellContextMenu(event: GridCellContextMenuEvent, currentState: Gr
function onGridCellValueChange(event: GridCellValueChangeEvent, currentState: GridCurrentState) {
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;
}
}
function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState) {

View File

@ -76,11 +76,18 @@ export async function readDataTransferItems(itemList: DataTransferItemList): Pro
}
function readDirectory(fileSystemDirectoryEntry: FileSystemDirectoryEntry): Promise<DroppedItem[]> {
return new Promise((resolve, reject) => {
fileSystemDirectoryEntry.createReader().readEntries(
async (entries) => resolve(await Promise.all(entries.map(readEntry))),
reject,
);
return new Promise(async (resolve, reject) => {
const allEntries = Array.of<FileSystemEntry>();
const reader = fileSystemDirectoryEntry.createReader();
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}
*/
export function flattenDroppedFiles(items: DroppedItem[]): DroppedFile[] {
console.log(items);
const result = Array.of<DroppedFile>();
for (const item of items) {
if (item.isFile) {