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/OEmbedCacheCleanup.ts

36 lines
1.1 KiB

import type { ServerMethods } from '@rocket.chat/ddp-client';
import { OEmbedCache } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
import { hasPermissionAsync } from '../../app/authorization/server/functions/hasPermission';
import { settings } from '../../app/settings/server';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
OEmbedCacheCleanup(): { message: string };
}
}
export const executeClearOEmbedCache = async () => {
const date = new Date();
const expirationDays = settings.get<number>('API_EmbedCacheExpirationDays');
date.setDate(date.getDate() - expirationDays);
return OEmbedCache.removeBeforeDate(date);
};
Meteor.methods<ServerMethods>({
async OEmbedCacheCleanup() {
const uid = Meteor.userId();
if (!uid || !(await hasPermissionAsync(uid, 'clear-oembed-cache'))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'OEmbedCacheCleanup',
});
}
await executeClearOEmbedCache();
return {
message: 'cache_cleared',
};
},
});