Compare commits
2 Commits
duykhang53
...
koenvander
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95d57780d0 | ||
|
|
5a6a4471f3 |
11
.travis.yml
11
.travis.yml
@@ -1,13 +1,11 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10.15.0"
|
||||
|
||||
sudo: required
|
||||
services:
|
||||
- xvfb
|
||||
- "6"
|
||||
|
||||
before_install:
|
||||
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
|
||||
- export CHROME_BIN=chromium-browser
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
|
||||
script:
|
||||
- npm run pretest
|
||||
@@ -17,7 +15,6 @@ after_success:
|
||||
- ./node_modules/.bin/codecov
|
||||
|
||||
addons:
|
||||
chrome: stable
|
||||
firefox: "latest"
|
||||
apt:
|
||||
sources:
|
||||
|
||||
@@ -67,7 +67,8 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
||||
5. `formatDataFunction` - Function to modify the request body. 'DisableMultipart' must be 'true' for this function to be called.
|
||||
6. `formatDataFunctionIsAsync` - Informs if the function sent in 'formatDataFunction' is asynchronous. Defaults to false.
|
||||
7. `parametersBeforeFiles` - States if additional parameters should be appended before or after the file. Defaults to false.
|
||||
|
||||
8. `uploadFilesInSingleRequest` - If 'true', all files in the queue will be uploaded using one multipart request. Defaults to false. Notice this cannot be combined with 'disableMultipart' is 'true'.
|
||||
|
||||
### Events
|
||||
|
||||
- `fileOver` - it fires during 'over' and 'out' events for Drop Area; returns `boolean`: `true` if file is over Drop Area, `false` in case of out.
|
||||
|
||||
@@ -18,8 +18,9 @@ export class SimpleDemoComponent {
|
||||
constructor (){
|
||||
this.uploader = new FileUploader({
|
||||
url: URL,
|
||||
disableMultipart: true, // 'DisableMultipart' must be 'true' for formatDataFunction to be called.
|
||||
formatDataFunctionIsAsync: true,
|
||||
disableMultipart: false, // 'DisableMultipart' must be 'true' for formatDataFunction to be called.
|
||||
uploadFilesInSingleRequest: true,
|
||||
formatDataFunctionIsAsync: false,
|
||||
formatDataFunction: async (item) => {
|
||||
return new Promise( (resolve, reject) => {
|
||||
resolve({
|
||||
|
||||
@@ -48,7 +48,6 @@ module.exports = function (config) {
|
||||
|
||||
if (process.env.TRAVIS) {
|
||||
configuration.browsers = ['Chrome_travis_ci'];
|
||||
configuration.singleRun = true;
|
||||
}
|
||||
|
||||
if (process.env.SAUCE) {
|
||||
|
||||
12008
package-lock.json
generated
12008
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,9 @@
|
||||
"lite-server": "lite-server -c demo/bs-config.json",
|
||||
"demo.serve": "run-s build link demo.build lite-server",
|
||||
"demo.gh-pages": "run-s build demo.build demo.deploy",
|
||||
"demo.build": "ng build -prod --aot",
|
||||
"demo.build": "ng build",
|
||||
"demo.build.watch": "ng build --watch",
|
||||
"demo.buildOld": "ng build -prod --aot",
|
||||
"demo.deploy": "gh-pages -d demo/dist",
|
||||
"link": "ngm link -p src --here",
|
||||
"lint": "exit 0",
|
||||
@@ -84,8 +86,8 @@
|
||||
"jasmine-core": "2.5.2",
|
||||
"jasmine-data-provider": "2.2.0",
|
||||
"jasmine-spec-reporter": "3.2.0",
|
||||
"karma": "^4.2.0",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma": "1.4.0",
|
||||
"karma-chrome-launcher": "^2.0.0",
|
||||
"karma-cli": "^1.0.1",
|
||||
"karma-coverage-istanbul-reporter": "^1.3.0",
|
||||
"karma-jasmine": "^1.0.2",
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { Directive, ElementRef, EventEmitter, HostListener, Input, Output } from '@angular/core';
|
||||
import { Directive, EventEmitter, ElementRef, HostListener, Input, Output } from '@angular/core';
|
||||
|
||||
import { FileUploader, FileUploaderOptions, FilterFunction } from './file-uploader.class';
|
||||
import { FileUploader, FileUploaderOptions } from './file-uploader.class';
|
||||
|
||||
@Directive({ selector: '[ng2FileDrop]' })
|
||||
export class FileDropDirective {
|
||||
@Input() public uploader: FileUploader;
|
||||
// tslint:disable-next-line:no-input-rename
|
||||
@Input('ng2FileFilter') public filter: FilterFunction['fn'];
|
||||
@Output() public fileOver: EventEmitter<any> = new EventEmitter();
|
||||
@Output() public onFileDrop: EventEmitter<FileList> = new EventEmitter<FileList>();
|
||||
@Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
|
||||
protected element: ElementRef;
|
||||
|
||||
@@ -24,7 +22,7 @@ export class FileDropDirective {
|
||||
return {};
|
||||
}
|
||||
|
||||
@HostListener('drop', ['$event'])
|
||||
@HostListener('drop', [ '$event' ])
|
||||
public onDrop(event: any): void {
|
||||
let transfer = this._getTransfer(event);
|
||||
if (!transfer) {
|
||||
@@ -32,17 +30,14 @@ export class FileDropDirective {
|
||||
}
|
||||
|
||||
let options = this.getOptions();
|
||||
let filters = typeof this.filter === 'function' ? [{
|
||||
name: 'ng2FileDropDirectiveFilter',
|
||||
fn: this.filter
|
||||
}, ...options.filters] : this.getFilters();
|
||||
let filters = this.getFilters();
|
||||
this._preventAndStop(event);
|
||||
this.uploader.addToQueue(transfer.files, options, filters);
|
||||
this.fileOver.emit(false);
|
||||
this.onFileDrop.emit(transfer.files);
|
||||
}
|
||||
|
||||
@HostListener('dragover', ['$event'])
|
||||
@HostListener('dragover', [ '$event' ])
|
||||
public onDragOver(event: any): void {
|
||||
let transfer = this._getTransfer(event);
|
||||
if (!this._haveFiles(transfer.types)) {
|
||||
@@ -54,10 +49,10 @@ export class FileDropDirective {
|
||||
this.fileOver.emit(true);
|
||||
}
|
||||
|
||||
@HostListener('dragleave', ['$event'])
|
||||
@HostListener('dragleave', [ '$event' ])
|
||||
public onDragLeave(event: any): any {
|
||||
if ((this as any).element) {
|
||||
if (event.currentTarget === (this as any).element[0]) {
|
||||
if (event.currentTarget === (this as any).element[ 0 ]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -66,11 +61,11 @@ export class FileDropDirective {
|
||||
this.fileOver.emit(false);
|
||||
}
|
||||
|
||||
protected _getTransfer(event: any): DragEvent['dataTransfer'] {
|
||||
protected _getTransfer(event: any): any {
|
||||
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
|
||||
}
|
||||
|
||||
protected _preventAndStop(event: Event): any {
|
||||
protected _preventAndStop(event: any): any {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Directive, ElementRef, EventEmitter, HostListener, Input, Output } from '@angular/core';
|
||||
import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core';
|
||||
|
||||
import { FileUploader, FilterFunction } from './file-uploader.class';
|
||||
import { FileUploader } from './file-uploader.class';
|
||||
|
||||
@Directive({ selector: '[ng2FileSelect]' })
|
||||
export class FileSelectDirective {
|
||||
@Input() public uploader: FileUploader;
|
||||
// tslint:disable-next-line:no-input-rename
|
||||
@Input('ng2FileFilter') public filter: FilterFunction['fn'];
|
||||
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
|
||||
protected element: ElementRef;
|
||||
@@ -31,10 +29,7 @@ export class FileSelectDirective {
|
||||
public onChange(): any {
|
||||
let files = this.element.nativeElement.files;
|
||||
let options = this.getOptions();
|
||||
let filters = typeof this.filter === 'function' ? [{
|
||||
name: 'ng2FileSelectDirectiveFilter',
|
||||
fn: this.filter
|
||||
}, ...options.filters] : this.getFilters();
|
||||
let filters = this.getFilters();
|
||||
|
||||
this.uploader.addToQueue(files, options, filters);
|
||||
this.onFileSelected.emit(files);
|
||||
|
||||
@@ -12,11 +12,11 @@ export interface Headers {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export type ParsedResponseHeaders = { [headerFieldName: string]: string };
|
||||
export type ParsedResponseHeaders = { [ headerFieldName: string ]: string };
|
||||
|
||||
export interface FilterFunction {
|
||||
name: string;
|
||||
fn(this: FileUploader, item?: FileLikeObject, options?: FileUploaderOptions, queueIndex?: number): boolean | Promise<boolean>;
|
||||
export type FilterFunction = {
|
||||
name: string,
|
||||
fn: (item?: FileLikeObject, options?: FileUploaderOptions) => boolean
|
||||
};
|
||||
|
||||
export interface FileUploaderOptions {
|
||||
@@ -35,10 +35,11 @@ export interface FileUploaderOptions {
|
||||
disableMultipart?: boolean;
|
||||
itemAlias?: string;
|
||||
authTokenHeader?: string;
|
||||
additionalParameter?: { [key: string]: any };
|
||||
additionalParameter?: { [ key: string ]: any };
|
||||
parametersBeforeFiles?: boolean;
|
||||
formatDataFunction?: Function;
|
||||
formatDataFunctionIsAsync?: boolean;
|
||||
uploadFilesInSingleRequest?: boolean;
|
||||
}
|
||||
|
||||
export class FileUploader {
|
||||
@@ -59,19 +60,19 @@ export class FileUploader {
|
||||
removeAfterUpload: false,
|
||||
disableMultipart: false,
|
||||
formatDataFunction: (item: FileItem) => item._file,
|
||||
formatDataFunctionIsAsync: false
|
||||
formatDataFunctionIsAsync: false,
|
||||
uploadFilesInSingleRequest : false
|
||||
};
|
||||
|
||||
protected _failFilterIndex: number;
|
||||
|
||||
public constructor(options: FileUploaderOptions) {
|
||||
this.setOptions(options);
|
||||
this.response = new EventEmitter<any>();
|
||||
this.response = new EventEmitter<any>();
|
||||
}
|
||||
|
||||
public setOptions(options: FileUploaderOptions): void {
|
||||
this.options = Object.assign(this.options, options);
|
||||
|
||||
this.authToken = this.options.authToken;
|
||||
this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
|
||||
this.autoUpload = this.options.autoUpload;
|
||||
@@ -89,39 +90,35 @@ export class FileUploader {
|
||||
this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
|
||||
}
|
||||
|
||||
for (const q of this.queue) {
|
||||
q.url = this.options.url;
|
||||
for (let i = 0; i < this.queue.length; i++) {
|
||||
this.queue[ i ].url = this.options.url;
|
||||
}
|
||||
}
|
||||
|
||||
public async addToQueue(files: FileList, options?: FileUploaderOptions, filters?: FilterFunction[] | string): Promise<void> {
|
||||
public addToQueue(files: File[], options?: FileUploaderOptions, filters?: FilterFunction[] | string): void {
|
||||
let list: File[] = [];
|
||||
// tslint:disable-next-line:prefer-for-of
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
list.push(files[i]);
|
||||
for (let file of files) {
|
||||
list.push(file);
|
||||
}
|
||||
|
||||
let arrayOfFilters = this._getFilters(filters);
|
||||
let count = this.queue.length;
|
||||
let addedFileItems: FileItem[] = [];
|
||||
let idx = 0;
|
||||
|
||||
for (const some of list) {
|
||||
list.map((some: File) => {
|
||||
if (!options) {
|
||||
options = this.options;
|
||||
}
|
||||
|
||||
let temp = new FileLikeObject(some);
|
||||
if (await this._isValidFile(temp, arrayOfFilters, options, idx++)) {
|
||||
if (this._isValidFile(temp, arrayOfFilters, options)) {
|
||||
let fileItem = new FileItem(this, some, options);
|
||||
addedFileItems.push(fileItem);
|
||||
this.queue.push(fileItem);
|
||||
this._onAfterAddingFile(fileItem);
|
||||
} else {
|
||||
let filter = arrayOfFilters[this._failFilterIndex];
|
||||
let filter = arrayOfFilters[ this._failFilterIndex ];
|
||||
this._onWhenAddingFileFailed(temp, filter, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (this.queue.length !== count) {
|
||||
this._onAfterAddingAll(addedFileItems);
|
||||
this.progress = this._getTotalProgress();
|
||||
@@ -134,7 +131,7 @@ export class FileUploader {
|
||||
|
||||
public removeFromQueue(value: FileItem): void {
|
||||
let index = this.getIndexOfItem(value);
|
||||
let item = this.queue[index];
|
||||
let item = this.queue[ index ];
|
||||
if (item.isUploading) {
|
||||
item.cancel();
|
||||
}
|
||||
@@ -144,39 +141,54 @@ export class FileUploader {
|
||||
|
||||
public clearQueue(): void {
|
||||
while (this.queue.length) {
|
||||
this.queue[0].remove();
|
||||
this.queue[ 0 ].remove();
|
||||
}
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
public uploadItem(value: FileItem): void {
|
||||
let index = this.getIndexOfItem(value);
|
||||
let item = this.queue[index];
|
||||
public uploadItem(value: FileItem): void {
|
||||
this.uploadItems(new Array<FileItem>(value));
|
||||
}
|
||||
|
||||
public uploadItems(values: FileItem[]): void {
|
||||
values.forEach(element => {
|
||||
let index = this.getIndexOfItem(element);
|
||||
let item = this.queue[ index ];
|
||||
item._prepareToUploading();
|
||||
});
|
||||
|
||||
let transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
|
||||
item._prepareToUploading();
|
||||
|
||||
if (this.isUploading) {
|
||||
return;
|
||||
}
|
||||
this.isUploading = true;
|
||||
(this as any)[transport](item);
|
||||
this.isUploading = true;
|
||||
(this as any)[ transport ](values);
|
||||
}
|
||||
|
||||
public cancelItem(value: FileItem): void {
|
||||
let index = this.getIndexOfItem(value);
|
||||
let item = this.queue[index];
|
||||
let item = this.queue[ index ];
|
||||
let prop = this.options.isHTML5 ? item._xhr : item._form;
|
||||
if (item && item.isUploading) {
|
||||
prop.abort();
|
||||
}
|
||||
}
|
||||
|
||||
public uploadAll(): void {
|
||||
public uploadAll(): void {
|
||||
let items = this.getNotUploadedItems().filter((item: FileItem) => !item.isUploading);
|
||||
if (!items.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
items.map((item: FileItem) => item._prepareToUploading());
|
||||
items[0].upload();
|
||||
|
||||
if (this.options.uploadFilesInSingleRequest){
|
||||
this.uploadItems(items);
|
||||
}
|
||||
else{
|
||||
items[ 0 ].upload();
|
||||
}
|
||||
}
|
||||
|
||||
public cancelAll(): void {
|
||||
@@ -279,12 +291,27 @@ export class FileUploader {
|
||||
public _onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
item._onComplete(response, status, headers);
|
||||
this.onCompleteItem(item, response, status, headers);
|
||||
let nextItem = this.getReadyItems()[0];
|
||||
|
||||
if (!this.options.uploadFilesInSingleRequest)
|
||||
{
|
||||
let nextItem = this.getReadyItems()[ 0 ];
|
||||
this.isUploading = false;
|
||||
if (nextItem) {
|
||||
nextItem.upload();
|
||||
return;
|
||||
}
|
||||
this.onCompleteAll();
|
||||
this.progress = this._getTotalProgress();
|
||||
this._render();
|
||||
}
|
||||
}
|
||||
|
||||
public _onCompleteAllItems(items: FileItem[], response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
items.forEach(item => {
|
||||
item._onComplete(response, status, headers);
|
||||
this.onCompleteItem(item, response, status, headers);
|
||||
});
|
||||
this.isUploading = false;
|
||||
if (nextItem) {
|
||||
nextItem.upload();
|
||||
return;
|
||||
}
|
||||
this.onCompleteAll();
|
||||
this.progress = this._getTotalProgress();
|
||||
this._render();
|
||||
@@ -293,93 +320,109 @@ export class FileUploader {
|
||||
protected _headersGetter(parsedHeaders: ParsedResponseHeaders): any {
|
||||
return (name: any): any => {
|
||||
if (name) {
|
||||
return parsedHeaders[name.toLowerCase()] || void 0;
|
||||
return parsedHeaders[ name.toLowerCase() ] || void 0;
|
||||
}
|
||||
return parsedHeaders;
|
||||
};
|
||||
}
|
||||
|
||||
protected _xhrTransport(item: FileItem): any {
|
||||
protected _xhrTransport(items: FileItem[]): any {
|
||||
let that = this;
|
||||
let xhr = item._xhr = new XMLHttpRequest();
|
||||
let firstItem = items[0];
|
||||
let xhr = firstItem._xhr = new XMLHttpRequest();
|
||||
let sendable: any;
|
||||
this._onBeforeUploadItem(item);
|
||||
|
||||
if (typeof item._file.size !== 'number') {
|
||||
throw new TypeError('The file specified is no longer valid');
|
||||
}
|
||||
items.forEach(item => {
|
||||
this._onBeforeUploadItem(item);
|
||||
});
|
||||
|
||||
items.forEach(item => {
|
||||
if (typeof item._file.size !== 'number') {
|
||||
throw new TypeError('The file specified is no longer valid');
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.options.disableMultipart) {
|
||||
sendable = new FormData();
|
||||
this._onBuildItemForm(item, sendable);
|
||||
items.forEach(item => {
|
||||
this._onBuildItemForm(item, sendable);
|
||||
});
|
||||
|
||||
const appendFiles = () => {
|
||||
items.forEach(item => {
|
||||
sendable.append(item.alias, item._file, item.file.name)
|
||||
});
|
||||
};
|
||||
|
||||
const appendFile = () => sendable.append(item.alias, item._file, item.file.name);
|
||||
if (!this.options.parametersBeforeFiles) {
|
||||
appendFile();
|
||||
appendFiles();
|
||||
}
|
||||
|
||||
// For AWS, Additional Parameters must come BEFORE Files
|
||||
if (this.options.additionalParameter !== undefined) {
|
||||
Object.keys(this.options.additionalParameter).forEach((key: string) => {
|
||||
let paramVal = this.options.additionalParameter[key];
|
||||
let paramVal = this.options.additionalParameter[ key ];
|
||||
// Allow an additional parameter to include the filename
|
||||
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
|
||||
paramVal = paramVal.replace('{{file_name}}', item.file.name);
|
||||
if (!this.options.uploadFilesInSingleRequest && typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
|
||||
paramVal = paramVal.replace('{{file_name}}', firstItem.file.name);
|
||||
}
|
||||
sendable.append(key, paramVal);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.options.parametersBeforeFiles) {
|
||||
appendFile();
|
||||
appendFiles();
|
||||
}
|
||||
} else {
|
||||
sendable = this.options.formatDataFunction(item);
|
||||
sendable = this.options.formatDataFunction(firstItem);
|
||||
}
|
||||
|
||||
xhr.upload.onprogress = (event: any) => {
|
||||
let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
|
||||
this._onProgressItem(item, progress);
|
||||
};
|
||||
xhr.onload = () => {
|
||||
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
||||
let response = this._transformResponse(xhr.response, headers);
|
||||
let gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
|
||||
let method = '_on' + gist + 'Item';
|
||||
(this as any)[method](item, response, xhr.status, headers);
|
||||
this._onCompleteItem(item, response, xhr.status, headers);
|
||||
items.forEach(item => {
|
||||
(this as any)[ method ](item, response, xhr.status, headers);
|
||||
});
|
||||
this._onCompleteAllItems(items, response, xhr.status, headers);
|
||||
};
|
||||
xhr.onerror = () => {
|
||||
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
||||
let response = this._transformResponse(xhr.response, headers);
|
||||
this._onErrorItem(item, response, xhr.status, headers);
|
||||
this._onCompleteItem(item, response, xhr.status, headers);
|
||||
items.forEach(item => {
|
||||
this._onErrorItem(firstItem, response, xhr.status, headers);
|
||||
});
|
||||
this._onCompleteAllItems(items, response, xhr.status, headers);
|
||||
};
|
||||
xhr.onabort = () => {
|
||||
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
||||
let response = this._transformResponse(xhr.response, headers);
|
||||
this._onCancelItem(item, response, xhr.status, headers);
|
||||
this._onCompleteItem(item, response, xhr.status, headers);
|
||||
items.forEach(item => {
|
||||
this._onCancelItem(firstItem, response, xhr.status, headers);
|
||||
});
|
||||
this._onCompleteAllItems(items, response, xhr.status, headers);
|
||||
};
|
||||
xhr.open(item.method, item.url, true);
|
||||
xhr.withCredentials = item.withCredentials;
|
||||
xhr.open(firstItem.method, firstItem.url, true);
|
||||
xhr.withCredentials = firstItem.withCredentials;
|
||||
if (this.options.headers) {
|
||||
for (let header of this.options.headers) {
|
||||
xhr.setRequestHeader(header.name, header.value);
|
||||
}
|
||||
}
|
||||
if (item.headers.length) {
|
||||
for (let header of item.headers) {
|
||||
if (firstItem.headers.length) {
|
||||
for (let header of firstItem.headers) {
|
||||
xhr.setRequestHeader(header.name, header.value);
|
||||
}
|
||||
}
|
||||
if (this.authToken) {
|
||||
xhr.setRequestHeader(this.authTokenHeader, this.authToken);
|
||||
}
|
||||
xhr.onreadystatechange = function (): void {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
that.response.emit(xhr.responseText);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||
that.response.emit(xhr.responseText)
|
||||
}
|
||||
};
|
||||
}
|
||||
if (this.options.formatDataFunctionIsAsync) {
|
||||
sendable.then(
|
||||
(result: any) => xhr.send(JSON.stringify(result))
|
||||
@@ -424,18 +467,12 @@ export class FileUploader {
|
||||
return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
|
||||
}
|
||||
|
||||
protected async _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions, queueIndex: number): Promise<boolean> {
|
||||
protected _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions): boolean {
|
||||
this._failFilterIndex = -1;
|
||||
|
||||
for (const filter of filters) {
|
||||
return !filters.length ? true : filters.every((filter: FilterFunction) => {
|
||||
this._failFilterIndex++;
|
||||
|
||||
if (!(await Promise.resolve(filter.fn.call(this, file, options, queueIndex)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return filter.fn.call(this, file, options);
|
||||
});
|
||||
}
|
||||
|
||||
protected _isSuccessCode(status: number): boolean {
|
||||
@@ -459,7 +496,7 @@ export class FileUploader {
|
||||
key = line.slice(0, i).trim().toLowerCase();
|
||||
val = line.slice(i + 1).trim();
|
||||
if (key) {
|
||||
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
||||
parsed[ key ] = parsed[ key ] ? parsed[ key ] + ', ' + val : val;
|
||||
}
|
||||
});
|
||||
return parsed;
|
||||
|
||||
Reference in New Issue
Block a user