Skip to content

Commit

Permalink
Remove dependency of RC namespace on half of api files (#13275)
Browse files Browse the repository at this point in the history
* Move RestAPI client to rc-api package

* Remove dependency of RC namespace in rc-api/helpers and api.js

* Remove dependency of RC namespace on half of api files
  • Loading branch information
MarcosSpessatto authored and rodrigok committed Feb 6, 2019
1 parent 767f35d commit 5228d2f
Show file tree
Hide file tree
Showing 11 changed files with 511 additions and 490 deletions.
1 change: 1 addition & 0 deletions packages/rocketchat-api/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Package.onUse(function(api) {
'rocketchat:lib',
'rocketchat:models',
'rocketchat:settings',
'rocketchat:assets',
'rocketchat:utils',
'rocketchat:metrics',
'rocketchat:authorization',
Expand Down
15 changes: 8 additions & 7 deletions packages/rocketchat-api/server/v1/assets.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Meteor } from 'meteor/meteor';
import { RocketChatAssets } from 'meteor/rocketchat:assets';
import Busboy from 'busboy';
import { RocketChat } from 'meteor/rocketchat:lib';
import { API } from '../api';

RocketChat.API.v1.addRoute('assets.setAsset', { authRequired: true }, {
API.v1.addRoute('assets.setAsset', { authRequired: true }, {
post() {
const busboy = new Busboy({ headers: this.request.headers });
const fields = {};
Expand All @@ -11,7 +12,7 @@ RocketChat.API.v1.addRoute('assets.setAsset', { authRequired: true }, {
Meteor.wrapAsync((callback) => {
busboy.on('field', (fieldname, value) => fields[fieldname] = value);
busboy.on('file', Meteor.bindEnvironment((fieldname, file, filename, encoding, mimetype) => {
const isValidAsset = Object.keys(RocketChat.Assets.assets).includes(fieldname);
const isValidAsset = Object.keys(RocketChatAssets.assets).includes(fieldname);
if (!isValidAsset) {
callback(new Meteor.Error('error-invalid-asset', 'Invalid asset'));
}
Expand All @@ -35,21 +36,21 @@ RocketChat.API.v1.addRoute('assets.setAsset', { authRequired: true }, {
if (fields.refreshAllClients) {
Meteor.runAsUser(this.userId, () => Meteor.call('refreshClients'));
}
return RocketChat.API.v1.success();
return API.v1.success();
},
});

RocketChat.API.v1.addRoute('assets.unsetAsset', { authRequired: true }, {
API.v1.addRoute('assets.unsetAsset', { authRequired: true }, {
post() {
const { assetName, refreshAllClients } = this.bodyParams;
const isValidAsset = Object.keys(RocketChat.Assets.assets).includes(assetName);
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.runAsUser(this.userId, () => Meteor.call('refreshClients'));
}
return RocketChat.API.v1.success();
return API.v1.success();
},
});
Loading

0 comments on commit 5228d2f

Please sign in to comment.