fix(lint): fixed linting errors
This commit is contained in:
@@ -4,27 +4,27 @@ import { FileUploader, FileUploaderOptions } from './file-uploader.class';
|
||||
|
||||
@Directive({ selector: '[ng2FileDrop]' })
|
||||
export class FileDropDirective {
|
||||
@Input() public uploader?: FileUploader;
|
||||
@Output() public fileOver: EventEmitter<any> = new EventEmitter();
|
||||
@Input() uploader?: FileUploader;
|
||||
@Output() fileOver: EventEmitter<any> = new EventEmitter();
|
||||
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
|
||||
@Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
@Output() onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
|
||||
protected element: ElementRef;
|
||||
|
||||
public constructor(element: ElementRef) {
|
||||
constructor(element: ElementRef) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public getOptions(): FileUploaderOptions | void {
|
||||
getOptions(): FileUploaderOptions | void {
|
||||
return this.uploader?.options;
|
||||
}
|
||||
|
||||
public getFilters(): any {
|
||||
return {};
|
||||
getFilters(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
@HostListener('drop', [ '$event' ])
|
||||
public onDrop(event: any): void {
|
||||
onDrop(event: MouseEvent): void {
|
||||
const transfer = this._getTransfer(event);
|
||||
if (!transfer) {
|
||||
return;
|
||||
@@ -41,7 +41,7 @@ export class FileDropDirective {
|
||||
}
|
||||
|
||||
@HostListener('dragover', [ '$event' ])
|
||||
public onDragOver(event: any): void {
|
||||
onDragOver(event: MouseEvent): void {
|
||||
const transfer = this._getTransfer(event);
|
||||
if (!this._haveFiles(transfer.types)) {
|
||||
return;
|
||||
@@ -53,7 +53,7 @@ export class FileDropDirective {
|
||||
}
|
||||
|
||||
@HostListener('dragleave', [ '$event' ])
|
||||
public onDragLeave(event: any): any {
|
||||
onDragLeave(event: MouseEvent): void {
|
||||
if ((this as any).element) {
|
||||
if (event.currentTarget === (this as any).element[ 0 ]) {
|
||||
return;
|
||||
@@ -68,12 +68,12 @@ export class FileDropDirective {
|
||||
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
|
||||
}
|
||||
|
||||
protected _preventAndStop(event: any): any {
|
||||
protected _preventAndStop(event: MouseEvent): void {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
protected _haveFiles(types: any): any {
|
||||
protected _haveFiles(types: any): boolean {
|
||||
if (!types) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,30 +2,30 @@ import { FileLikeObject } from './file-like-object.class';
|
||||
import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file-uploader.class';
|
||||
|
||||
export class FileItem {
|
||||
public file: FileLikeObject;
|
||||
public _file: File;
|
||||
public alias?: string;
|
||||
public url? = '/';
|
||||
public method?: string;
|
||||
public headers: any = [];
|
||||
public withCredentials = true;
|
||||
public formData: any = [];
|
||||
public isReady = false;
|
||||
public isUploading = false;
|
||||
public isUploaded = false;
|
||||
public isSuccess = false;
|
||||
public isCancel = false;
|
||||
public isError = false;
|
||||
public progress = 0;
|
||||
public index?: number;
|
||||
public _xhr?: XMLHttpRequest;
|
||||
public _form: any;
|
||||
file: FileLikeObject;
|
||||
_file: File;
|
||||
alias?: string;
|
||||
url = '/';
|
||||
method?: string;
|
||||
headers: any = [];
|
||||
withCredentials = true;
|
||||
formData: any = [];
|
||||
isReady = false;
|
||||
isUploading = false;
|
||||
isUploaded = false;
|
||||
isSuccess = false;
|
||||
isCancel = false;
|
||||
isError = false;
|
||||
progress = 0;
|
||||
index?: number;
|
||||
_xhr?: XMLHttpRequest;
|
||||
_form: any;
|
||||
|
||||
protected uploader: FileUploader;
|
||||
protected some: File;
|
||||
protected options: FileUploaderOptions;
|
||||
|
||||
public constructor(uploader: FileUploader, some: File, options: FileUploaderOptions) {
|
||||
constructor(uploader: FileUploader, some: File, options: FileUploaderOptions) {
|
||||
this.uploader = uploader;
|
||||
this.some = some;
|
||||
this.options = options;
|
||||
@@ -38,7 +38,7 @@ export class FileItem {
|
||||
this.url = uploader.options.url;
|
||||
}
|
||||
|
||||
public upload(): void {
|
||||
upload(): void {
|
||||
try {
|
||||
this.uploader.uploadItem(this);
|
||||
} catch (e) {
|
||||
@@ -47,43 +47,43 @@ export class FileItem {
|
||||
}
|
||||
}
|
||||
|
||||
public cancel(): void {
|
||||
cancel(): void {
|
||||
this.uploader.cancelItem(this);
|
||||
}
|
||||
|
||||
public remove(): void {
|
||||
remove(): void {
|
||||
this.uploader.removeFromQueue(this);
|
||||
}
|
||||
|
||||
public onBeforeUpload(): void {
|
||||
onBeforeUpload(): void {
|
||||
return void 0;
|
||||
}
|
||||
|
||||
public onBuildForm(form: any): any {
|
||||
onBuildForm(form: any): any {
|
||||
return { form };
|
||||
}
|
||||
|
||||
public onProgress(progress: number): any {
|
||||
onProgress(progress: number): any {
|
||||
return { progress };
|
||||
}
|
||||
|
||||
public onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { response, status, headers };
|
||||
}
|
||||
|
||||
public onError(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onError(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { response, status, headers };
|
||||
}
|
||||
|
||||
public onCancel(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onCancel(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { response, status, headers };
|
||||
}
|
||||
|
||||
public onComplete(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onComplete(response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { response, status, headers };
|
||||
}
|
||||
|
||||
public _onBeforeUpload(): void {
|
||||
_onBeforeUpload(): void {
|
||||
this.isReady = true;
|
||||
this.isUploading = true;
|
||||
this.isUploaded = false;
|
||||
@@ -94,16 +94,16 @@ export class FileItem {
|
||||
this.onBeforeUpload();
|
||||
}
|
||||
|
||||
public _onBuildForm(form: any): void {
|
||||
_onBuildForm(form: any): void {
|
||||
this.onBuildForm(form);
|
||||
}
|
||||
|
||||
public _onProgress(progress: number): void {
|
||||
_onProgress(progress: number): void {
|
||||
this.progress = progress;
|
||||
this.onProgress(progress);
|
||||
}
|
||||
|
||||
public _onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
_onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
this.isReady = false;
|
||||
this.isUploading = false;
|
||||
this.isUploaded = true;
|
||||
@@ -115,7 +115,7 @@ export class FileItem {
|
||||
this.onSuccess(response, status, headers);
|
||||
}
|
||||
|
||||
public _onError(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
_onError(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
this.isReady = false;
|
||||
this.isUploading = false;
|
||||
this.isUploaded = true;
|
||||
@@ -127,7 +127,7 @@ export class FileItem {
|
||||
this.onError(response, status, headers);
|
||||
}
|
||||
|
||||
public _onCancel(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
_onCancel(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
this.isReady = false;
|
||||
this.isUploading = false;
|
||||
this.isUploaded = false;
|
||||
@@ -139,7 +139,7 @@ export class FileItem {
|
||||
this.onCancel(response, status, headers);
|
||||
}
|
||||
|
||||
public _onComplete(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
_onComplete(response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
this.onComplete(response, status, headers);
|
||||
|
||||
if (this.uploader.options.removeAfterUpload) {
|
||||
@@ -147,7 +147,7 @@ export class FileItem {
|
||||
}
|
||||
}
|
||||
|
||||
public _prepareToUploading(): void {
|
||||
_prepareToUploading(): void {
|
||||
this.index = this.index || ++this.uploader._nextIndex;
|
||||
this.isReady = true;
|
||||
}
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
function isElement(node: any): boolean {
|
||||
return !!(node && (node.nodeName || node.prop && node.attr && node.find));
|
||||
}
|
||||
|
||||
export class FileLikeObject {
|
||||
public lastModifiedDate: any;
|
||||
public size: any;
|
||||
public type?: string;
|
||||
public name?: string;
|
||||
public rawFile: string;
|
||||
lastModifiedDate: any;
|
||||
size: any;
|
||||
type?: string;
|
||||
name?: string;
|
||||
rawFile: HTMLInputElement | File;
|
||||
|
||||
public constructor(fileOrInput: any) {
|
||||
constructor(fileOrInput: HTMLInputElement | File) {
|
||||
this.rawFile = fileOrInput;
|
||||
const isInput = isElement(fileOrInput);
|
||||
const fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
|
||||
const fakePathOrObject = fileOrInput instanceof HTMLInputElement ? fileOrInput.value : fileOrInput;
|
||||
const postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
|
||||
const method = '_createFrom' + postfix;
|
||||
const method = `_createFrom${postfix}`;
|
||||
(this as any)[ method ](fakePathOrObject);
|
||||
}
|
||||
|
||||
public _createFromFakePath(path: string): void {
|
||||
_createFromFakePath(path: string): void {
|
||||
this.lastModifiedDate = void 0;
|
||||
this.size = void 0;
|
||||
this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
|
||||
this.type = `like/${path.slice(path.lastIndexOf('.') + 1).toLowerCase()}`;
|
||||
this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
|
||||
}
|
||||
|
||||
public _createFromObject(object: { size: number, type: string, name: string }): void {
|
||||
_createFromObject(object: { size: number, type: string, name: string }): void {
|
||||
this.size = object.size;
|
||||
this.type = object.type;
|
||||
this.name = object.name;
|
||||
|
||||
@@ -1,39 +1,37 @@
|
||||
import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core';
|
||||
|
||||
import {FileUploader, FileUploaderOptions} from './file-uploader.class';
|
||||
import { FileUploader, FileUploaderOptions } from './file-uploader.class';
|
||||
|
||||
@Directive({ selector: '[ng2FileSelect]' })
|
||||
export class FileSelectDirective {
|
||||
@Input() public uploader?: FileUploader;
|
||||
@Input() uploader?: FileUploader;
|
||||
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
|
||||
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
@Output() onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
|
||||
protected element: ElementRef;
|
||||
|
||||
public constructor(element: ElementRef) {
|
||||
constructor(element: ElementRef) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public getOptions(): FileUploaderOptions | void {
|
||||
getOptions(): FileUploaderOptions | undefined {
|
||||
return this.uploader?.options;
|
||||
}
|
||||
|
||||
public getFilters(): any {
|
||||
return {};
|
||||
getFilters(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
public isEmptyAfterSelection(): boolean {
|
||||
isEmptyAfterSelection(): boolean {
|
||||
return !!this.element.nativeElement.attributes.multiple;
|
||||
}
|
||||
|
||||
@HostListener('change')
|
||||
public onChange(): any {
|
||||
onChange(): void {
|
||||
const files = this.element.nativeElement.files;
|
||||
const options = this.getOptions();
|
||||
const filters = this.getFilters();
|
||||
if (options) {
|
||||
this.uploader?.addToQueue(files, options, filters);
|
||||
}
|
||||
this.uploader?.addToQueue(files, options, filters);
|
||||
|
||||
this.onFileSelected.emit(files);
|
||||
if (this.isEmptyAfterSelection()) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { FileLikeObject } from "../index";
|
||||
import { FileLikeObject } from '../index';
|
||||
|
||||
export class FileType {
|
||||
/* MS office */
|
||||
public static mime_doc: string[] = [
|
||||
// tslint:disable-next-line:variable-name
|
||||
static mime_doc: string[] = [
|
||||
'application/msword',
|
||||
'application/msword',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
@@ -10,7 +11,8 @@ export class FileType {
|
||||
'application/vnd.ms-word.document.macroEnabled.12',
|
||||
'application/vnd.ms-word.template.macroEnabled.12'
|
||||
];
|
||||
public static mime_xsl: string[] = [
|
||||
// tslint:disable-next-line:variable-name
|
||||
static mime_xsl: string[] = [
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.ms-excel',
|
||||
@@ -21,7 +23,8 @@ export class FileType {
|
||||
'application/vnd.ms-excel.addin.macroEnabled.12',
|
||||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
|
||||
];
|
||||
public static mime_ppt: string[] = [
|
||||
// tslint:disable-next-line:variable-name
|
||||
static mime_ppt: string[] = [
|
||||
'application/vnd.ms-powerpoint',
|
||||
'application/vnd.ms-powerpoint',
|
||||
'application/vnd.ms-powerpoint',
|
||||
@@ -36,7 +39,8 @@ export class FileType {
|
||||
];
|
||||
|
||||
/* PSD */
|
||||
public static mime_psd: string[] = [
|
||||
// tslint:disable-next-line:variable-name
|
||||
static mime_psd: string[] = [
|
||||
'image/photoshop',
|
||||
'image/x-photoshop',
|
||||
'image/psd',
|
||||
@@ -46,7 +50,8 @@ export class FileType {
|
||||
];
|
||||
|
||||
/* Compressed files */
|
||||
public static mime_compress: string[] = [
|
||||
// tslint:disable-next-line:variable-name
|
||||
static mime_compress: string[] = [
|
||||
'application/x-gtar',
|
||||
'application/x-gcompress',
|
||||
'application/compress',
|
||||
@@ -60,7 +65,7 @@ export class FileType {
|
||||
'application/x-bzip2'
|
||||
];
|
||||
|
||||
public static getMimeClass(file: FileLikeObject): string {
|
||||
static getMimeClass(file: FileLikeObject): string {
|
||||
let mimeClass = 'application';
|
||||
if (file?.type && this.mime_psd.indexOf(file.type) !== -1) {
|
||||
mimeClass = 'image';
|
||||
@@ -88,66 +93,66 @@ export class FileType {
|
||||
return mimeClass;
|
||||
}
|
||||
|
||||
public static fileTypeDetection(inputFilename: string): string {
|
||||
static fileTypeDetection(inputFilename: string): string {
|
||||
const types: { [ key: string ]: string } = {
|
||||
'jpg': 'image',
|
||||
'jpeg': 'image',
|
||||
'tif': 'image',
|
||||
'psd': 'image',
|
||||
'bmp': 'image',
|
||||
'png': 'image',
|
||||
'nef': 'image',
|
||||
'tiff': 'image',
|
||||
'cr2': 'image',
|
||||
'dwg': 'image',
|
||||
'cdr': 'image',
|
||||
'ai': 'image',
|
||||
'indd': 'image',
|
||||
'pin': 'image',
|
||||
'cdp': 'image',
|
||||
'skp': 'image',
|
||||
'stp': 'image',
|
||||
jpg: 'image',
|
||||
jpeg: 'image',
|
||||
tif: 'image',
|
||||
psd: 'image',
|
||||
bmp: 'image',
|
||||
png: 'image',
|
||||
nef: 'image',
|
||||
tiff: 'image',
|
||||
cr2: 'image',
|
||||
dwg: 'image',
|
||||
cdr: 'image',
|
||||
ai: 'image',
|
||||
indd: 'image',
|
||||
pin: 'image',
|
||||
cdp: 'image',
|
||||
skp: 'image',
|
||||
stp: 'image',
|
||||
'3dm': 'image',
|
||||
'mp3': 'audio',
|
||||
'wav': 'audio',
|
||||
'wma': 'audio',
|
||||
'mod': 'audio',
|
||||
'm4a': 'audio',
|
||||
'compress': 'compress',
|
||||
'zip': 'compress',
|
||||
'rar': 'compress',
|
||||
mp3: 'audio',
|
||||
wav: 'audio',
|
||||
wma: 'audio',
|
||||
mod: 'audio',
|
||||
m4a: 'audio',
|
||||
compress: 'compress',
|
||||
zip: 'compress',
|
||||
rar: 'compress',
|
||||
'7z': 'compress',
|
||||
'lz': 'compress',
|
||||
'z01': 'compress',
|
||||
'bz2': 'compress',
|
||||
'gz': 'compress',
|
||||
'pdf': 'pdf',
|
||||
'xls': 'xls',
|
||||
'xlsx': 'xls',
|
||||
'ods': 'xls',
|
||||
'mp4': 'video',
|
||||
'avi': 'video',
|
||||
'wmv': 'video',
|
||||
'mpg': 'video',
|
||||
'mts': 'video',
|
||||
'flv': 'video',
|
||||
lz: 'compress',
|
||||
z01: 'compress',
|
||||
bz2: 'compress',
|
||||
gz: 'compress',
|
||||
pdf: 'pdf',
|
||||
xls: 'xls',
|
||||
xlsx: 'xls',
|
||||
ods: 'xls',
|
||||
mp4: 'video',
|
||||
avi: 'video',
|
||||
wmv: 'video',
|
||||
mpg: 'video',
|
||||
mts: 'video',
|
||||
flv: 'video',
|
||||
'3gp': 'video',
|
||||
'vob': 'video',
|
||||
'm4v': 'video',
|
||||
'mpeg': 'video',
|
||||
'm2ts': 'video',
|
||||
'mov': 'video',
|
||||
'doc': 'doc',
|
||||
'docx': 'doc',
|
||||
'eps': 'doc',
|
||||
'txt': 'doc',
|
||||
'odt': 'doc',
|
||||
'rtf': 'doc',
|
||||
'ppt': 'ppt',
|
||||
'pptx': 'ppt',
|
||||
'pps': 'ppt',
|
||||
'ppsx': 'ppt',
|
||||
'odp': 'ppt'
|
||||
vob: 'video',
|
||||
m4v: 'video',
|
||||
mpeg: 'video',
|
||||
m2ts: 'video',
|
||||
mov: 'video',
|
||||
doc: 'doc',
|
||||
docx: 'doc',
|
||||
eps: 'doc',
|
||||
txt: 'doc',
|
||||
odt: 'doc',
|
||||
rtf: 'doc',
|
||||
ppt: 'ppt',
|
||||
pptx: 'ppt',
|
||||
pps: 'ppt',
|
||||
ppsx: 'ppt',
|
||||
odp: 'ppt'
|
||||
};
|
||||
|
||||
const chunks = inputFilename.split('.');
|
||||
|
||||
@@ -12,12 +12,12 @@ export interface Headers {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export type ParsedResponseHeaders = { [ headerFieldName: string ]: string };
|
||||
export interface ParsedResponseHeaders { [ headerFieldName: string ]: string }
|
||||
|
||||
export type FilterFunction = {
|
||||
name: string,
|
||||
fn: (item: FileLikeObject, options?: FileUploaderOptions) => boolean
|
||||
};
|
||||
export interface FilterFunction {
|
||||
name: string;
|
||||
fn(item: FileLikeObject, options?: FileUploaderOptions): boolean;
|
||||
}
|
||||
|
||||
export interface FileUploaderOptions {
|
||||
allowedMimeType?: string[];
|
||||
@@ -31,7 +31,7 @@ export interface FileUploaderOptions {
|
||||
maxFileSize?: number;
|
||||
queueLimit?: number;
|
||||
removeAfterUpload?: boolean;
|
||||
url?: string;
|
||||
url: string;
|
||||
disableMultipart?: boolean;
|
||||
itemAlias?: string;
|
||||
authTokenHeader?: string;
|
||||
@@ -44,33 +44,34 @@ export interface FileUploaderOptions {
|
||||
|
||||
export class FileUploader {
|
||||
|
||||
public authToken?: string;
|
||||
public isUploading = false;
|
||||
public queue: FileItem[] = [];
|
||||
public progress = 0;
|
||||
public _nextIndex = 0;
|
||||
public autoUpload: any;
|
||||
public authTokenHeader?: string;
|
||||
public response: EventEmitter<any>;
|
||||
authToken?: string;
|
||||
isUploading = false;
|
||||
queue: FileItem[] = [];
|
||||
progress = 0;
|
||||
_nextIndex = 0;
|
||||
autoUpload: any;
|
||||
authTokenHeader?: string;
|
||||
response: EventEmitter<any>;
|
||||
|
||||
public options: FileUploaderOptions = {
|
||||
options: FileUploaderOptions = {
|
||||
autoUpload: false,
|
||||
isHTML5: true,
|
||||
filters: [],
|
||||
removeAfterUpload: false,
|
||||
disableMultipart: false,
|
||||
formatDataFunction: (item: FileItem) => item._file,
|
||||
formatDataFunctionIsAsync: false
|
||||
formatDataFunctionIsAsync: false,
|
||||
url: ''
|
||||
};
|
||||
|
||||
protected _failFilterIndex?: number;
|
||||
|
||||
public constructor(options: FileUploaderOptions) {
|
||||
constructor(options: FileUploaderOptions) {
|
||||
this.setOptions(options);
|
||||
this.response = new EventEmitter<any>();
|
||||
this.response = new EventEmitter<string>();
|
||||
}
|
||||
|
||||
public setOptions(options: FileUploaderOptions): void {
|
||||
setOptions(options: FileUploaderOptions): void {
|
||||
this.options = Object.assign(this.options, options);
|
||||
|
||||
this.authToken = this.options.authToken;
|
||||
@@ -78,8 +79,8 @@ export class FileUploader {
|
||||
this.autoUpload = this.options.autoUpload;
|
||||
this.options.filters?.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
|
||||
|
||||
if (this.options.maxFileSize && this.options.filters) {
|
||||
this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
|
||||
if (this.options.maxFileSize) {
|
||||
this.options.filters?.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
|
||||
}
|
||||
|
||||
if (this.options.allowedFileType) {
|
||||
@@ -95,7 +96,8 @@ export class FileUploader {
|
||||
}
|
||||
}
|
||||
|
||||
public addToQueue(files: File[], options?: FileUploaderOptions, filters?: FilterFunction[] | string): void {
|
||||
addToQueue(files: File[], _options?: FileUploaderOptions, filters?: [] | string): void {
|
||||
let options = _options;
|
||||
const list: File[] = [];
|
||||
for (const file of files) {
|
||||
list.push(file);
|
||||
@@ -131,7 +133,7 @@ export class FileUploader {
|
||||
}
|
||||
}
|
||||
|
||||
public removeFromQueue(value: FileItem): void {
|
||||
removeFromQueue(value: FileItem): void {
|
||||
const index = this.getIndexOfItem(value);
|
||||
const item = this.queue[ index ];
|
||||
if (item.isUploading) {
|
||||
@@ -141,14 +143,14 @@ export class FileUploader {
|
||||
this.progress = this._getTotalProgress();
|
||||
}
|
||||
|
||||
public clearQueue(): void {
|
||||
clearQueue(): void {
|
||||
while (this.queue.length) {
|
||||
this.queue[ 0 ].remove();
|
||||
}
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
public uploadItem(value: FileItem): void {
|
||||
uploadItem(value: FileItem): void {
|
||||
const index = this.getIndexOfItem(value);
|
||||
const item = this.queue[ index ];
|
||||
const transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
|
||||
@@ -160,7 +162,7 @@ export class FileUploader {
|
||||
(this as any)[ transport ](item);
|
||||
}
|
||||
|
||||
public cancelItem(value: FileItem): void {
|
||||
cancelItem(value: FileItem): void {
|
||||
const index = this.getIndexOfItem(value);
|
||||
const item = this.queue[ index ];
|
||||
const prop = this.options.isHTML5 ? item._xhr : item._form;
|
||||
@@ -169,7 +171,7 @@ export class FileUploader {
|
||||
}
|
||||
}
|
||||
|
||||
public uploadAll(): void {
|
||||
uploadAll(): void {
|
||||
const items = this.getNotUploadedItems().filter((item: FileItem) => !item.isUploading);
|
||||
if (!items.length) {
|
||||
return;
|
||||
@@ -178,110 +180,111 @@ export class FileUploader {
|
||||
items[ 0 ].upload();
|
||||
}
|
||||
|
||||
public cancelAll(): void {
|
||||
cancelAll(): void {
|
||||
const items = this.getNotUploadedItems();
|
||||
items.map((item: FileItem) => item.cancel());
|
||||
}
|
||||
|
||||
public isFile(value: any): boolean {
|
||||
isFile(value: any): boolean {
|
||||
return isFile(value);
|
||||
}
|
||||
|
||||
public isFileLikeObject(value: any): boolean {
|
||||
isFileLikeObject(value: any): boolean {
|
||||
return value instanceof FileLikeObject;
|
||||
}
|
||||
|
||||
public getIndexOfItem(value: any): number {
|
||||
getIndexOfItem(value: any): number {
|
||||
return typeof value === 'number' ? value : this.queue.indexOf(value);
|
||||
}
|
||||
|
||||
public getNotUploadedItems(): any[] {
|
||||
getNotUploadedItems(): any[] {
|
||||
return this.queue.filter((item: FileItem) => !item.isUploaded);
|
||||
}
|
||||
|
||||
public getReadyItems(): any[] {
|
||||
getReadyItems(): any[] {
|
||||
return this.queue
|
||||
.filter((item: FileItem) => (item.isReady && !item.isUploading))
|
||||
.sort((item1: any, item2: any) => item1.index - item2.index);
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
return void 0;
|
||||
destroy(): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public onAfterAddingAll(fileItems: any): any {
|
||||
onAfterAddingAll(fileItems: any): any {
|
||||
return { fileItems };
|
||||
}
|
||||
|
||||
public onBuildItemForm(fileItem: FileItem, form: any): any {
|
||||
onBuildItemForm(fileItem: FileItem, form: any): any {
|
||||
return { fileItem, form };
|
||||
}
|
||||
|
||||
public onAfterAddingFile(fileItem: FileItem): any {
|
||||
onAfterAddingFile(fileItem: FileItem): any {
|
||||
return { fileItem };
|
||||
}
|
||||
|
||||
public onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): any {
|
||||
onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): any {
|
||||
return { item, filter, options };
|
||||
}
|
||||
|
||||
public onBeforeUploadItem(fileItem: FileItem): any {
|
||||
onBeforeUploadItem(fileItem: FileItem): any {
|
||||
return { fileItem };
|
||||
}
|
||||
|
||||
public onProgressItem(fileItem: FileItem, progress: any): any {
|
||||
onProgressItem(fileItem: FileItem, progress: any): any {
|
||||
return { fileItem, progress };
|
||||
}
|
||||
|
||||
public onProgressAll(progress: any): any {
|
||||
onProgressAll(progress: any): any {
|
||||
return { progress };
|
||||
}
|
||||
|
||||
public onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { item, response, status, headers };
|
||||
}
|
||||
|
||||
public onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { item, response, status, headers };
|
||||
}
|
||||
|
||||
public onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { item, response, status, headers };
|
||||
}
|
||||
|
||||
public onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
|
||||
return { item, response, status, headers };
|
||||
}
|
||||
|
||||
public onCompleteAll(): any {
|
||||
onCompleteAll(): any {
|
||||
return void 0;
|
||||
}
|
||||
|
||||
public _mimeTypeFilter(item: FileLikeObject): boolean {
|
||||
_mimeTypeFilter(item: FileLikeObject): boolean {
|
||||
return !(item?.type && this.options.allowedMimeType && this.options.allowedMimeType?.indexOf(item.type) === -1);
|
||||
}
|
||||
|
||||
public _fileSizeFilter(item: FileLikeObject): boolean {
|
||||
_fileSizeFilter(item: FileLikeObject): boolean {
|
||||
return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
|
||||
}
|
||||
|
||||
public _fileTypeFilter(item: FileLikeObject): boolean {
|
||||
_fileTypeFilter(item: FileLikeObject): boolean {
|
||||
return !(this.options.allowedFileType &&
|
||||
this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
|
||||
}
|
||||
|
||||
public _onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
_onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
item._onError(response, status, headers);
|
||||
this.onErrorItem(item, response, status, headers);
|
||||
}
|
||||
|
||||
public _onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
_onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
item._onComplete(response, status, headers);
|
||||
this.onCompleteItem(item, response, status, headers);
|
||||
const nextItem = this.getReadyItems()[ 0 ];
|
||||
this.isUploading = false;
|
||||
if (nextItem) {
|
||||
nextItem.upload();
|
||||
|
||||
return;
|
||||
}
|
||||
this.onCompleteAll();
|
||||
@@ -294,12 +297,14 @@ export class FileUploader {
|
||||
if (name) {
|
||||
return parsedHeaders[ name.toLowerCase() ] || void 0;
|
||||
}
|
||||
|
||||
return parsedHeaders;
|
||||
};
|
||||
}
|
||||
|
||||
protected _xhrTransport(item: FileItem): any {
|
||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||
// tslint:disable-next-line:no-this-assignment
|
||||
const that = this;
|
||||
const xhr = item._xhr = new XMLHttpRequest();
|
||||
let sendable: any;
|
||||
@@ -312,11 +317,9 @@ export class FileUploader {
|
||||
sendable = new FormData();
|
||||
this._onBuildItemForm(item, sendable);
|
||||
let appendFile;
|
||||
if (item.alias && item._file && item.file.name) {
|
||||
appendFile = () => sendable.append(item.alias, item._file, item.file.name);
|
||||
if (!this.options.parametersBeforeFiles) {
|
||||
appendFile();
|
||||
}
|
||||
appendFile = () => sendable.append(item.alias, item._file, item.file.name);
|
||||
if (!this.options.parametersBeforeFiles) {
|
||||
appendFile();
|
||||
}
|
||||
|
||||
// For AWS, Additional Parameters must come BEFORE Files
|
||||
@@ -348,7 +351,7 @@ export class FileUploader {
|
||||
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
||||
const response = this._transformResponse(xhr.response, headers);
|
||||
const gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
|
||||
const method = '_on' + gist + 'Item';
|
||||
const method = `_on${gist}Item`;
|
||||
(this as any)[ method ](item, response, xhr.status, headers);
|
||||
this._onCompleteItem(item, response, xhr.status, headers);
|
||||
};
|
||||
@@ -416,9 +419,11 @@ export class FileUploader {
|
||||
}
|
||||
if (typeof filters === 'string') {
|
||||
const names = filters.match(/[^\s,]+/g);
|
||||
|
||||
return this.options?.filters || []
|
||||
.filter((filter: any) => names?.indexOf(filter.name) !== -1);
|
||||
}
|
||||
|
||||
return this.options?.filters || [];
|
||||
}
|
||||
|
||||
@@ -432,10 +437,12 @@ export class FileUploader {
|
||||
|
||||
protected _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions): boolean {
|
||||
this._failFilterIndex = -1;
|
||||
|
||||
return !filters.length ? true : filters.every((filter: FilterFunction) => {
|
||||
if (typeof this._failFilterIndex === 'number') {
|
||||
if (this._failFilterIndex) {
|
||||
this._failFilterIndex++;
|
||||
}
|
||||
|
||||
return filter.fn.call(this, file, options);
|
||||
});
|
||||
}
|
||||
@@ -464,6 +471,7 @@ export class FileUploader {
|
||||
parsed[ key ] = parsed[ key ] ? parsed[ key ] + ', ' + val : val;
|
||||
}
|
||||
});
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"name": "ng2-file-upload",
|
||||
"version": "1.3.0"
|
||||
"version": "1.3.0",
|
||||
"peerDependencies": {
|
||||
"@angular/common": "*",
|
||||
"@angular/core": "*"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user