added rate limit config to web ui

fixed number input problem
This commit is contained in:
euzu
2025-03-27 17:24:20 +01:00
parent 3351e3c837
commit 5f9576e2a0
5 changed files with 32 additions and 6 deletions
+4 -1
View File
@@ -85,7 +85,10 @@
"XTREAM_CODES": "xtream codes",
"XC": "xc",
"M3U": "m3u",
"PLAYLIST_BROWSER": "Playlist Browser"
"PLAYLIST_BROWSER": "Playlist Browser",
"RATE_LIMIT": "Rate Limit",
"PERIOD_MILLIS": "Period Millis",
"BURST_SIZE": "Burst Size"
},
"TITLE": {
"USER_BOUQUET_EDITOR": "User group editor"
@@ -64,7 +64,15 @@ export default function FormView(props: FormViewProps) {
const handleInputValueChange = useCallback((evt: any) => {
const field = evt.target.dataset.field;
const value = evt.target.value;
let value = evt.target.value;
for (const fieldDef of fields) {
if (fieldDef.name === field) {
if (fieldDef.fieldType === FormFieldType.NUMBER) {
value = parseInt(value);
}
}
}
if (data) {
data[field] = value;
}
@@ -4,7 +4,7 @@ import ServerConfig, {
CacheConfig,
LogConfig,
MessagingConfig,
PushoverConfig,
PushoverConfig, RateLimitConfig,
RestConfig,
ReverseProxyConfig,
ServerApiConfig,
@@ -72,9 +72,14 @@ const CONFIG_REVERSE_PROXY_STREAM_BUFFER_FIELDS = [
const CONFIG_REVERSE_PROXY_CACHE_FIELDS = [
{name: 'enabled', label: 'LABEL.ENABLED', fieldType: FormFieldType.CHECK},
{name: 'size', label: 'LABEL.SIZE', fieldType: FormFieldType.TEXT},
{name: 'sir', label: 'LABEL.CACHE_DIR', fieldType: FormFieldType.TEXT},
{name: 'dir', label: 'LABEL.CACHE_DIR', fieldType: FormFieldType.TEXT},
];
const CONFIG_REVERSE_PROXY_RATE_LIMIT_FIELDS = [
{name: 'enabled', label: 'LABEL.ENABLED', fieldType: FormFieldType.CHECK},
{name: 'period_millis', label: 'LABEL.PERIOD_MILLIS', fieldType: FormFieldType.NUMBER},
{name: 'burst_size', label: 'LABEL.BURST_SIZE', fieldType: FormFieldType.NUMBER},
];
const CONFIG_MESSAGING_FIELDS = [
{
@@ -147,6 +152,7 @@ export default function MainConfigView(props: MainConfigViewProps) {
const reverseProxyStreamConfig = useMemo<StreamConfig>(() => config?.reverse_proxy?.stream || {} as any, [config]);
const reverseProxyStreamBufferConfig = useMemo<StreamBufferConfig>(() => config?.reverse_proxy?.stream?.buffer || {} as any, [config]);
const reverseProxyCacheConfig = useMemo<CacheConfig>(() => config?.reverse_proxy?.cache || {} as any, [config]);
const reverseProxyRateLimitConfig = useMemo<RateLimitConfig>(() => config?.reverse_proxy?.rate_limit || {} as any, [config]);
const logConfig = useMemo<LogConfig>(() => config?.log || {} as any, [config]);
const configs = useMemo(() => {
const translations: any = {
@@ -158,6 +164,7 @@ export default function MainConfigView(props: MainConfigViewProps) {
reverse_proxy_stream_fields: translateLabels(CONFIG_REVERSE_PROXY_STREAM_FIELDS, translate),
reverse_proxy_stream_buffer_fields: translateLabels(CONFIG_REVERSE_PROXY_STREAM_BUFFER_FIELDS, translate),
reverse_proxy_cache_fields: translateLabels(CONFIG_REVERSE_PROXY_CACHE_FIELDS, translate),
reverse_proxy_rate_limit_fields: translateLabels(CONFIG_REVERSE_PROXY_RATE_LIMIT_FIELDS, translate),
messaging_fields: translateLabels(CONFIG_MESSAGING_FIELDS, translate),
telegram_fields: translateLabels(CONFIG_TELEGRAM_FIELDS, translate),
rest_fields: translateLabels(CONFIG_REST_FIELDS, translate),
@@ -200,6 +207,7 @@ export default function MainConfigView(props: MainConfigViewProps) {
resource_rewrite_disabled: reverseProxyConfig.resource_rewrite_disabled,
stream: cfgReverseProxyStreamBuffer ?? undefined,
cache: reverseProxyCacheConfig ?? undefined,
rate_limit: reverseProxyRateLimitConfig ?? undefined,
};
const cfgVideo = {
@@ -234,7 +242,7 @@ export default function MainConfigView(props: MainConfigViewProps) {
}
}, [mainConfig, apiConfig, videoConfig, messagingConfig, telegramConfig, restConfig, pushoverConfig,
videoDownloadConfig, reverseProxyConfig, enqueueSnackbar, services, logConfig,
reverseProxyCacheConfig, reverseProxyStreamConfig, reverseProxyStreamBufferConfig,
reverseProxyRateLimitConfig, reverseProxyCacheConfig, reverseProxyStreamConfig, reverseProxyStreamBufferConfig,
translate]);
const handleTabChange = useCallback((tab: string) => {
@@ -277,6 +285,8 @@ export default function MainConfigView(props: MainConfigViewProps) {
fields={configs.reverse_proxy_stream_buffer_fields}></FormView>
<label className="main-config__content-form__section-title">{translate('LABEL.CACHE')}</label>
<FormView data={reverseProxyCacheConfig} fields={configs.reverse_proxy_cache_fields}></FormView>
<label className="main-config__content-form__section-title">{translate('LABEL.RATE_LIMIT')}</label>
<FormView data={reverseProxyRateLimitConfig} fields={configs.reverse_proxy_rate_limit_fields}></FormView>
</div>
<div className={'main-config__content-form' + ('messaging' !== activeTab ? ' hidden' : '')}>
<FormView data={messagingConfig} fields={configs.messaging_fields}></FormView>
+6
View File
@@ -203,9 +203,15 @@ export interface CacheConfig {
dir?: string,
}
export interface RateLimitConfig {
enabled: boolean,
period_millis: number,
burst_size: number,
}
export interface ReverseProxyConfig {
stream?: StreamConfig,
cache?: CacheConfig,
rate_limit?: RateLimitConfig,
resource_rewrite_disabled: boolean,
}
-1
View File
@@ -1193,7 +1193,6 @@ impl StreamConfig {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct RateLimitConfig {
#[serde(default)]
pub enabled: bool,
pub period_millis: u64,
pub burst_size: u32,