Compare commits
2 Commits
v1.2.0
...
infinum/fe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44d804319a | ||
|
|
cf12851e1d |
10
README.md
10
README.md
@@ -1,15 +1,9 @@
|
||||
# ng2-file-upload [](http://badge.fury.io/js/ng2-file-upload)
|
||||
# ng2-file-upload [](http://badge.fury.io/js/ng2-file-upload) [](https://npmjs.org/ng2-file-upload)[](https://ngx-slack.herokuapp.com)
|
||||
Easy to use Angular2 directives for files upload ([demo](http://valor-software.github.io/ng2-file-upload/))
|
||||
|
||||
Follow me [](https://twitter.com/valorkin) to be notified about new releases.
|
||||
|
||||
[](https://github.com/mgechev/angular2-style-guide)
|
||||
[](https://travis-ci.org/valor-software/ng2-file-upload)
|
||||
[](https://codeclimate.com/github/valor-software/ng2-file-upload)
|
||||
[](https://gitter.im/valor-software/ng2-bootstrap?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://travis-ci.org/valor-software/ng2-file-upload)
|
||||
[](https://david-dm.org/valor-software/ng2-file-upload)
|
||||
[](https://david-dm.org/valor-software/ng2-file-upload#info=devDependencies)
|
||||
[](https://waffle.io/valor-software/ng2-file-upload/metrics)
|
||||
|
||||
## Quick start
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface Headers {
|
||||
|
||||
export type ParsedResponseHeaders = {[headerFieldName:string]:string};
|
||||
|
||||
export type FilterFunction = {name:string, fn:(item?:FileLikeObject, options?:FileUploaderOptions)=>boolean};
|
||||
export type FilterFunction = {name:string, fn:(item?:FileLikeObject, options?:FileUploaderOptions)=>boolean|Promise<boolean>};
|
||||
|
||||
export interface FileUploaderOptions {
|
||||
allowedMimeType?:Array<string>;
|
||||
@@ -98,15 +98,15 @@ export class FileUploader {
|
||||
}
|
||||
|
||||
let temp = new FileLikeObject(some);
|
||||
if (this._isValidFile(temp, arrayOfFilters, options)) {
|
||||
this._isValidFile(temp, arrayOfFilters, options).then(() => {
|
||||
let fileItem = new FileItem(this, some, options);
|
||||
addedFileItems.push(fileItem);
|
||||
this.queue.push(fileItem);
|
||||
this._onAfterAddingFile(fileItem);
|
||||
} else {
|
||||
}).catch(() => {
|
||||
let filter = arrayOfFilters[this._failFilterIndex];
|
||||
this._onWhenAddingFileFailed(temp, filter, options);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (this.queue.length !== count) {
|
||||
this._onAfterAddingAll(addedFileItems);
|
||||
@@ -400,11 +400,27 @@ export class FileUploader {
|
||||
return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
|
||||
}
|
||||
|
||||
protected _isValidFile(file:FileLikeObject, filters:FilterFunction[], options:FileUploaderOptions):boolean {
|
||||
protected _isValidFile(file:FileLikeObject, filters:FilterFunction[], options:FileUploaderOptions): Promise<boolean> {
|
||||
if (!filters.length) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
this._failFilterIndex = -1;
|
||||
return !filters.length ? true : filters.every((filter:FilterFunction) => {
|
||||
this._failFilterIndex++;
|
||||
return filter.fn.call(this, file, options);
|
||||
|
||||
return Promise.all(
|
||||
filters.map((filter: FilterFunction) => {
|
||||
const isValid: boolean = filter.fn.call(this, file, options);
|
||||
|
||||
return Promise.resolve(isValid);
|
||||
})
|
||||
).then((values) => {
|
||||
const isValid = values.every((value: boolean) => {
|
||||
this._failFilterIndex++;
|
||||
|
||||
return value;
|
||||
})
|
||||
|
||||
return isValid ? Promise.resolve(isValid) : Promise.reject(isValid);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user