cmssmartedit/web/features/cmssmarteditContainer/components/genericEditor/media/services/seFileMimeTypeService.js
cmssmartedit/web/features/cmssmarteditContainer/components/genericEditor/media/services/seFileValidationService.js
angular.module('seFileMimeTypeServiceModule', [])
.constant('seFileMimeTypeServiceConstants', {
VALID_IMAGE_MIME_TYPE_CODES: ['FFD8FFDB', 'FFD8FFE0', 'FFD8FFE1', '474946383761', '424D', '49492A00', '4D4D002A', '89504E470D0A1A0A']
})
.....
Here VALID_IMAGE_MIME_TYPE_CODES variable contains list of supported Magic Numbers which help to validate uploaded media.
angular.module('seFileValidationServiceModule', ['seObjectValidatorFactoryModule', 'seFileMimeTypeServiceModule'])
.constant('seFileValidationServiceConstants', {
ACCEPTED_FILE_TYPES: ['jpeg', 'jpg', 'gif', 'bmp', 'tiff', 'tif', 'png'],
MAX_FILE_SIZE_IN_BYTES: 20 * 1024 * 1024,
I18N_KEYS: {
FILE_TYPE_INVALID: 'se.upload.file.type.invalid',
FILE_SIZE_INVALID: 'se.upload.file.size.invalid'
}
})
......
Here ACCEPTED_FILE_TYPES variable contains valid file type extensions.
media.allowed.extensions.for.ClassLoader=jpeg,jpg,gif,bmp,tiff,vcard,templ,tif,csv,eps,pdf,png
angular.module('seTrainingFileMimeTypeServiceModule', ['seFileMimeTypeServiceModule'])
.constant('seFileMimeTypeServiceConstants', {
VALID_IMAGE_MIME_TYPE_CODES: ['FFD8FFDB', 'FFD8FFE0', 'FFD8FFE1', '474946383761', '424D', '49492A00', '4D4D002A', '89504E470D0A1A0A']
})
.factory('seFileMimeTypeService', function(seFileMimeTypeServiceConstants, seFileReader, $q) {
var _validateMimeTypeFromFile = function(loadedFile) {
var fileAsBytes = (new Uint8Array(loadedFile)).subarray(0, 8);
var header = fileAsBytes.reduce(function(header, byte) {
var byteAsStr = byte.toString(16);
if (byteAsStr.length === 1) {
byteAsStr = '0' + byteAsStr;
}
header += byteAsStr;
return header;
}, '');
return seFileMimeTypeServiceConstants.VALID_IMAGE_MIME_TYPE_CODES.some(function(mimeTypeCode) {
return header.toLowerCase().indexOf(mimeTypeCode.toLowerCase()) === 0;
});
};
var isFileMimeTypeValid = function(file) {
var deferred = $q.defer();
if (file.type === 'image/svg+xml') {
// Special Handling for SVG
seFileReader.read(file, {
onLoadEnd: function(e) {
var u8arr = new Uint8Array(e.target.result);
try {
var fileContentAsString = new TextDecoder('utf-8').decode(u8arr);
var parser = new DOMParser();
parser.parseFromString(fileContentAsString, 'image/svg+xml');
deferred.resolve();
} catch (e) {
deferred.reject();
}
},
onError: function() {
deferred.reject();
}
});
return deferred.promise;
}
seFileReader.read(file, {
onLoadEnd: function(e) {
if (_validateMimeTypeFromFile(e.target.result)) {
deferred.resolve();
} else {
deferred.reject();
}
},
onError: function() {
deferred.reject();
}
});
return deferred.promise;
};
return {
isFileMimeTypeValid: isFileMimeTypeValid
};
});
angular.module('seTrainingFileValidationServiceModule', ['seFileValidationServiceModule', 'seObjectValidatorFactoryModule', 'seTrainingFileMimeTypeServiceModule'])
.constant('seFileValidationServiceConstants', {
ACCEPTED_FILE_TYPES: ['jpeg', 'jpg', 'gif', 'bmp', 'tiff', 'tif', 'png','svg'],
MAX_FILE_SIZE_IN_BYTES: 20 * 1024 * 1024,
I18N_KEYS: {
FILE_TYPE_INVALID: 'se.upload.file.type.invalid',
FILE_SIZE_INVALID: 'se.upload.file.size.invalid'
}
});
........
@SeModule({
imports: [
'smarteditServicesModule',
'abAnalyticsToolbarItemModule',
'seTrainingFileMimeTypeServiceModule',
'seTrainingFileValidationServiceModule'
],
........
media.allowed.extensions.for.ClassLoader=jpeg,jpg,gif,bmp,tiff,vcard,templ,tif,csv,eps,pdf,png,svg
INSERT_UPDATE SmartEditConfiguration;key[unique=true];value
;applications.trainingsmartedit;{"smartEditLocation":"/trainingsmartedit/trainingsmartedit/js/trainingsmartedit.js","extends": "cmssmartedit"}
;applications.trainingsmarteditContainer;{"smartEditContainerLocation":"/trainingsmartedit/trainingsmartedit/js/trainingsmarteditContainer.js","extends": "cmssmarteditContainer"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |