From a52a6874931b91d218e2ea4992f40c97681c83b7 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 12 Jul 2024 14:15:16 -0300 Subject: [PATCH] chore: Remove unused fileExists function in use-multi-file-auth-state-prisma.ts Explanation: This commit removes an unused `fileExists` function from the `use-multi-file-auth-state-prisma.ts` file. This change simplifies the code and reduces the potential for confusion or maintenance issues in the future. The previously implemented `fileExists` function was commented out and not used in any other part of the file, so it was safe to remove. This change does not affect the functionality of the module and is a pure code improvement. Affected files: - `src/utils/use-multi-file-auth-state-prisma.ts` --- src/utils/use-multi-file-auth-state-prisma.ts | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/utils/use-multi-file-auth-state-prisma.ts b/src/utils/use-multi-file-auth-state-prisma.ts index b8af060b..8790b3a5 100644 --- a/src/utils/use-multi-file-auth-state-prisma.ts +++ b/src/utils/use-multi-file-auth-state-prisma.ts @@ -8,21 +8,20 @@ import { prismaServer } from '../libs/prisma.connect'; const prisma = prismaServer; -const fixFileName = (file: string): string | undefined => { - if (!file) { - return undefined; - } - const replacedSlash = file.replace(/\//g, '__'); - const replacedColon = replacedSlash.replace(/:/g, '-'); - return replacedColon; -}; +// const fixFileName = (file: string): string | undefined => { +// if (!file) { +// return undefined; +// } +// const replacedSlash = file.replace(/\//g, '__'); +// const replacedColon = replacedSlash.replace(/:/g, '-'); +// return replacedColon; +// }; export async function keyExists(sessionId: string): Promise { try { const key = await prisma.session.findUnique({ where: { sessionId: sessionId } }); return !!key; } catch (error) { - console.log(`${error}`); return false; } } @@ -42,7 +41,6 @@ export async function saveKey(sessionId: string, keyJson: any): Promise { data: { creds: JSON.stringify(keyJson) }, }); } catch (error) { - console.log(`${error}`); return null; } } @@ -54,7 +52,6 @@ export async function getAuthKey(sessionId: string): Promise { const auth = await prisma.session.findUnique({ where: { sessionId: sessionId } }); return JSON.parse(auth?.creds); } catch (error) { - console.log(`${error}`); return null; } } @@ -64,20 +61,20 @@ async function deleteAuthKey(sessionId: string): Promise { const register = await keyExists(sessionId); if (!register) return; await prisma.session.delete({ where: { sessionId: sessionId } }); - } catch (error) { - console.log('2', `${error}`); - } -} - -async function fileExists(file: string): Promise { - try { - const stat = await fs.stat(file); - if (stat.isFile()) return true; } catch (error) { return; } } +// async function fileExists(file: string): Promise { +// try { +// const stat = await fs.stat(file); +// if (stat.isFile()) return true; +// } catch (error) { +// return; +// } +// } + export default async function useMultiFileAuthStatePrisma( sessionId: string, cache: CacheService, @@ -86,7 +83,7 @@ export default async function useMultiFileAuthStatePrisma( saveCreds: () => Promise; }> { const localFolder = path.join(INSTANCE_DIR, sessionId); - const localFile = (key: string) => path.join(localFolder, fixFileName(key) + '.json'); + // const localFile = (key: string) => path.join(localFolder, fixFileName(key) + '.json'); await fs.mkdir(localFolder, { recursive: true }); async function writeData(data: any, key: string): Promise {