snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
170
apps/meteor/server/lib/ui-master/index.ts
Normal file
170
apps/meteor/server/lib/ui-master/index.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
import type { ISettingColor } from '@rocket.chat/core-typings';
|
||||
import { Settings } from '@rocket.chat/models';
|
||||
import { escapeHTML } from '@rocket.chat/tools';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Inject } from 'meteor/meteorhacks:inject-initial';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
|
||||
import { applyHeadInjections, headInjections, injectIntoBody, injectIntoHead } from './inject';
|
||||
import { getMessageMaxParseLength } from '../../../lib/getMessageMaxParseLength';
|
||||
import { withDebouncing } from '../../../lib/utils/highOrderFunctions';
|
||||
import { settings } from '../../settings';
|
||||
import { getURL } from '../utils/getURL';
|
||||
|
||||
import './scripts';
|
||||
|
||||
export * from './inject';
|
||||
|
||||
Meteor.startup(() => {
|
||||
Tracker.autorun(() => {
|
||||
const injections = Object.values(headInjections.all()).filter((injection): injection is NonNullable<typeof injection> => !!injection);
|
||||
Inject.rawModHtml('headInjections', applyHeadInjections(injections));
|
||||
});
|
||||
|
||||
settings.watch<string>('Default_Referrer_Policy', (value) => {
|
||||
if (!value) {
|
||||
return injectIntoHead('noreferrer', '<meta name="referrer" content="same-origin" />');
|
||||
}
|
||||
|
||||
injectIntoHead('noreferrer', `<meta name="referrer" content="${value}" />`);
|
||||
});
|
||||
|
||||
settings.watch<boolean>('Use_RC_SDK', (value) => {
|
||||
injectIntoHead('Use_RC_SDK', `<meta name="rc-sdk-transport-enabled" content="${value ? 'on' : 'off'}" />`);
|
||||
});
|
||||
|
||||
if (process.env.DISABLE_ANIMATION) {
|
||||
injectIntoHead(
|
||||
'disable-animation',
|
||||
`
|
||||
<style>
|
||||
body, body * {
|
||||
animation: none !important;
|
||||
}
|
||||
</style>
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
settings.watch<boolean>('Assets_SvgFavicon_Enable', (value) => {
|
||||
const standardFavicons = `
|
||||
<link rel="icon" sizes="16x16" type="image/png" href=${getURL('assets/favicon_16.png')} />
|
||||
<link rel="icon" sizes="32x32" type="image/png" href=${getURL('assets/favicon_32.png')} />`;
|
||||
|
||||
if (value) {
|
||||
injectIntoHead(
|
||||
'Assets_SvgFavicon_Enable',
|
||||
`${standardFavicons}
|
||||
<link rel="icon" sizes="any" type="image/svg+xml" href=${getURL('assets/favicon.svg')} />`,
|
||||
);
|
||||
} else {
|
||||
injectIntoHead('Assets_SvgFavicon_Enable', standardFavicons);
|
||||
}
|
||||
});
|
||||
|
||||
settings.watch<string>('theme-color-sidebar-background', (value) => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead(
|
||||
'theme-color-sidebar-background',
|
||||
`<meta name="msapplication-TileColor" content="${escapedValue}" /><meta name="theme-color" content="${escapedValue}" />`,
|
||||
);
|
||||
});
|
||||
|
||||
settings.watch<string>('Site_Name', (value = 'Rocket.Chat') => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead(
|
||||
'Site_Name',
|
||||
`<title>${escapedValue}</title>` +
|
||||
`<meta name="application-name" content="${escapedValue}">` +
|
||||
`<meta name="apple-mobile-web-app-title" content="${escapedValue}">`,
|
||||
);
|
||||
});
|
||||
|
||||
settings.watch<string>('Meta_language', (value = '') => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead(
|
||||
'Meta_language',
|
||||
`<meta http-equiv="content-language" content="${escapedValue}"><meta name="language" content="${escapedValue}">`,
|
||||
);
|
||||
});
|
||||
|
||||
settings.watch<string>('Meta_robots', (value = '') => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead('Meta_robots', `<meta name="robots" content="${escapedValue}">`);
|
||||
});
|
||||
|
||||
settings.watch<string>('Meta_msvalidate01', (value = '') => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead('Meta_msvalidate01', `<meta name="msvalidate.01" content="${escapedValue}">`);
|
||||
});
|
||||
|
||||
settings.watch<string>('Meta_google-site-verification', (value = '') => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead('Meta_google-site-verification', `<meta name="google-site-verification" content="${escapedValue}">`);
|
||||
});
|
||||
|
||||
settings.watch<string>('Meta_fb_app_id', (value = '') => {
|
||||
const escapedValue = escapeHTML(value);
|
||||
injectIntoHead('Meta_fb_app_id', `<meta property="fb:app_id" content="${escapedValue}">`);
|
||||
});
|
||||
|
||||
settings.watch<string>('Meta_custom', (value = '') => {
|
||||
injectIntoHead('Meta_custom', value);
|
||||
});
|
||||
|
||||
const baseUrl = ((prefix) => {
|
||||
if (!prefix) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
prefix = prefix.trim();
|
||||
|
||||
if (!prefix) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return /\/$/.test(prefix) ? prefix : `${prefix}/`;
|
||||
})(__meteor_runtime_config__.ROOT_URL_PATH_PREFIX);
|
||||
|
||||
injectIntoHead('base', `<base href="${baseUrl}">`);
|
||||
|
||||
const escapedMessageMaxParseLength = escapeHTML(String(getMessageMaxParseLength()));
|
||||
injectIntoHead('MESSAGE_MAX_PARSE_LENGTH', `<meta name="rc-message-parser-max-length" content="${escapedMessageMaxParseLength}" />`);
|
||||
});
|
||||
|
||||
const renderDynamicCssList = withDebouncing({ wait: 500 })(async () => {
|
||||
// const variables = RocketChat.models.Settings.findOne({_id:'theme-custom-variables'}, {fields: { value: 1}});
|
||||
const colors = await Settings.find({ _id: /theme-color-rc/i }, { projection: { value: 1, editor: 1 } }).toArray();
|
||||
const css = colors
|
||||
.filter((color): color is ISettingColor => !!color?.value)
|
||||
.map(({ _id, value, editor }) => {
|
||||
if (editor === 'expression') {
|
||||
return `--${_id.replace('theme-color-', '')}: var(--${value});`;
|
||||
}
|
||||
return `--${_id.replace('theme-color-', '')}: ${value};`;
|
||||
})
|
||||
.join('\n');
|
||||
injectIntoBody('dynamic-variables', `<style id='css-variables'> :root {${css}}</style>`);
|
||||
});
|
||||
|
||||
await renderDynamicCssList();
|
||||
|
||||
settings.watchByRegex(/theme-color-rc/i, renderDynamicCssList);
|
||||
|
||||
injectIntoBody(
|
||||
'react-root',
|
||||
`
|
||||
<noscript style="color: white; text-align:center">
|
||||
You need to enable JavaScript to run this app.
|
||||
</noscript>
|
||||
<div id="react-root">
|
||||
<div class="page-loading" role="alert" aria-busy="true" aria-live="polite" aria-label="loading">
|
||||
<div class="loading__animation">
|
||||
<div class="loading__animation__bounce"></div>
|
||||
<div class="loading__animation__bounce"></div>
|
||||
<div class="loading__animation__bounce"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
);
|
||||
134
apps/meteor/server/lib/ui-master/inject.ts
Normal file
134
apps/meteor/server/lib/ui-master/inject.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
import type { NextHandleFunction } from 'connect';
|
||||
import { Inject } from 'meteor/meteorhacks:inject-initial';
|
||||
import { ReactiveDict } from 'meteor/reactive-dict';
|
||||
import { WebApp } from 'meteor/webapp';
|
||||
import parseRequest from 'parseurl';
|
||||
|
||||
import { getURL } from '../utils/getURL';
|
||||
|
||||
type Injection =
|
||||
| string
|
||||
| {
|
||||
content: string;
|
||||
type: 'JS' | 'CSS';
|
||||
tag: string;
|
||||
};
|
||||
|
||||
export const headInjections = new ReactiveDict<Record<string, Injection>>();
|
||||
|
||||
const callback: NextHandleFunction = (req, res, next) => {
|
||||
if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'OPTIONS') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const rawPath = parseRequest(req);
|
||||
const pathname = rawPath?.pathname && decodeURIComponent(rawPath.pathname);
|
||||
|
||||
if (!pathname) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const injection = headInjections.get(pathname.replace(/^\//, '').split('_')[0]);
|
||||
|
||||
if (!injection || typeof injection === 'string') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const serve =
|
||||
(contentType: string) =>
|
||||
(content: string, cacheControl = 'public, max-age=31536000'): void => {
|
||||
res.writeHead(200, {
|
||||
'Content-type': contentType,
|
||||
'cache-control': cacheControl,
|
||||
'Content-Length': content.length,
|
||||
});
|
||||
res.write(content);
|
||||
res.end();
|
||||
};
|
||||
|
||||
const serveStaticJS = serve('application/javascript; charset=UTF-8');
|
||||
const serveStaticCSS = serve('text/css; charset=UTF-8');
|
||||
|
||||
if (injection.type === 'JS') {
|
||||
serveStaticJS(injection.content);
|
||||
return;
|
||||
}
|
||||
|
||||
if (injection.type === 'CSS') {
|
||||
serveStaticCSS(injection.content);
|
||||
return;
|
||||
}
|
||||
next();
|
||||
} catch (e) {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
WebApp.connectHandlers.use(callback);
|
||||
|
||||
export const injectIntoHead = (key: string, value: Injection): void => {
|
||||
headInjections.set(key, value);
|
||||
};
|
||||
|
||||
export const addScript = (key: string, content: string): void => {
|
||||
if (/_/.test(key)) {
|
||||
throw new Error('inject.js > addScript - key cannot contain "_" (underscore)');
|
||||
}
|
||||
|
||||
if (!content.trim()) {
|
||||
injectIntoHead(key, '');
|
||||
return;
|
||||
}
|
||||
const currentHash = crypto.createHash('sha1').update(content).digest('hex');
|
||||
|
||||
injectIntoHead(key, {
|
||||
type: 'JS',
|
||||
tag: `<script id="${key}" type="text/javascript" src="${`${getURL(key)}_${currentHash}.js`}"></script>`,
|
||||
content,
|
||||
});
|
||||
};
|
||||
|
||||
export const addStyle = (key: string, content: string): void => {
|
||||
if (/_/.test(key)) {
|
||||
throw new Error('inject.js > addStyle - key cannot contain "_" (underscore)');
|
||||
}
|
||||
|
||||
if (!content.trim()) {
|
||||
injectIntoHead(key, '');
|
||||
return;
|
||||
}
|
||||
const currentHash = crypto.createHash('sha1').update(content).digest('hex');
|
||||
|
||||
injectIntoHead(key, {
|
||||
type: 'CSS',
|
||||
tag: `<link id="${key}" rel="stylesheet" type="text/css" href="${`${getURL(key)}_${currentHash}.css`}">`,
|
||||
content,
|
||||
});
|
||||
};
|
||||
|
||||
export const injectIntoBody = (key: string, value: string): void => {
|
||||
Inject.rawBody(key, value);
|
||||
};
|
||||
|
||||
export const applyHeadInjections = (injections: Injection[]): ((html: string) => string) => {
|
||||
if (injections.length === 0) {
|
||||
return (html: string): string => html;
|
||||
}
|
||||
|
||||
const replacementHtml = `${injections
|
||||
.map((i) => {
|
||||
if (typeof i === 'string') {
|
||||
return i;
|
||||
}
|
||||
return i.content.trim().length > 0 ? i.tag : '';
|
||||
})
|
||||
.join('\n')
|
||||
.replace(/\$/g, '$$$$')}\n</head>`;
|
||||
|
||||
return (html: string): string => html.replace('</head>', replacementHtml);
|
||||
};
|
||||
44
apps/meteor/server/lib/ui-master/scripts.ts
Normal file
44
apps/meteor/server/lib/ui-master/scripts.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { addScript } from './inject';
|
||||
import { settings } from '../../settings';
|
||||
|
||||
const getContent = (): string => `
|
||||
|
||||
${
|
||||
process.env.BUGSNAG_CLIENT
|
||||
? `window.__BUGSNAG_KEY__ = "${process.env.BUGSNAG_CLIENT}";\n
|
||||
window.addEventListener('load', function() {
|
||||
const event = new Event('bugsnag-error-boundary');
|
||||
window.dispatchEvent(event);
|
||||
});
|
||||
`
|
||||
: ''
|
||||
}
|
||||
|
||||
${process.env.DISABLE_ANIMATION ? 'window.DISABLE_ANIMATION = true;\n' : ''}
|
||||
|
||||
// Custom_Script_Logged_Out
|
||||
window.addEventListener('Custom_Script_Logged_Out', function() {
|
||||
${settings.get('Custom_Script_Logged_Out')}
|
||||
})
|
||||
|
||||
|
||||
// Custom_Script_Logged_In
|
||||
window.addEventListener('Custom_Script_Logged_In', function() {
|
||||
${settings.get('Custom_Script_Logged_In')}
|
||||
})
|
||||
|
||||
|
||||
// Custom_Script_On_Logout
|
||||
window.addEventListener('Custom_Script_On_Logout', function() {
|
||||
${settings.get('Custom_Script_On_Logout')}
|
||||
})
|
||||
|
||||
${settings.get('Accounts_ForgetUserSessionOnWindowClose') ? `window.Accounts_ForgetUserSessionOnWindowClose = true;` : ''}`;
|
||||
|
||||
settings.watchMultiple(
|
||||
['Custom_Script_Logged_Out', 'Custom_Script_Logged_In', 'Custom_Script_On_Logout', 'Accounts_ForgetUserSessionOnWindowClose'],
|
||||
() => {
|
||||
const content = getContent();
|
||||
addScript('scripts', content);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user