chore: Use Assets’ async API (#29311)

pull/29315/head^2
Rodrigo Nascimento 3 years ago committed by GitHub
parent 150454bcb5
commit df82bccb86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/meteor/app/livechat/server/livechat.ts
  2. 2
      apps/meteor/app/ui-master/server/index.js
  3. 8
      apps/meteor/definition/externals/meteor/meteor.d.ts
  4. 2
      apps/meteor/server/lib/dataExport/sendViaEmail.ts
  5. 6
      apps/meteor/server/lib/getMomentLocale.ts
  6. 14
      apps/meteor/server/routes/i18n.ts
  7. 2
      apps/meteor/server/startup/initialData.js

@ -5,7 +5,7 @@ import { WebApp } from 'meteor/webapp';
import { settings } from '../../settings/server';
import { addServerUrlToIndex } from '../lib/Assets';
const indexHtmlWithServerURL = addServerUrlToIndex(Assets.getText('livechat/index.html') || '');
const indexHtmlWithServerURL = addServerUrlToIndex((await Assets.getTextAsync('livechat/index.html')) || '');
WebApp.connectHandlers.use('/livechat', (req, res, next) => {
if (!req.url) {

@ -161,4 +161,4 @@ injectIntoBody(
`,
);
injectIntoBody('icons', Assets.getText('public/icons.svg'));
injectIntoBody('icons', await Assets.getTextAsync('public/icons.svg'));

@ -6,6 +6,14 @@ type StringifyBuffers<T extends unknown[]> = {
[P in keyof T]: T[P] extends Buffer ? string : T[P];
};
declare global {
namespace Assets {
function getBinaryAsync(assetPath: string): Promise<EJSON | undefined>;
function getTextAsync(assetPath: string): Promise<string | undefined>;
}
}
declare module 'meteor/meteor' {
namespace Meteor {
const Streamer: IStreamerConstructor & IStreamer;

@ -53,7 +53,7 @@ export async function sendViaEmail(
const localMoment = moment();
if (lang !== 'en') {
const localeFn = getMomentLocale(lang);
const localeFn = await getMomentLocale(lang);
if (localeFn) {
Function(localeFn).call({ moment });
localMoment.locale(lang);

@ -1,13 +1,13 @@
import { Meteor } from 'meteor/meteor';
export function getMomentLocale(locale: string): string | undefined {
export async function getMomentLocale(locale: string): Promise<string | undefined> {
const localeLower = locale.toLowerCase();
try {
return Assets.getText(`moment-locales/${localeLower}.js`);
return Assets.getTextAsync(`moment-locales/${localeLower}.js`);
} catch (error) {
try {
return Assets.getText(`moment-locales/${String(localeLower.split('-').shift())}.js`);
return Assets.getTextAsync(`moment-locales/${String(localeLower.split('-').shift())}.js`);
} catch (error) {
throw new Meteor.Error('moment-locale-not-found', `Moment locale not found: ${locale}`);
}

@ -17,18 +17,20 @@ const i18nHandler = async function (req: IncomingMessage, res: ServerResponse) {
const { lng } = match.params;
Assets.getText(`i18n/${lng}.i18n.json`, (err: Error, data: Record<string, any>) => {
if (err || !data) {
res.writeHead(400);
res.end();
return;
try {
const data = await Assets.getTextAsync(`i18n/${lng}.i18n.json`);
if (!data) {
throw new Error();
}
res.setHeader('Content-Type', 'application/json');
res.setHeader('Content-Length', data.length);
res.writeHead(200);
res.end(data);
});
} catch (e) {
res.writeHead(400);
res.end();
}
};
WebApp.connectHandlers.use('/i18n/', i18nHandler);

@ -38,7 +38,7 @@ Meteor.startup(async function () {
await addUserRolesAsync('rocket.cat', ['bot']);
const buffer = Buffer.from(Assets.getBinary('avatars/rocketcat.png'));
const buffer = Buffer.from(await Assets.getBinaryAsync('avatars/rocketcat.png'));
const rs = RocketChatFile.bufferToStream(buffer, 'utf8');
const fileStore = FileUpload.getStore('Avatars');

Loading…
Cancel
Save