Merge pull request #1768 from dpalou/MOBILE-2869

MOBILE-2869 core: Support '*' as accepted file types
main
Juan Leyva 2019-02-18 15:10:30 +01:00 committed by GitHub
commit a1271ac2c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -77,7 +77,9 @@ export class CoreAttachmentsComponent implements OnInit {
this.maxSubmissionsReadable = String(this.maxSubmissions); this.maxSubmissionsReadable = String(this.maxSubmissions);
} }
if (this.acceptedTypes && this.acceptedTypes.trim()) { this.acceptedTypes = this.acceptedTypes && this.acceptedTypes.trim();
if (this.acceptedTypes && this.acceptedTypes != '*') {
this.fileTypes = this.fileUploaderProvider.prepareFiletypeList(this.acceptedTypes); this.fileTypes = this.fileUploaderProvider.prepareFiletypeList(this.acceptedTypes);
} }
} }

View File

@ -333,9 +333,16 @@ export class CoreFileUploaderProvider {
* Parse filetypeList to get the list of allowed mimetypes and the data to render information. * Parse filetypeList to get the list of allowed mimetypes and the data to render information.
* *
* @param {string} filetypeList Formatted string list where the mimetypes can be checked. * @param {string} filetypeList Formatted string list where the mimetypes can be checked.
* @return {{info: any[], mimetypes: string[]}} Mimetypes and the filetypes informations. * @return {{info: any[], mimetypes: string[]}} Mimetypes and the filetypes informations. Undefined if all types supported.
*/ */
prepareFiletypeList(filetypeList: string): { info: any[], mimetypes: string[] } { prepareFiletypeList(filetypeList: string): { info: any[], mimetypes: string[] } {
filetypeList = filetypeList && filetypeList.trim();
if (!filetypeList || filetypeList == '*') {
// All types supported, return undefined.
return undefined;
}
const filetypes = filetypeList.split(/[;, ]+/g), const filetypes = filetypeList.split(/[;, ]+/g),
mimetypes = {}, // Use an object to prevent duplicates. mimetypes = {}, // Use an object to prevent duplicates.
typesInfo = []; typesInfo = [];