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/apps/meteor/server/methods/setAvatarFromService.ts

44 lines
1.2 KiB

import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { setAvatarFromServiceWithValidation } from '../../app/lib/server/functions/setUserAvatar';
declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
setAvatarFromService(dataURI: Buffer | Blob, contentType?: string, service?: string, targetUserId?: string): void;
}
}
Meteor.methods<ServerMethods>({
async setAvatarFromService(dataURI, contentType, service, targetUserId) {
check(dataURI, String);
check(contentType, Match.Optional(String));
check(service, Match.Optional(String));
check(targetUserId, Match.Optional(String));
const uid = Meteor.userId();
if (!uid) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'setAvatarFromService',
});
}
return setAvatarFromServiceWithValidation(uid, dataURI, contentType, service, targetUserId);
},
});
DDPRateLimiter.addRule(
{
type: 'method',
name: 'setAvatarFromService',
userId() {
return true;
},
},
1,
5000,
);