[ADF-917] added exlcluded files into app config to prevent special fi… (#2039)

* [ADF 917] added exlcluded files into app config to prevent special files upload
This commit is contained in:
Vito
2017-07-06 05:29:41 -07:00
committed by Eugenio Romano
parent 4bd0f04913
commit d9fca83e04
10 changed files with 86 additions and 27 deletions

View File

@@ -31,7 +31,10 @@ describe('UploadService', () => {
imports: [
CoreModule.forRoot(),
AppConfigModule.forRoot('app.config.json', {
ecmHost: 'http://localhost:9876/ecm'
ecmHost: 'http://localhost:9876/ecm',
files: {
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
}
})
],
providers: [
@@ -82,7 +85,7 @@ describe('UploadService', () => {
});
let fileFake = new FileModel(
<File>{ name: 'fake-name', size: 10 },
<FileUploadOptions> { parentId: '-root-', path: 'fake-dir' }
<FileUploadOptions>{ parentId: '-root-', path: 'fake-dir' }
);
service.addToQueue(fileFake);
service.uploadFilesInTheQueue(emitter);
@@ -107,7 +110,7 @@ describe('UploadService', () => {
});
let fileFake = new FileModel(
<File>{ name: 'fake-name', size: 10 },
<FileUploadOptions> { parentId: '-root-' }
<FileUploadOptions>{ parentId: '-root-' }
);
service.addToQueue(fileFake);
service.uploadFilesInTheQueue(emitter);
@@ -193,4 +196,15 @@ describe('UploadService', () => {
let file = service.getQueue();
service.cancelUpload(...file);
});
it('should remove from the queue all the files in the exluded list', () => {
const file1 = new FileModel(new File([''], '.git'));
const file2 = new FileModel(new File([''], '.DS_Store'));
const file3 = new FileModel(new File([''], 'desktop.ini'));
const file4 = new FileModel(new File([''], 'readme.md'));
const file5 = new FileModel(new File([''], 'test.git'));
const result = service.addToQueue(file1, file2, file3, file4, file5);
expect(result.length).toBe(1);
expect(result[0]).toBe(file4);
});
});

View File

@@ -17,9 +17,10 @@
import { EventEmitter, Injectable } from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { AlfrescoApiService } from 'ng2-alfresco-core';
import { AlfrescoApiService, AppConfigService } from 'ng2-alfresco-core';
import { FileUploadEvent, FileUploadCompleteEvent } from '../events/file.event';
import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file.model';
import * as minimatch from 'minimatch';
@Injectable()
export class UploadService {
@@ -29,6 +30,7 @@ export class UploadService {
private totalComplete: number = 0;
private totalAborted: number = 0;
private activeTask: Promise<any> = null;
private excludedFileList: String[] = [];
queueChanged: Subject<FileModel[]> = new Subject<FileModel[]>();
fileUpload: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
@@ -39,7 +41,8 @@ export class UploadService {
fileUploadError: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
fileUploadComplete: Subject<FileUploadCompleteEvent> = new Subject<FileUploadCompleteEvent>();
constructor(private apiService: AlfrescoApiService) {
constructor(private apiService: AlfrescoApiService, private appConfigService: AppConfigService) {
this.excludedFileList = <String[]>this.appConfigService.get('files.excluded');
}
/**
@@ -71,12 +74,20 @@ export class UploadService {
* addToQueue(...[file1, file2, file3]); // pass an array of files
*/
addToQueue(...files: FileModel[]): FileModel[] {
const allowedFiles = files.filter(f => !f.name.startsWith('.'));
const allowedFiles = files.filter(f => this.filterElement(f));
this.queue = this.queue.concat(allowedFiles);
this.queueChanged.next(this.queue);
return allowedFiles;
}
private filterElement(file: FileModel) {
let isAllowed = true;
if (this.excludedFileList) {
isAllowed = this.excludedFileList.filter(expr => minimatch(file.name, expr)).length === 0;
}
return isAllowed;
}
/**
* Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder.
*
@@ -133,8 +144,8 @@ export class UploadService {
private beginUpload(file: FileModel, /* @deprecated */emitter: EventEmitter<any>): any {
let opts: any = {
renditions: 'doclib'
};
renditions: 'doclib'
};
if (file.options.newVersion === true) {
opts.overwrite = true;
@@ -167,7 +178,6 @@ export class UploadService {
.catch(err => {
this.onUploadError(file, err);
});
return promise;
}