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/app/custom-sounds/server/methods/uploadCustomSound.js

26 lines
953 B

import { Meteor } from 'meteor/meteor';
import { hasPermission } from '../../../authorization';
import { Notifications } from '../../../notifications';
import { RocketChatFile } from '../../../file';
import { RocketChatFileCustomSoundsInstance } from '../startup/custom-sounds';
Meteor.methods({
uploadCustomSound(binaryContent, contentType, soundData) {
if (!hasPermission(this.userId, 'manage-sounds')) {
throw new Meteor.Error('not_authorized');
}
const file = Buffer.from(binaryContent, 'binary');
const rs = RocketChatFile.bufferToStream(file);
RocketChatFileCustomSoundsInstance.deleteFile(`${soundData._id}.${soundData.extension}`);
const ws = RocketChatFileCustomSoundsInstance.createWriteStream(`${soundData._id}.${soundData.extension}`, contentType);
ws.on(
'end',
Meteor.bindEnvironment(() => Meteor.setTimeout(() => Notifications.notifyAll('updateCustomSound', { soundData }), 500)),
);
rs.pipe(ws);
},
});