import { Injectable } from '@angular/core'; import * as i0 from "@angular/core"; /** * This service contains the filtering logic to be applied to * any dropped or selected file. If a file matches all criteria * like maximum size or accept type, it will be emitted in the * addedFiles array, otherwise in the rejectedFiles array. */ export class NgxDropzoneService { parseFileList(files, accept, maxFileSize, multiple) { const addedFiles = []; const rejectedFiles = []; for (let i = 0; i < files.length; i++) { const file = files.item(i); if (!this.isAccepted(file, accept)) { this.rejectFile(rejectedFiles, file, 'type'); continue; } if (maxFileSize && file.size > maxFileSize) { this.rejectFile(rejectedFiles, file, 'size'); continue; } if (!multiple && addedFiles.length >= 1) { this.rejectFile(rejectedFiles, file, 'no_multiple'); continue; } addedFiles.push(file); } const result = { addedFiles, rejectedFiles }; return result; } isAccepted(file, accept) { if (accept === '*') { return true; } const acceptFiletypes = accept.split(',').map(it => it.toLowerCase().trim()); const filetype = file.type.toLowerCase(); const filename = file.name.toLowerCase(); const matchedFileType = acceptFiletypes.find(acceptFiletype => { // check for wildcard mimetype (e.g. image/*) if (acceptFiletype.endsWith('/*')) { return filetype.split('/')[0] === acceptFiletype.split('/')[0]; } // check for file extension (e.g. .csv) if (acceptFiletype.startsWith(".")) { return filename.endsWith(acceptFiletype); } // check for exact mimetype match (e.g. image/jpeg) return acceptFiletype == filetype; }); return !!matchedFileType; } rejectFile(rejectedFiles, file, reason) { const rejectedFile = file; rejectedFile.reason = reason; rejectedFiles.push(rejectedFile); } } NgxDropzoneService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: NgxDropzoneService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); NgxDropzoneService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: NgxDropzoneService }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: NgxDropzoneService, decorators: [{ type: Injectable }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJ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