Skip to content

Commit

Permalink
Chore: Convert assets endpoint to Typescript (#25358)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
  • Loading branch information
3 people committed Jun 17, 2022
1 parent 6b6f9dc commit 42ae7aa
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { isAssetsUnsetAssetProps } from '@rocket.chat/rest-typings';

import { RocketChatAssets } from '../../../assets/server';
import { API } from '../api';
Expand All @@ -8,12 +9,10 @@ API.v1.addRoute(
'assets.setAsset',
{ authRequired: true },
{
post() {
const [asset, { refreshAllClients }, assetName] = Promise.await(
getUploadFormData({
request: this.request,
}),
);
async post() {
const [asset, { refreshAllClients }, assetName] = await getUploadFormData({
request: this.request,
});

const assetsKeys = Object.keys(RocketChatAssets.assets);

Expand All @@ -36,20 +35,21 @@ API.v1.addRoute(

API.v1.addRoute(
'assets.unsetAsset',
{ authRequired: true },
{
authRequired: true,
validateParams: isAssetsUnsetAssetProps,
},
{
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');
}
Meteor.runAsUser(this.userId, () => {
Meteor.call('unsetAsset', assetName);
if (refreshAllClients) {
Meteor.call('refreshClients');
}
});
Meteor.call('unsetAsset', assetName);
if (refreshAllClients) {
Meteor.call('refreshClients');
}
return API.v1.success();
},
},
Expand Down
Loading

0 comments on commit 42ae7aa

Please sign in to comment.