The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/views/admin/customSounds/lib.js

46 lines
1.1 KiB

// Here previousData will define if it is an update or a new entry
export function validate(soundData, soundFile) {
const errors = [];
if (!soundData.name) {
errors.push('Name');
}
if (!soundData._id && !soundFile) {
errors.push('Sound File');
}
if (soundFile) {
if (!soundData.previousSound || soundData.previousSound !== soundFile) {
if (
!/audio\/mp3/.test(soundFile.type) &&
!/audio\/mpeg/.test(soundFile.type) &&
!/audio\/x-mpeg/.test(soundFile.type)
) {
errors.push('FileType');
}
}
}
return errors;
}
export function createSoundData(soundFile, name = '', previousData) {
const soundData = {
extension: soundFile.name.split('.').pop(),
};
if (previousData) {
soundData._id = previousData._id;
soundData.previousName = previousData.previousName;
soundData.previousSound = previousData.previousSound;
soundData.previousExtension = previousData.previousSound.extension;
soundData.name = name;
soundData.newFile = false;
} else {
soundData.name = name.trim();
soundData.newFile = true;
}
return soundData;
}