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/app/api/server/v1/assets.ts

63 lines
1.6 KiB

import { Meteor } from 'meteor/meteor';
import { isAssetsUnsetAssetProps } from '@rocket.chat/rest-typings';
import { RocketChatAssets } from '../../../assets/server';
import { API } from '../api';
import { getUploadFormData } from '../lib/getUploadFormData';
import { settings } from '../../../settings/server';
API.v1.addRoute(
'assets.setAsset',
{ authRequired: true },
{
async post() {
const asset = await getUploadFormData(
{
request: this.request,
},
{ field: 'asset', sizeLimit: settings.get('FileUpload_MaxFileSize') },
);
const { fileBuffer, fields, filename, mimetype } = asset;
const { refreshAllClients, assetName: customName } = fields;
const assetName = customName || filename;
const assetsKeys = Object.keys(RocketChatAssets.assets);
const isValidAsset = assetsKeys.includes(assetName);
if (!isValidAsset) {
throw new Meteor.Error('error-invalid-asset', 'Invalid asset');
}
await Meteor.callAsync('setAsset', fileBuffer, mimetype, assetName);
if (refreshAllClients) {
await Meteor.callAsync('refreshClients');
}
return API.v1.success();
},
},
);
API.v1.addRoute(
'assets.unsetAsset',
{
authRequired: true,
validateParams: isAssetsUnsetAssetProps,
},
{
async post() {
const { assetName, refreshAllClients } = this.bodyParams;
const isValidAsset = Object.keys(RocketChatAssets.assets).includes(assetName);
if (!isValidAsset) {
throw new Meteor.Error('error-invalid-asset', 'Invalid asset');
}
await Meteor.callAsync('unsetAsset', assetName);
if (refreshAllClients) {
await Meteor.callAsync('refreshClients');
}
return API.v1.success();
},
},
);