Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
fix: guard calling isFile on null/undefined webkit entry objects
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsasharegan committed Nov 14, 2017
1 parent 5d26e17 commit dbe0ad2
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 57 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export default class VueTransmit extends Vue {
handleDragLeave(e: DragEvent): void;
handleDragEnd(e: DragEvent): void;
onDrop(e: DragEvent): void;
paste(e: any): void;
paste(e: ClipboardEvent): void;
handleFiles(files: File[]): VTransmitFile[];
addFilesFromItems(items: any): void;
addFilesFromDirectory(directory: any, path: any): void;
addFilesFromItems(items: DataTransferItem[]): void;
addFilesFromDirectory(directory: WebKitDirectoryEntry, path: any): void;
mounted(): void;
}
2 changes: 2 additions & 0 deletions dist/types/src/core/utils.d.ts → dist/src/core/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ export interface IDimensions {
height: number;
}
export declare function resizeImg(file: VTransmitFile, dims: IDimensions): IDrawImageArgs;
export declare function webkitIsFile(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitFileEntry;
export declare function webkitIsDir(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitDirectoryEntry;
File renamed without changes.
27 changes: 22 additions & 5 deletions dist/vue-transmit.browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-transmit.browser.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/vue-transmit.browser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-transmit.browser.min.js.map

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions dist/vue-transmit.common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/vue-transmit.common.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-transmit.common.min.js.map

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions dist/vue-transmit.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-transmit.esm.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/vue-transmit.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-transmit.esm.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ async function rmDirContents(dirPath) {

async function main() {
try {
return await rmDirContents(resolve(__dirname, "../dist"))
return await Promise.all([
rmDirContents(resolve(__dirname, "../dist")),
rmDirContents(resolve(__dirname, "../types"))
])
} catch (err) {
console.error(err)
}
Expand Down
File renamed without changes.
70 changes: 48 additions & 22 deletions src/components/VueTransmit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ import Vue from "vue"
import { Component, Prop, Watch } from "vue-property-decorator"
import noop from "lodash-es/noop"
import identity from "lodash-es/identity"
import { READY_STATES, hbsRegex, hbsReplacer, objFactory, resizeImg, IDrawImageArgs, IDimensions } from "../core/utils"
import {
READY_STATES,
hbsRegex,
hbsReplacer,
objFactory,
resizeImg,
IDrawImageArgs,
IDimensions,
webkitIsFile,
webkitIsDir
} from "../core/utils"
import VTransmitFile from "../classes/VTransmitFile"
type FileSystemEntry = WebKitFileEntry | WebKitDirectoryEntry
const STATUSES = {
ADDED: "added",
QUEUED: "queued",
Expand Down Expand Up @@ -819,7 +831,7 @@ export default class VueTransmit extends Vue {
this.handleFiles(files)
}
}
paste(e): void {
paste(e: ClipboardEvent): void {
if (!e || !e.clipboardData || !e.clipboardData.items) {
return
}
Expand All @@ -832,14 +844,17 @@ export default class VueTransmit extends Vue {
handleFiles(files: File[]): VTransmitFile[] {
return files.map(this.addFile)
}
addFilesFromItems(items): void {
addFilesFromItems(items: DataTransferItem[]): void {
for (const item of items) {
if (item.webkitGetAsEntry) {
const entry = item.webkitGetAsEntry()
const entry: FileSystemEntry = item.webkitGetAsEntry()
if (entry == null) {
continue
}
if (entry.isFile) {
entry.file(this.addFile)
} else if (entry.isDirectory) {
if (webkitIsFile(entry)) {
entry.file(this.addFile as any)
} else if (webkitIsDir(entry)) {
this.addFilesFromDirectory(entry, entry.name)
}
} else if (item.getAsFile) {
Expand All @@ -849,22 +864,33 @@ export default class VueTransmit extends Vue {
}
}
}
addFilesFromDirectory(directory, path): void {
directory.createReader().readEntries(entries => {
for (const entry of entries) {
if (entry.isFile) {
entry.file(file => {
if (this.ignoreHiddenFiles && /^\./.test(file.name)) {
return
}
file.fullPath = `${path}/${file.name}`
this.addFile(file)
}, console.error)
} else if (entry.isDirectory) {
this.addFilesFromDirectory(entry, `${path}/${entry.name}`)
addFilesFromDirectory(directory: WebKitDirectoryEntry, path): void {
directory.createReader().readEntries(
<any>((entries: FileSystemEntry[]) => {
for (const entry of entries) {
if (entry == null) {
continue
}
if (webkitIsDir(entry)) {
this.addFilesFromDirectory(entry, `${path}/${entry.name}`)
continue
}
if (webkitIsFile(entry)) {
entry.file(
<any>((file: File) => {
if (this.ignoreHiddenFiles && /^\./.test(file.name)) {
return
}
;(file as any).fullPath = `${path}/${file.name}`
this.addFile(file)
}),
console.error
)
}
}
}
}, console.error)
}),
console.error
)
}
mounted() {
Expand Down
2 changes: 2 additions & 0 deletions types/src/core/utils.d.ts → src/core/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ export interface IDimensions {
height: number;
}
export declare function resizeImg(file: VTransmitFile, dims: IDimensions): IDrawImageArgs;
export declare function webkitIsFile(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitFileEntry;
export declare function webkitIsDir(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitDirectoryEntry;
8 changes: 8 additions & 0 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,11 @@ export function resizeImg(file: VTransmitFile, dims: IDimensions): IDrawImageArg

return imgCoords
}

export function webkitIsFile(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitFileEntry {
return entry.isFile
}

export function webkitIsDir(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitDirectoryEntry {
return entry.isDirectory
}
File renamed without changes.
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"module": "es2015",
"moduleResolution": "node",
"declaration": true,
"declarationDir": "./types",
"allowJs": false,
"experimentalDecorators": true,
"noImplicitAny": false,
Expand All @@ -17,8 +16,7 @@
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true,
"baseUrl": "./src/"
"skipLibCheck": true
},
"include": ["./src", "./index.ts"],
"exclude": ["node_modules", "vendor"]
Expand Down

0 comments on commit dbe0ad2

Please sign in to comment.