mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: remove max upload size from settings / use env var instead to centralize the config
This commit is contained in:
parent
bb83cd53bc
commit
99c702de17
@ -17,6 +17,5 @@
|
|||||||
"show_emoji": "Enable Emoji Picker",
|
"show_emoji": "Enable Emoji Picker",
|
||||||
"show_file": "Enable Attachment Uploader",
|
"show_file": "Enable Attachment Uploader",
|
||||||
"show_location": "Enable Geolocation Share",
|
"show_location": "Enable Geolocation Share",
|
||||||
"allowed_upload_size": "Max Upload Size (in bytes)",
|
|
||||||
"allowed_upload_types": "Allowed Upload Mime Types (comma separated)"
|
"allowed_upload_types": "Allowed Upload Mime Types (comma separated)"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,5 @@
|
|||||||
"show_emoji": "Activer le sélecteur d'Emojis",
|
"show_emoji": "Activer le sélecteur d'Emojis",
|
||||||
"show_file": "Activer l'upload de fichiers",
|
"show_file": "Activer l'upload de fichiers",
|
||||||
"show_location": "Activer le partage de géolocalisation",
|
"show_location": "Activer le partage de géolocalisation",
|
||||||
"allowed_upload_size": "Taille maximale de téléchargement (en octets)",
|
|
||||||
"allowed_upload_types": "Types MIME autorisés pour le téléchargement (séparés par des virgules)"
|
"allowed_upload_types": "Types MIME autorisés pour le téléchargement (séparés par des virgules)"
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ import { ChannelSetting } from '@/channel/types';
|
|||||||
import { config } from '@/config';
|
import { config } from '@/config';
|
||||||
import { SettingType } from '@/setting/schemas/types';
|
import { SettingType } from '@/setting/schemas/types';
|
||||||
|
|
||||||
import { Web } from '../web/types';
|
|
||||||
|
|
||||||
export const CONSOLE_CHANNEL_NAME = 'console-channel';
|
export const CONSOLE_CHANNEL_NAME = 'console-channel';
|
||||||
|
|
||||||
export const CONSOLE_CHANNEL_NAMESPACE = 'console_channel';
|
export const CONSOLE_CHANNEL_NAMESPACE = 'console_channel';
|
||||||
@ -19,68 +17,62 @@ export const CONSOLE_CHANNEL_NAMESPACE = 'console_channel';
|
|||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.allowed_domains,
|
label: 'allowed_domains',
|
||||||
value: config.security.cors.allowOrigins.join(','),
|
value: config.security.cors.allowOrigins.join(','),
|
||||||
type: SettingType.text,
|
type: SettingType.text,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.start_button,
|
label: 'start_button',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.input_disabled,
|
label: 'input_disabled',
|
||||||
value: false,
|
value: false,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.persistent_menu,
|
label: 'persistent_menu',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.greeting_message,
|
label: 'greeting_message',
|
||||||
value: 'Welcome! Ready to start a conversation with our chatbot?',
|
value: 'Welcome! Ready to start a conversation with our chatbot?',
|
||||||
type: SettingType.textarea,
|
type: SettingType.textarea,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.theme_color,
|
label: 'theme_color',
|
||||||
value: 'teal',
|
value: 'teal',
|
||||||
type: SettingType.select,
|
type: SettingType.select,
|
||||||
options: ['teal', 'orange', 'red', 'green', 'blue', 'dark'],
|
options: ['teal', 'orange', 'red', 'green', 'blue', 'dark'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.show_emoji,
|
label: 'show_emoji',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.show_file,
|
label: 'show_file',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.show_location,
|
label: 'show_location',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
group: CONSOLE_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.allowed_upload_size,
|
label: 'allowed_upload_types',
|
||||||
value: 2500000,
|
|
||||||
type: SettingType.number,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
group: CONSOLE_CHANNEL_NAMESPACE,
|
|
||||||
label: Web.SettingLabel.allowed_upload_types,
|
|
||||||
value:
|
value:
|
||||||
'audio/mpeg,audio/x-ms-wma,audio/vnd.rn-realaudio,audio/x-wav,image/gif,image/jpeg,image/png,image/tiff,image/vnd.microsoft.icon,image/vnd.djvu,image/svg+xml,text/css,text/csv,text/html,text/plain,text/xml,video/mpeg,video/mp4,video/quicktime,video/x-ms-wmv,video/x-msvideo,video/x-flv,video/web,application/msword,application/vnd.ms-powerpoint,application/pdf,application/vnd.ms-excel,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.tex,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.graphics,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
'audio/mpeg,audio/x-ms-wma,audio/vnd.rn-realaudio,audio/x-wav,image/gif,image/jpeg,image/png,image/tiff,image/vnd.microsoft.icon,image/vnd.djvu,image/svg+xml,text/css,text/csv,text/html,text/plain,text/xml,video/mpeg,video/mp4,video/quicktime,video/x-ms-wmv,video/x-msvideo,video/x-flv,video/web,application/msword,application/vnd.ms-powerpoint,application/pdf,application/vnd.ms-excel,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.tex,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.graphics,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
type: SettingType.textarea,
|
type: SettingType.textarea,
|
||||||
|
@ -17,6 +17,5 @@
|
|||||||
"show_emoji": "Enable Emoji Picker",
|
"show_emoji": "Enable Emoji Picker",
|
||||||
"show_file": "Enable Attachment Uploader",
|
"show_file": "Enable Attachment Uploader",
|
||||||
"show_location": "Enable Geolocation Share",
|
"show_location": "Enable Geolocation Share",
|
||||||
"allowed_upload_size": "Max Upload Size (in bytes)",
|
|
||||||
"allowed_upload_types": "Allowed Upload Mime Types (comma separated)"
|
"allowed_upload_types": "Allowed Upload Mime Types (comma separated)"
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,5 @@
|
|||||||
"show_emoji": "Activer le sélecteur d'Emojis",
|
"show_emoji": "Activer le sélecteur d'Emojis",
|
||||||
"show_file": "Activer l'upload de fichiers",
|
"show_file": "Activer l'upload de fichiers",
|
||||||
"show_location": "Activer le partage de géolocalisation",
|
"show_location": "Activer le partage de géolocalisation",
|
||||||
"allowed_upload_size": "Taille maximale de téléchargement (en octets)",
|
|
||||||
"allowed_upload_types": "Types MIME autorisés pour le téléchargement (séparés par des virgules)"
|
"allowed_upload_types": "Types MIME autorisés pour le téléchargement (séparés par des virgules)"
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
import { ChannelSetting } from '@/channel/types';
|
import { ChannelSetting } from '@/channel/types';
|
||||||
import { SettingType } from '@/setting/schemas/types';
|
import { SettingType } from '@/setting/schemas/types';
|
||||||
|
|
||||||
import { Web } from './types';
|
|
||||||
|
|
||||||
export const WEB_CHANNEL_NAME = 'web-channel' as const;
|
export const WEB_CHANNEL_NAME = 'web-channel' as const;
|
||||||
|
|
||||||
export const WEB_CHANNEL_NAMESPACE = 'web_channel';
|
export const WEB_CHANNEL_NAMESPACE = 'web_channel';
|
||||||
@ -18,82 +16,76 @@ export const WEB_CHANNEL_NAMESPACE = 'web_channel';
|
|||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.allowed_domains,
|
label: 'allowed_domains',
|
||||||
value: 'http://localhost:8080,http://localhost:4000',
|
value: 'http://localhost:8080,http://localhost:4000',
|
||||||
type: SettingType.text,
|
type: SettingType.text,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.start_button,
|
label: 'start_button',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.input_disabled,
|
label: 'input_disabled',
|
||||||
value: false,
|
value: false,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.persistent_menu,
|
label: 'persistent_menu',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.greeting_message,
|
label: 'greeting_message',
|
||||||
value: 'Welcome! Ready to start a conversation with our chatbot?',
|
value: 'Welcome! Ready to start a conversation with our chatbot?',
|
||||||
type: SettingType.textarea,
|
type: SettingType.textarea,
|
||||||
translatable: true,
|
translatable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.theme_color,
|
label: 'theme_color',
|
||||||
value: 'teal',
|
value: 'teal',
|
||||||
type: SettingType.select,
|
type: SettingType.select,
|
||||||
options: ['teal', 'orange', 'red', 'green', 'blue', 'dark'],
|
options: ['teal', 'orange', 'red', 'green', 'blue', 'dark'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.window_title,
|
label: 'window_title',
|
||||||
value: 'Widget Title',
|
value: 'Widget Title',
|
||||||
type: SettingType.text,
|
type: SettingType.text,
|
||||||
translatable: true,
|
translatable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.avatar_url,
|
label: 'avatar_url',
|
||||||
value: '',
|
value: '',
|
||||||
type: SettingType.text,
|
type: SettingType.text,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.show_emoji,
|
label: 'show_emoji',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.show_file,
|
label: 'show_file',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.show_location,
|
label: 'show_location',
|
||||||
value: true,
|
value: true,
|
||||||
type: SettingType.checkbox,
|
type: SettingType.checkbox,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
group: WEB_CHANNEL_NAMESPACE,
|
||||||
label: Web.SettingLabel.allowed_upload_size,
|
label: 'allowed_upload_types',
|
||||||
value: 2500000,
|
|
||||||
type: SettingType.number,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
group: WEB_CHANNEL_NAMESPACE,
|
|
||||||
label: Web.SettingLabel.allowed_upload_types,
|
|
||||||
value:
|
value:
|
||||||
'audio/mpeg,audio/x-ms-wma,audio/vnd.rn-realaudio,audio/x-wav,image/gif,image/jpeg,image/png,image/tiff,image/vnd.microsoft.icon,image/vnd.djvu,image/svg+xml,text/css,text/csv,text/html,text/plain,text/xml,video/mpeg,video/mp4,video/quicktime,video/x-ms-wmv,video/x-msvideo,video/x-flv,video/web,application/msword,application/vnd.ms-powerpoint,application/pdf,application/vnd.ms-excel,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.tex,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.graphics,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
'audio/mpeg,audio/x-ms-wma,audio/vnd.rn-realaudio,audio/x-wav,image/gif,image/jpeg,image/png,image/tiff,image/vnd.microsoft.icon,image/vnd.djvu,image/svg+xml,text/css,text/csv,text/html,text/plain,text/xml,video/mpeg,video/mp4,video/quicktime,video/x-ms-wmv,video/x-msvideo,video/x-flv,video/web,application/msword,application/vnd.ms-powerpoint,application/pdf,application/vnd.ms-excel,application/vnd.oasis.opendocument.presentation,application/vnd.oasis.opendocument.tex,application/vnd.oasis.opendocument.spreadsheet,application/vnd.oasis.opendocument.graphics,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
type: SettingType.textarea,
|
type: SettingType.textarea,
|
||||||
|
@ -12,24 +12,6 @@ import { FileType } from '@/chat/schemas/types/message';
|
|||||||
import { StdQuickReply } from '@/chat/schemas/types/quick-reply';
|
import { StdQuickReply } from '@/chat/schemas/types/quick-reply';
|
||||||
|
|
||||||
export namespace Web {
|
export namespace Web {
|
||||||
export enum SettingLabel {
|
|
||||||
allowed_domains = 'allowed_domains',
|
|
||||||
start_button = 'start_button',
|
|
||||||
input_disabled = 'input_disabled',
|
|
||||||
persistent_menu = 'persistent_menu',
|
|
||||||
greeting_message = 'greeting_message',
|
|
||||||
theme_color = 'theme_color',
|
|
||||||
window_title = 'window_title',
|
|
||||||
avatar_url = 'avatar_url',
|
|
||||||
show_emoji = 'show_emoji',
|
|
||||||
show_file = 'show_file',
|
|
||||||
show_location = 'show_location',
|
|
||||||
allowed_upload_size = 'allowed_upload_size',
|
|
||||||
allowed_upload_types = 'allowed_upload_types',
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Settings = Record<SettingLabel, any>;
|
|
||||||
|
|
||||||
export type RequestSession = {
|
export type RequestSession = {
|
||||||
web?: {
|
web?: {
|
||||||
profile: SubscriberFull;
|
profile: SubscriberFull;
|
||||||
|
@ -16,7 +16,7 @@ SESSION_SECRET=f661ff500fff6b0c8f91310b6fff6b0c
|
|||||||
SESSION_NAME=s.id
|
SESSION_NAME=s.id
|
||||||
UPLOAD_DIR=/uploads
|
UPLOAD_DIR=/uploads
|
||||||
AVATAR_DIR=/avatars
|
AVATAR_DIR=/avatars
|
||||||
UPLOAD_MAX_SIZE_IN_BYTES=2000000
|
UPLOAD_MAX_SIZE_IN_BYTES=20971520
|
||||||
INVITATION_JWT_SECRET=dev_only
|
INVITATION_JWT_SECRET=dev_only
|
||||||
INVITATION_EXPIRES_IN=24h
|
INVITATION_EXPIRES_IN=24h
|
||||||
PASSWORD_RESET_JWT_SECRET=dev_only
|
PASSWORD_RESET_JWT_SECRET=dev_only
|
||||||
|
@ -23,6 +23,6 @@ export default function handler(
|
|||||||
ssoEnabled: process.env.NEXT_PUBLIC_SSO_ENABLED === "true" || false,
|
ssoEnabled: process.env.NEXT_PUBLIC_SSO_ENABLED === "true" || false,
|
||||||
maxUploadSize: process.env.UPLOAD_MAX_SIZE_IN_BYTES
|
maxUploadSize: process.env.UPLOAD_MAX_SIZE_IN_BYTES
|
||||||
? Number(process.env.UPLOAD_MAX_SIZE_IN_BYTES)
|
? Number(process.env.UPLOAD_MAX_SIZE_IN_BYTES)
|
||||||
: 50 * 1024 * 1024, // 50 MB in bytes
|
: 20 * 1024 * 1024, // 20 MB in bytes
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,21 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import "normalize.css";
|
||||||
|
import "./ChatWidget.css";
|
||||||
import Launcher from "./components/Launcher";
|
import Launcher from "./components/Launcher";
|
||||||
import UserSubscription from "./components/UserSubscription";
|
import UserSubscription from "./components/UserSubscription";
|
||||||
import ChatProvider from "./providers/ChatProvider";
|
import ChatProvider from "./providers/ChatProvider";
|
||||||
import { ColorProvider } from "./providers/ColorProvider";
|
import { ColorProvider } from "./providers/ColorProvider";
|
||||||
import { Config, ConfigProvider } from "./providers/ConfigProvider";
|
import { ConfigProvider } from "./providers/ConfigProvider";
|
||||||
import { CookieProvider } from "./providers/CookieProvider";
|
import { CookieProvider } from "./providers/CookieProvider";
|
||||||
import { SettingsProvider } from "./providers/SettingsProvider";
|
import { SettingsProvider } from "./providers/SettingsProvider";
|
||||||
import { SocketProvider } from "./providers/SocketProvider";
|
import { SocketProvider } from "./providers/SocketProvider";
|
||||||
import { TranslationProvider } from "./providers/TranslationProvider";
|
import { TranslationProvider } from "./providers/TranslationProvider";
|
||||||
import WidgetProvider from "./providers/WidgetProvider";
|
import WidgetProvider from "./providers/WidgetProvider";
|
||||||
import "normalize.css";
|
import { Config } from "./types/config.types";
|
||||||
import "./ChatWidget.css";
|
|
||||||
|
|
||||||
function ChatWidget(props: Config) {
|
function ChatWidget(props: Partial<Config>) {
|
||||||
return (
|
return (
|
||||||
<ConfigProvider {...props}>
|
<ConfigProvider {...props}>
|
||||||
<TranslationProvider>
|
<TranslationProvider>
|
||||||
|
@ -12,13 +12,14 @@ import Launcher from "./components/Launcher";
|
|||||||
import UserSubscription from "./components/UserSubscription";
|
import UserSubscription from "./components/UserSubscription";
|
||||||
import ChatProvider from "./providers/ChatProvider";
|
import ChatProvider from "./providers/ChatProvider";
|
||||||
import { ColorProvider } from "./providers/ColorProvider";
|
import { ColorProvider } from "./providers/ColorProvider";
|
||||||
import { Config, ConfigProvider } from "./providers/ConfigProvider";
|
import { ConfigProvider } from "./providers/ConfigProvider";
|
||||||
import { SettingsProvider } from "./providers/SettingsProvider";
|
import { SettingsProvider } from "./providers/SettingsProvider";
|
||||||
import { SocketProvider } from "./providers/SocketProvider";
|
import { SocketProvider } from "./providers/SocketProvider";
|
||||||
import { TranslationProvider } from "./providers/TranslationProvider";
|
import { TranslationProvider } from "./providers/TranslationProvider";
|
||||||
import WidgetProvider, { WidgetContextType } from "./providers/WidgetProvider";
|
import WidgetProvider, { WidgetContextType } from "./providers/WidgetProvider";
|
||||||
import "./UiChatWidget.css";
|
import { Config } from "./types/config.types";
|
||||||
import { ConnectionState } from "./types/state.types";
|
import { ConnectionState } from "./types/state.types";
|
||||||
|
import "./UiChatWidget.css";
|
||||||
|
|
||||||
type UiChatWidgetProps = PropsWithChildren<{
|
type UiChatWidgetProps = PropsWithChildren<{
|
||||||
CustomLauncher?: (props: { widget: WidgetContextType }) => JSX.Element;
|
CustomLauncher?: (props: { widget: WidgetContextType }) => JSX.Element;
|
||||||
@ -26,7 +27,7 @@ type UiChatWidgetProps = PropsWithChildren<{
|
|||||||
CustomAvatar?: () => JSX.Element;
|
CustomAvatar?: () => JSX.Element;
|
||||||
PreChat?: React.FC;
|
PreChat?: React.FC;
|
||||||
PostChat?: React.FC;
|
PostChat?: React.FC;
|
||||||
config: Config;
|
config: Partial<Config>;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
function UiChatWidget({
|
function UiChatWidget({
|
||||||
|
@ -11,6 +11,7 @@ import React, { useEffect, useRef, useState } from "react";
|
|||||||
import { useTranslation } from "../hooks/useTranslation";
|
import { useTranslation } from "../hooks/useTranslation";
|
||||||
import { useChat } from "../providers/ChatProvider";
|
import { useChat } from "../providers/ChatProvider";
|
||||||
import { useColors } from "../providers/ColorProvider";
|
import { useColors } from "../providers/ColorProvider";
|
||||||
|
import { useConfig } from "../providers/ConfigProvider";
|
||||||
import { useSettings } from "../providers/SettingsProvider";
|
import { useSettings } from "../providers/SettingsProvider";
|
||||||
import { TOutgoingMessageType } from "../types/message.types";
|
import { TOutgoingMessageType } from "../types/message.types";
|
||||||
import { OutgoingMessageState } from "../types/state.types";
|
import { OutgoingMessageState } from "../types/state.types";
|
||||||
@ -27,6 +28,7 @@ import Suggestions from "./Suggestions";
|
|||||||
import "./UserInput.scss";
|
import "./UserInput.scss";
|
||||||
|
|
||||||
const UserInput: React.FC = () => {
|
const UserInput: React.FC = () => {
|
||||||
|
const { maxUploadSize } = useConfig();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { colors } = useColors();
|
const { colors } = useColors();
|
||||||
const {
|
const {
|
||||||
@ -43,7 +45,6 @@ const UserInput: React.FC = () => {
|
|||||||
focusOnOpen,
|
focusOnOpen,
|
||||||
autoFlush,
|
autoFlush,
|
||||||
allowedUploadTypes,
|
allowedUploadTypes,
|
||||||
allowedUploadSize,
|
|
||||||
showEmoji,
|
showEmoji,
|
||||||
showLocation,
|
showLocation,
|
||||||
showFile,
|
showFile,
|
||||||
@ -106,7 +107,7 @@ const UserInput: React.FC = () => {
|
|||||||
|
|
||||||
if (!typeCheck) {
|
if (!typeCheck) {
|
||||||
setFileError(t("messages.file_message.unsupported_file_type"));
|
setFileError(t("messages.file_message.unsupported_file_type"));
|
||||||
} else if (file.size > (allowedUploadSize || 0)) {
|
} else if (file.size > maxUploadSize) {
|
||||||
setFileError(t("messages.file_message.unsupported_file_size"));
|
setFileError(t("messages.file_message.unsupported_file_size"));
|
||||||
} else {
|
} else {
|
||||||
send({
|
send({
|
||||||
|
@ -6,8 +6,13 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const DEFAULT_CONFIG = {
|
import { Config } from "../types/config.types";
|
||||||
|
|
||||||
|
export const DEFAULT_CONFIG: Config = {
|
||||||
apiUrl: process.env.REACT_APP_WIDGET_API_URL || "http://localhost:4000",
|
apiUrl: process.env.REACT_APP_WIDGET_API_URL || "http://localhost:4000",
|
||||||
channel: process.env.REACT_APP_WIDGET_CHANNEL || "console-channel",
|
channel: process.env.REACT_APP_WIDGET_CHANNEL || "console-channel",
|
||||||
language: "en",
|
language: "en",
|
||||||
|
maxUploadSize: process.env.UPLOAD_MAX_SIZE_IN_BYTES
|
||||||
|
? Number(process.env.UPLOAD_MAX_SIZE_IN_BYTES)
|
||||||
|
: 20 * 1024 * 1024, // 20 MB in bytes
|
||||||
};
|
};
|
||||||
|
@ -9,23 +9,15 @@
|
|||||||
import React, { createContext, ReactNode, useContext, useRef } from "react";
|
import React, { createContext, ReactNode, useContext, useRef } from "react";
|
||||||
|
|
||||||
import { DEFAULT_CONFIG } from "../constants/defaultConfig";
|
import { DEFAULT_CONFIG } from "../constants/defaultConfig";
|
||||||
|
import { Config } from "../types/config.types";
|
||||||
|
|
||||||
// Define the type for your config, including all possible properties
|
|
||||||
export type Config = {
|
|
||||||
apiUrl: string;
|
|
||||||
channel: string;
|
|
||||||
language: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create a context with a specific type, providing better type-checking
|
|
||||||
const ConfigContext = createContext<Config>(DEFAULT_CONFIG);
|
const ConfigContext = createContext<Config>(DEFAULT_CONFIG);
|
||||||
|
|
||||||
export const ConfigProvider: React.FC<{
|
export const ConfigProvider: React.FC<
|
||||||
apiUrl?: string;
|
Partial<Config> & {
|
||||||
channel?: string;
|
children: ReactNode;
|
||||||
language?: string;
|
}
|
||||||
children: ReactNode;
|
> = ({ children, ...providedConfig }) => {
|
||||||
}> = ({ children, ...providedConfig }) => {
|
|
||||||
const config = useRef<Config>({
|
const config = useRef<Config>({
|
||||||
...DEFAULT_CONFIG,
|
...DEFAULT_CONFIG,
|
||||||
...providedConfig,
|
...providedConfig,
|
||||||
|
@ -35,7 +35,6 @@ type ChannelSettings = {
|
|||||||
show_location: boolean;
|
show_location: boolean;
|
||||||
allowed_upload_types: string;
|
allowed_upload_types: string;
|
||||||
greeting_message: string;
|
greeting_message: string;
|
||||||
allowed_upload_size: number;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ChatSettings = {
|
type ChatSettings = {
|
||||||
@ -52,7 +51,6 @@ type ChatSettings = {
|
|||||||
menu: IMenuNode[];
|
menu: IMenuNode[];
|
||||||
autoFlush: boolean;
|
autoFlush: boolean;
|
||||||
allowedUploadTypes: string[];
|
allowedUploadTypes: string[];
|
||||||
allowedUploadSize: number;
|
|
||||||
color: string;
|
color: string;
|
||||||
greetingMessage: string;
|
greetingMessage: string;
|
||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
@ -72,7 +70,6 @@ const defaultSettings: ChatSettings = {
|
|||||||
menu: [],
|
menu: [],
|
||||||
autoFlush: true,
|
autoFlush: true,
|
||||||
allowedUploadTypes: ["image/gif", "image/png", "image/jpeg"],
|
allowedUploadTypes: ["image/gif", "image/png", "image/jpeg"],
|
||||||
allowedUploadSize: 2500000,
|
|
||||||
color: "blue",
|
color: "blue",
|
||||||
greetingMessage: "Welcome !",
|
greetingMessage: "Welcome !",
|
||||||
avatarUrl: "",
|
avatarUrl: "",
|
||||||
@ -106,7 +103,6 @@ export const SettingsProvider: React.FC<ChatSettingsProviderProps> = ({
|
|||||||
titleImageUrl: settings.avatar_url,
|
titleImageUrl: settings.avatar_url,
|
||||||
menu: settings.menu,
|
menu: settings.menu,
|
||||||
allowedUploadTypes: settings.allowed_upload_types.split(","),
|
allowedUploadTypes: settings.allowed_upload_types.split(","),
|
||||||
allowedUploadSize: settings.allowed_upload_size,
|
|
||||||
inputDisabled: settings.input_disabled,
|
inputDisabled: settings.input_disabled,
|
||||||
color: settings.theme_color,
|
color: settings.theme_color,
|
||||||
greetingMessage: settings.greeting_message,
|
greetingMessage: settings.greeting_message,
|
||||||
|
14
widget/src/types/config.types.ts
Normal file
14
widget/src/types/config.types.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type Config = {
|
||||||
|
apiUrl: string;
|
||||||
|
channel: string;
|
||||||
|
language: string;
|
||||||
|
maxUploadSize: number;
|
||||||
|
};
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import { io, ManagerOptions, Socket, SocketOptions } from "socket.io-client";
|
import { io, ManagerOptions, Socket, SocketOptions } from "socket.io-client";
|
||||||
|
|
||||||
import { Config } from "../providers/ConfigProvider";
|
import { Config } from "../types/config.types";
|
||||||
import {
|
import {
|
||||||
IOIncomingMessage,
|
IOIncomingMessage,
|
||||||
IOOutgoingMessage,
|
IOOutgoingMessage,
|
||||||
|
Loading…
Reference in New Issue
Block a user