Skip to content

Commit 39c3770

Browse files
committed
Refactor config command to utilize exported parsing functions
1 parent 5b0e340 commit 39c3770

File tree

2 files changed

+7
-30
lines changed

2 files changed

+7
-30
lines changed

src/commands/config.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseCommand } from "./base.js";
22
import { CommandContext } from "../types/index.js";
3-
import config from "../config.js";
3+
import config, { parseBoolean, parseVideoCodec, parsePreset } from "../config.js";
44
import logger from "../utils/logger.js";
55

66
export default class ConfigCommand extends BaseCommand {
@@ -83,7 +83,7 @@ export default class ConfigCommand extends BaseCommand {
8383
case 'respect_video_params':
8484
case 'hardwareacceleration':
8585
case 'hardwareaccelerateddecoding':
86-
const boolValue = this.parseBoolean(value);
86+
const boolValue = parseBoolean(value);
8787
if (param === 'hardwareacceleration' || param === 'hardwareaccelerateddecoding') {
8888
config.hardwareAcceleratedDecoding = boolValue;
8989
await this.sendSuccess(context.message, `Set hardwareAcceleratedDecoding to \`${boolValue}\``);
@@ -112,7 +112,7 @@ export default class ConfigCommand extends BaseCommand {
112112

113113
// Video codec
114114
case 'videocodec':
115-
const codec = this.parseVideoCodec(value);
115+
const codec = parseVideoCodec(value);
116116
if (!codec) {
117117
await this.sendError(context.message, `Invalid video codec. Valid options: VP8, H264, H265`);
118118
return;
@@ -125,7 +125,7 @@ export default class ConfigCommand extends BaseCommand {
125125
// H26x preset
126126
case 'h26xpreset':
127127
case 'preset':
128-
const preset = this.parsePreset(value);
128+
const preset = parsePreset(value);
129129
if (!preset) {
130130
await this.sendError(context.message, `Invalid preset. Valid options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow`);
131131
return;
@@ -171,29 +171,6 @@ export default class ConfigCommand extends BaseCommand {
171171
];
172172
}
173173

174-
private parseBoolean(value: string): boolean {
175-
const val = value.trim().toLowerCase();
176-
return val === 'true' || val === '1' || val === 'yes' || val === 'on';
177-
}
178-
179-
private parseVideoCodec(value: string): "VP8" | "H264" | "H265" | null {
180-
const VALID_VIDEO_CODECS = ['VP8', 'H264', 'H265'];
181-
const codec = value.trim().toUpperCase();
182-
if (VALID_VIDEO_CODECS.includes(codec)) {
183-
return codec as "VP8" | "H264" | "H265";
184-
}
185-
return null;
186-
}
187-
188-
private parsePreset(value: string): "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" | null {
189-
const VALID_PRESETS = ["ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"];
190-
const preset = value.trim().toLowerCase();
191-
if (VALID_PRESETS.includes(preset)) {
192-
return preset as "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow";
193-
}
194-
return null;
195-
}
196-
197174
private isAdmin(userId: string): boolean {
198175
// If no admins configured, allow all users (backwards compatibility)
199176
if (!config.adminIds || config.adminIds.length === 0) {

src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dotenv.config({ quiet: true });
55

66
const VALID_VIDEO_CODECS = ['VP8', 'H264', 'H265', 'VP9', 'AV1'];
77

8-
function parseVideoCodec(value: string): "VP8" | "H264" | "H265" {
8+
export function parseVideoCodec(value: string): "VP8" | "H264" | "H265" {
99
if (typeof value === "string") {
1010
value = value.trim().toUpperCase();
1111
}
@@ -15,7 +15,7 @@ function parseVideoCodec(value: string): "VP8" | "H264" | "H265" {
1515
return "H264";
1616
}
1717

18-
function parsePreset(value: string): "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" {
18+
export function parsePreset(value: string): "ultrafast" | "superfast" | "veryfast" | "faster" | "fast" | "medium" | "slow" | "slower" | "veryslow" {
1919
if (typeof value === "string") {
2020
value = value.trim().toLowerCase();
2121
}
@@ -35,7 +35,7 @@ function parsePreset(value: string): "ultrafast" | "superfast" | "veryfast" | "f
3535
}
3636
}
3737

38-
function parseBoolean(value: string | undefined): boolean {
38+
export function parseBoolean(value: string | undefined): boolean {
3939
if (typeof value === "string") {
4040
value = value.trim().toLowerCase();
4141
}

0 commit comments

Comments
 (0)