mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
nettoyage du code
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
export const BOT_CONTROL_QUEUE = "bot-control";
|
||||
export const BOT_CONTROL_QUEUE_PREFIX = "discord-saas";
|
||||
|
||||
export const BOT_STATUS = ["stopped", "starting", "running", "stopping", "error"] as const;
|
||||
export const BOT_STATUS = [
|
||||
"stopped",
|
||||
"starting",
|
||||
"running",
|
||||
"stopping",
|
||||
"error",
|
||||
] as const;
|
||||
export type BotStatus = (typeof BOT_STATUS)[number];
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
const sanitizeSegment = (segment: string): string => segment.replace(/[^a-zA-Z0-9:_-]/g, "_");
|
||||
const sanitizeSegment = (segment: string): string =>
|
||||
segment.replace(/[^a-zA-Z0-9:_-]/g, "_");
|
||||
|
||||
export const tenantRedisKey = (tenantId: string, ...parts: string[]): string => {
|
||||
export const tenantRedisKey = (
|
||||
tenantId: string,
|
||||
...parts: string[]
|
||||
): string => {
|
||||
const tail = parts.map(sanitizeSegment).join(":");
|
||||
return tail.length > 0
|
||||
? `tenant:${sanitizeSegment(tenantId)}:${tail}`
|
||||
@@ -11,6 +15,10 @@ export const tenantRateLimitKey = (tenantId: string, scope: string): string => {
|
||||
return tenantRedisKey(tenantId, "ratelimit", scope);
|
||||
};
|
||||
|
||||
export const tenantBotRedisKey = (tenantId: string, botId: string, ...parts: string[]): string => {
|
||||
export const tenantBotRedisKey = (
|
||||
tenantId: string,
|
||||
botId: string,
|
||||
...parts: string[]
|
||||
): string => {
|
||||
return tenantRedisKey(tenantId, "bot", botId, ...parts);
|
||||
};
|
||||
|
||||
@@ -18,11 +18,17 @@ export const parseTokenEncryptionKey = (base64Key: string): Buffer => {
|
||||
return key;
|
||||
};
|
||||
|
||||
export const encryptToken = (plainToken: string, key: Buffer): EncryptedToken => {
|
||||
export const encryptToken = (
|
||||
plainToken: string,
|
||||
key: Buffer,
|
||||
): EncryptedToken => {
|
||||
const iv = randomBytes(IV_LENGTH);
|
||||
const cipher = createCipheriv(ALGORITHM, key, iv);
|
||||
|
||||
const ciphertext = Buffer.concat([cipher.update(plainToken, "utf8"), cipher.final()]);
|
||||
const ciphertext = Buffer.concat([
|
||||
cipher.update(plainToken, "utf8"),
|
||||
cipher.final(),
|
||||
]);
|
||||
const tag = cipher.getAuthTag();
|
||||
|
||||
return {
|
||||
@@ -32,8 +38,15 @@ export const encryptToken = (plainToken: string, key: Buffer): EncryptedToken =>
|
||||
};
|
||||
};
|
||||
|
||||
export const decryptToken = (encryptedToken: EncryptedToken, key: Buffer): string => {
|
||||
const decipher = createDecipheriv(ALGORITHM, key, Buffer.from(encryptedToken.iv, "base64"));
|
||||
export const decryptToken = (
|
||||
encryptedToken: EncryptedToken,
|
||||
key: Buffer,
|
||||
): string => {
|
||||
const decipher = createDecipheriv(
|
||||
ALGORITHM,
|
||||
key,
|
||||
Buffer.from(encryptedToken.iv, "base64"),
|
||||
);
|
||||
decipher.setAuthTag(Buffer.from(encryptedToken.tag, "base64"));
|
||||
|
||||
const decrypted = Buffer.concat([
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
"outDir": "dist",
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user