Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the detection of folders #41

Merged
merged 3 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
750 changes: 452 additions & 298 deletions dist/vue-file-agent.common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-file-agent.common.js.map

Large diffs are not rendered by default.

750 changes: 452 additions & 298 deletions dist/vue-file-agent.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-file-agent.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-file-agent.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-file-agent.umd.min.js.map

Large diffs are not rendered by default.

1,329 changes: 810 additions & 519 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"@types/tus-js-client": "^1.8.0",
"@vue/cli-plugin-typescript": "^4.1.0",
"@vue/cli-plugin-unit-jest": "^4.1.0",
"@vue/cli-service": "^4.1.0",
"@vue/cli-service": "^4.2.3",
"@vue/test-utils": "1.0.0-beta.29",
"node-sass": "^4.12.0",
"node-sass": "^4.13.1",
"prettier": "1.19.1",
"sass-loader": "^8.0.0",
"tus-js-client": "^1.8.0",
Expand Down
22 changes: 18 additions & 4 deletions src/lib/drop-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function getFilesFromDroppedItems(dataTransfer: DataTransfer): Promise<File[] | FileList> {
return new Promise((resolve) => {
if (!includesFolder(dataTransfer.files)) {
if (!includesFolder(dataTransfer)) {
return resolve(dataTransfer.files);
}
const files: File[] = [];
Expand Down Expand Up @@ -74,12 +74,26 @@ function getEntries(entry: any): Promise<File[]> | undefined {
});
}

function includesFolder(files: FileList): boolean {
if (!files.length) {
function includesFolder(transfer: DataTransfer): boolean {
if (!transfer.files.length) {
return true; // if dropping only folders, no files will exist
}

// Loop through the dropped items and log their data
for (const item of transfer.items) {
if (item.webkitGetAsEntry != null) {
const entry = item.webkitGetAsEntry();

if (entry && entry.isDirectory) {
return true;
}
}
}

const files: FileList = transfer.files;

// tslint:disable-next-line
for (var i = 0; i < files.length; i++) {
for (let i = 0; i < files.length; i++) {
// A folder has no type and has a size that is a multiple of 4096
if (!files[i].type && files[i].size % 4096 === 0) {
return true;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"baseUrl": ".",
"declaration": true,
"declarationDir": "types",
"downlevelIteration": true,
"types": [
"webpack-env",
"jest"
Expand Down