diff --git a/packages/rocketchat-api/server/v1/misc.js b/packages/rocketchat-api/server/v1/misc.js index 38176417f88..f279e1bb1fb 100644 --- a/packages/rocketchat-api/server/v1/misc.js +++ b/packages/rocketchat-api/server/v1/misc.js @@ -31,3 +31,54 @@ RocketChat.API.v1.addRoute('me', { authRequired: true }, { ])); } }); + +RocketChat.API.v1.addRoute('shield.svg', { authRequired: false }, { + get() { + const { type, channel, name } = this.queryParams; + let text; + switch (type) { + case 'online': + const count = RocketChat.models.Users.findUsersNotOffline().count(); + text = `${ count } Online`; + break; + case 'channel': + if (!channel) { + return RocketChat.API.v1.failure('Shield channel is required for type "channel"'); + } + text = `#${ channel }`; + break; + default: + text = 'JOIN CHAT'; + } + const leftSize = name ? name.length * 6 + 32 : 24; + const rightSize = text.length * 6 + 20; + const width = leftSize + rightSize; + const height = 20; + return { + headers: { 'Content-Type': 'image/svg+xml;charset=utf-8' }, + body: ` + + + + + + + + + + + + + + + + ${ name ? `${ name } + ${ name }` : '' } + ${ text } + ${ text } + + + `.trim().replace(/\>[\s]+\<') + }; + } +});