feat: limit logs timestamp_format length
This commit is contained in:
parent
c82e147ea1
commit
fafaefa1fb
3 changed files with 23 additions and 4 deletions
|
@ -110,6 +110,7 @@ import { logVoiceChannelForceMove } from "./logFunctions/logVoiceChannelForceMov
|
|||
import { logVoiceChannelJoin } from "./logFunctions/logVoiceChannelJoin";
|
||||
import { logVoiceChannelLeave } from "./logFunctions/logVoiceChannelLeave";
|
||||
import { logVoiceChannelMove } from "./logFunctions/logVoiceChannelMove";
|
||||
import { asBoundedString } from "../../utils/iotsUtils";
|
||||
|
||||
// The `any` cast here is to prevent TypeScript from locking up from the circular dependency
|
||||
function getCasesPlugin(): Promise<any> {
|
||||
|
@ -120,12 +121,12 @@ const defaultOptions: PluginOptions<LogsPluginType> = {
|
|||
config: {
|
||||
channels: {},
|
||||
format: {
|
||||
timestamp: FORMAT_NO_TIMESTAMP, // Legacy/deprecated, use timestamp_format below instead
|
||||
timestamp: asBoundedString(FORMAT_NO_TIMESTAMP), // Legacy/deprecated, use timestamp_format below instead
|
||||
...DefaultLogMessages,
|
||||
},
|
||||
ping_user: true, // Legacy/deprecated, if below is false mentions wont actually ping. In case you really want the old behavior, set below to true
|
||||
allow_user_mentions: false,
|
||||
timestamp_format: "[<t:]X[>]",
|
||||
timestamp_format: asBoundedString("[<t:]X[>]"),
|
||||
include_embed_timestamp: true,
|
||||
},
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
TemplateSafeUser,
|
||||
} from "../../utils/templateSafeObjects";
|
||||
import { TRegex } from "../../validatorUtils";
|
||||
import { tBoundedString } from "../../utils/iotsUtils";
|
||||
|
||||
export const tLogFormats = t.record(t.string, t.union([t.string, tMessageContent]));
|
||||
export type TLogFormats = t.TypeOf<typeof tLogFormats>;
|
||||
|
@ -53,12 +54,12 @@ export const ConfigSchema = t.type({
|
|||
format: t.intersection([
|
||||
tLogFormats,
|
||||
t.type({
|
||||
timestamp: t.string, // Legacy/deprecated
|
||||
timestamp: tBoundedString(0, 64), // Legacy/deprecated
|
||||
}),
|
||||
]),
|
||||
ping_user: t.boolean, // Legacy/deprecated, if below is false mentions wont actually ping
|
||||
allow_user_mentions: t.boolean,
|
||||
timestamp_format: t.string,
|
||||
timestamp_format: tBoundedString(0, 64),
|
||||
include_embed_timestamp: t.boolean,
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
|
17
backend/src/utils/iotsUtils.ts
Normal file
17
backend/src/utils/iotsUtils.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import * as t from "io-ts";
|
||||
|
||||
interface BoundedStringBrand {
|
||||
readonly BoundedString: unique symbol;
|
||||
}
|
||||
|
||||
export function asBoundedString(str: string) {
|
||||
return str as t.Branded<string, BoundedStringBrand>;
|
||||
}
|
||||
|
||||
export function tBoundedString(min: number, max: number) {
|
||||
return t.brand(
|
||||
t.string,
|
||||
(str): str is t.Branded<string, BoundedStringBrand> => (str.length >= min && str.length <= max),
|
||||
"BoundedString",
|
||||
);
|
||||
}
|
Loading…
Add table
Reference in a new issue