[ADF-3283] added minimatch options into the configuration to allow cu… (#3542)

* [ADF-3283] added minimatch options into the configuration to allow customisation

* [ADF-3283] added documentation
This commit is contained in:
Vito
2018-07-02 19:21:35 +01:00
committed by Eugenio Romano
parent de126670ee
commit cd4431e547
5 changed files with 76 additions and 4 deletions

View File

@@ -198,7 +198,10 @@
"supportedPageSizes": [ 5, 10, 15, 20 ] "supportedPageSizes": [ 5, 10, 15, 20 ]
}, },
"files": { "files": {
"excluded": [".DS_Store", "desktop.ini", ".git"] "excluded": [".DS_Store", "desktop.ini", ".git"],
"match-options": {
"nocase": true
}
}, },
"logLevel": "trace", "logLevel": "trace",
"activiti": { "activiti": {

View File

@@ -61,6 +61,9 @@ The configuration of this service is saved in the `app.config.json` file
The example below shows how to filter out the : '.git', '.DS_Store' and 'desktop.ini' files. The example below shows how to filter out the : '.git', '.DS_Store' and 'desktop.ini' files.
Each element of the ignore list is a glob pattern string, so you could exclude all the `.txt` Each element of the ignore list is a glob pattern string, so you could exclude all the `.txt`
files, for example, by adding a `*.txt` pattern to the list. files, for example, by adding a `*.txt` pattern to the list.
There is also the possibility to add some more option to how perform the check via the `match-options` parameter.
For example in this case we have added the ignore case so `*.TXT` will match all the txt files ignoring the case for the extension.
For more information about the options available please check [minimatch](https://www.npmjs.com/package/minimatch#options) documentation.
**app.config.json** **app.config.json**
@@ -72,7 +75,10 @@ files, for example, by adding a `*.txt` pattern to the list.
"name": "Alfresco" "name": "Alfresco"
}, },
"files": { "files": {
"excluded": [".DS_Store", "desktop.ini", ".git", "*.txt"] "excluded": [".DS_Store", "desktop.ini", ".git", "*.txt"],
"match-options": {
"nocase": true
}
} }
} }
``` ```

View File

@@ -318,6 +318,56 @@
"description": "File exclusions", "description": "File exclusions",
"type": "array", "type": "array",
"items": { "type": "string" } "items": { "type": "string" }
},
"match-options": {
"description": "Minimatch plugin option that will be applied for the check. By default all the options are false",
"type": "object",
"properties": {
"debug": {
"description": "Dump a ton of stuff to stderr",
"type": ["boolean", "null"]
},
"nobrace": {
"description": "Do not expand {a,b} and {1..3} brace sets.",
"type": ["boolean", "null"]
},
"noglobstar": {
"description": "Disable ** matching against multiple folder names.",
"type": ["boolean", "null"]
},
"dot": {
"description": "Allow patterns to match filenames starting with a period, even if the pattern does not explicitly have a period in that spot.",
"type": ["boolean", "null"]
},
"noext": {
"description": "Disable 'extglob' style patterns like +(a|b).",
"type": ["boolean", "null"]
},
"nocase": {
"description": "Perform a case-insensitive match.",
"type": ["boolean", "null"]
},
"nonull": {
"description": "When a match is not found by minimatch.match, return a list containing the pattern itself if this option is set. When not set, an empty list is returned if there are no matches.",
"type": ["boolean", "null"]
},
"matchBase": {
"description": "If set, then patterns without slashes will be matched against the basename of the path if it contains slashes.",
"type": ["boolean", "null"]
},
"nocomment": {
"description": "Suppress the behavior of treating # at the start of a pattern as a comment.",
"type": ["boolean", "null"]
},
"nonegate": {
"description": "Suppress the behavior of treating a leading ! character as negation.",
"type": ["boolean", "null"]
},
"flipNegate": {
"description": "Returns from negate expressions the same as if they were not negated.",
"type": ["boolean", "null"]
}
}
} }
} }
}, },

View File

@@ -41,7 +41,10 @@ describe('UploadService', () => {
appConfig.config = { appConfig.config = {
ecmHost: 'http://localhost:9876/ecm', ecmHost: 'http://localhost:9876/ecm',
files: { files: {
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git'] excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git', '*.SWF'],
'match-options': {
nocase: true
}
} }
}; };
@@ -83,6 +86,14 @@ describe('UploadService', () => {
expect(result[0]).toBe(file2); expect(result[0]).toBe(file2);
}); });
it('should match the extension in case insensitive way', () => {
const file1 = new FileModel(new File([''], 'test.swf'));
const file2 = new FileModel(new File([''], 'readme.md'));
const result = service.addToQueue(file1, file2);
expect(result.length).toBe(1);
expect(result[0]).toBe(file2);
});
it('should make XHR done request after the file is added in the queue', (done) => { it('should make XHR done request after the file is added in the queue', (done) => {
let emitter = new EventEmitter(); let emitter = new EventEmitter();

View File

@@ -38,6 +38,7 @@ export class UploadService {
private totalAborted: number = 0; private totalAborted: number = 0;
private totalError: number = 0; private totalError: number = 0;
private excludedFileList: String[] = []; private excludedFileList: String[] = [];
private matchingOptions: any = null;
activeTask: Promise<any> = null; activeTask: Promise<any> = null;
queue: FileModel[] = []; queue: FileModel[] = [];
@@ -56,6 +57,7 @@ export class UploadService {
constructor(protected apiService: AlfrescoApiService, constructor(protected apiService: AlfrescoApiService,
appConfigService: AppConfigService) { appConfigService: AppConfigService) {
this.excludedFileList = <String[]> appConfigService.get('files.excluded'); this.excludedFileList = <String[]> appConfigService.get('files.excluded');
this.matchingOptions = appConfigService.get('files.match-options');
} }
/** /**
@@ -90,7 +92,7 @@ export class UploadService {
let isAllowed = true; let isAllowed = true;
if (this.excludedFileList) { if (this.excludedFileList) {
isAllowed = this.excludedFileList.filter(expr => minimatch(file.name, expr)).length === 0; isAllowed = this.excludedFileList.filter(expr => minimatch(file.name, expr, this.matchingOptions)).length === 0;
} }
return isAllowed; return isAllowed;
} }