Skip to content

Commit

Permalink
chore: review
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Mar 22, 2024
1 parent 0636587 commit a3a807e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
46 changes: 27 additions & 19 deletions apps/meteor/app/assets/server/assets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from 'crypto';
import type { ServerResponse, IncomingMessage } from 'http';

import type { IRocketChatAssets, IRocketChatAsset } from '@rocket.chat/core-typings';
import type { IRocketChatAssets, IRocketChatAsset, ISetting } from '@rocket.chat/core-typings';
import { Settings } from '@rocket.chat/models';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import type { NextHandleFunction } from 'connect';
Expand All @@ -20,7 +20,10 @@ import { getURL } from '../../utils/server/getURL';
const RocketChatAssetsInstance = new RocketChatFile.GridFS({
name: 'assets',
});
const assets: IRocketChatAssets = {

type IRocketChatAssetsConfig = Record<keyof IRocketChatAssets, IRocketChatAsset & { settingOptions?: Partial<ISetting> }>;

const assets: IRocketChatAssetsConfig = {
logo: {
label: 'logo (svg, png, jpg)',
defaultUrl: 'images/logo/logo.svg',
Expand Down Expand Up @@ -195,12 +198,19 @@ const assets: IRocketChatAssets = {
type: 'image',
extensions: ['svg', 'png', 'jpg', 'jpeg'],
},
settingOptions: {
section: 'Livechat',
group: 'Omnichannel',
invalidValue: null,
enableQuery: { _id: 'Livechat_enabled', value: true },
enterprise: true,
modules: ['livechat-enterprise'],
sorter: 999 + 1,
},
},
};

const ignoredKeys = ['livechat_widget_logo'];

function getAssetByKey(key: string): IRocketChatAsset {
function getAssetByKey(key: string) {
return assets[key as keyof IRocketChatAssets];
}

Expand Down Expand Up @@ -334,7 +344,7 @@ class RocketChatAssetsClass {

export const RocketChatAssets = new RocketChatAssetsClass();

async function addAssetToSetting(asset: string, value: IRocketChatAsset): Promise<void> {
export async function addAssetToSetting(asset: string, value: IRocketChatAsset, options?: Partial<ISetting>): Promise<void> {
const key = `Assets_${asset}`;

await settingsRegistry.add(
Expand All @@ -343,13 +353,15 @@ async function addAssetToSetting(asset: string, value: IRocketChatAsset): Promis
defaultUrl: value.defaultUrl,
},
{
type: 'asset',
group: 'Assets',
fileConstraints: value.constraints,
i18nLabel: value.label,
asset,
public: true,
wizard: value.wizard,
...{
type: 'asset',
group: 'Assets',
fileConstraints: value.constraints,
i18nLabel: value.label,
asset,
public: true,
},
...options,
},
);

Expand All @@ -363,12 +375,8 @@ async function addAssetToSetting(asset: string, value: IRocketChatAsset): Promis

void (async () => {
for await (const key of Object.keys(assets)) {
if (ignoredKeys.includes(key)) {
continue;
}

const value = getAssetByKey(key);
await addAssetToSetting(key, value);
const { wizard, settingOptions, ...value } = getAssetByKey(key);
await addAssetToSetting(key, value, { ...settingOptions, wizard });
}
})();

Expand Down
22 changes: 1 addition & 21 deletions apps/meteor/ee/app/livechat-enterprise/server/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,33 +228,13 @@ export const createSettings = async (): Promise<void> => {
group: 'Omnichannel',
section: 'Livechat',
invalidValue: false,
public: true,
enableQuery: omnichannelEnabledQuery,
i18nDescription: 'Livechat_hide_watermark_description',
enterprise: true,
sorter: 999,
modules: ['livechat-enterprise'],
});

await settingsRegistry.add(
'Assets_livechat_widget_logo',
{ defaultUrl: undefined },
{
type: 'asset',
group: 'Omnichannel',
section: 'Livechat',
invalidValue: null,
asset: 'livechat_widget_logo',
public: true,
enableQuery: omnichannelEnabledQuery,
enterprise: true,
modules: ['livechat-enterprise'],
fileConstraints: {
type: 'image',
extensions: ['svg', 'png', 'jpg', 'jpeg'],
},
},
);

await settingsRegistry.add('Omnichannel_contact_manager_routing', true, {
type: 'boolean',
group: 'Omnichannel',
Expand Down

0 comments on commit a3a807e

Please sign in to comment.