refactor: Separate isomorphic imports on utils - 1 (#29052)
parent
37cb94cc8c
commit
93f9828b5e
@ -1,8 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
if (Meteor.isClient) { |
||||
module.exports = require('./client/'); |
||||
} |
||||
if (Meteor.isServer) { |
||||
module.exports = require('./server/index.js'); |
||||
} |
||||
@ -0,0 +1,13 @@ |
||||
import { settings } from '../../settings/client'; |
||||
import { getURLWithoutSettings } from '../lib/getURL'; |
||||
|
||||
export const getURL = function ( |
||||
path: string, // eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
params: Record<string, any> = {}, |
||||
cloudDeepLinkUrl?: string, |
||||
): string { |
||||
const cdnPrefix = settings.get('CDN_PREFIX') || ''; |
||||
const siteUrl = settings.get('Site_Url') || ''; |
||||
|
||||
return getURLWithoutSettings(path, params, cdnPrefix, siteUrl, cloudDeepLinkUrl); |
||||
}; |
||||
@ -0,0 +1,14 @@ |
||||
import { getAvatarURL } from './getAvatarURL'; |
||||
import { settings } from '../../settings/client'; |
||||
|
||||
export const getUserAvatarURL = function (username: string, cache = ''): string | undefined { |
||||
const externalSource = (settings.get<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); |
||||
if (externalSource !== '') { |
||||
return externalSource.replace('{username}', username); |
||||
} |
||||
if (username == null) { |
||||
return; |
||||
} |
||||
|
||||
return getAvatarURL({ username, cache }); |
||||
}; |
||||
@ -1,8 +1,8 @@ |
||||
export { t } from '../lib/tapi18n'; |
||||
export { Info } from '../rocketchat.info'; |
||||
export { getUserPreference } from './lib/getUserPreference'; |
||||
export { fileUploadIsValidContentType } from '../lib/fileUploadRestrictions'; |
||||
export { getUserAvatarURL } from '../lib/getUserAvatarURL'; |
||||
export { fileUploadIsValidContentType } from './restrictions'; |
||||
export { getUserAvatarURL } from './getUserAvatarURL'; |
||||
export { slashCommands } from '../lib/slashCommand'; |
||||
export { getURL } from '../lib/getURL'; |
||||
export { getURL } from './getURL'; |
||||
export { APIClient } from './lib/RestApiClient'; |
||||
|
||||
@ -0,0 +1,9 @@ |
||||
import { fileUploadIsValidContentTypeFromSettings } from '../lib/restrictions'; |
||||
import { settings } from '../../settings/client'; |
||||
|
||||
export const fileUploadIsValidContentType = function (type: string, customWhiteList?: string): boolean { |
||||
const blackList = settings.get<string>('FileUpload_MediaTypeBlackList'); |
||||
const whiteList = customWhiteList || settings.get<string>('FileUpload_MediaTypeWhiteList'); |
||||
|
||||
return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList); |
||||
}; |
||||
@ -1,14 +0,0 @@ |
||||
import { getAvatarURL } from './getAvatarURL'; |
||||
import { settings } from '../../settings'; |
||||
|
||||
export const getUserAvatarURL = function (username, cache = '') { |
||||
const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); |
||||
if (externalSource !== '') { |
||||
return externalSource.replace('{username}', username); |
||||
} |
||||
if (username == null) { |
||||
return; |
||||
} |
||||
|
||||
return getAvatarURL({ username, cache }); |
||||
}; |
||||
@ -0,0 +1,10 @@ |
||||
import { getURL } from './getURL'; |
||||
|
||||
export const getAvatarURL = ({ username, roomId, cache }: { username?: string; roomId?: string; cache?: string }): string | undefined => { |
||||
if (username) { |
||||
return getURL(`/avatar/${encodeURIComponent(username)}${cache ? `?etag=${cache}` : ''}`); |
||||
} |
||||
if (roomId) { |
||||
return getURL(`/avatar/room/${encodeURIComponent(roomId)}${cache ? `?etag=${cache}` : ''}`); |
||||
} |
||||
}; |
||||
@ -0,0 +1,13 @@ |
||||
import { settings } from '../../settings/server'; |
||||
import { getURLWithoutSettings } from '../lib/getURL'; |
||||
|
||||
export const getURL = function ( |
||||
path: string, // eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
params: Record<string, any> = {}, |
||||
cloudDeepLinkUrl?: string, |
||||
): string { |
||||
const cdnPrefix = settings.get<string>('CDN_PREFIX') || ''; |
||||
const siteUrl = settings.get<string>('Site_Url') || ''; |
||||
|
||||
return getURLWithoutSettings(path, params, cdnPrefix, siteUrl, cloudDeepLinkUrl); |
||||
}; |
||||
@ -0,0 +1,14 @@ |
||||
import { getAvatarURL } from './getAvatarURL'; |
||||
import { settings } from '../../settings/server'; |
||||
|
||||
export const getUserAvatarURL = function (username: string, cache = ''): string | undefined { |
||||
const externalSource = (settings.get<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); |
||||
if (externalSource !== '') { |
||||
return externalSource.replace('{username}', username); |
||||
} |
||||
if (username == null) { |
||||
return; |
||||
} |
||||
|
||||
return getAvatarURL({ username, cache }); |
||||
}; |
||||
@ -0,0 +1,9 @@ |
||||
import { fileUploadIsValidContentTypeFromSettings } from '../lib/restrictions'; |
||||
import { settings } from '../../settings/server'; |
||||
|
||||
export const fileUploadIsValidContentType = function (type: string, customWhiteList?: string): boolean { |
||||
const blackList = settings.get<string>('FileUpload_MediaTypeBlackList'); |
||||
const whiteList = customWhiteList || settings.get<string>('FileUpload_MediaTypeWhiteList'); |
||||
|
||||
return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList); |
||||
}; |
||||
@ -1,5 +1,5 @@ |
||||
import { Template } from 'meteor/templating'; |
||||
|
||||
import { getUserAvatarURL } from '../../app/utils/lib/getUserAvatarURL'; |
||||
import { getUserAvatarURL } from '../../app/utils/client/getUserAvatarURL'; |
||||
|
||||
Template.registerHelper('avatarUrlFromUsername', getUserAvatarURL); |
||||
|
||||
Loading…
Reference in new issue