Skip to content

Commit

Permalink
chore: Remove unused fileExists function in use-multi-file-auth-state…
Browse files Browse the repository at this point in the history
…-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`
  • Loading branch information
dgcode-tec committed Jul 12, 2024
1 parent 634ee9b commit a52a687
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/utils/use-multi-file-auth-state-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
try {
const key = await prisma.session.findUnique({ where: { sessionId: sessionId } });
return !!key;
} catch (error) {
console.log(`${error}`);
return false;
}
}
Expand All @@ -42,7 +41,6 @@ export async function saveKey(sessionId: string, keyJson: any): Promise<any> {
data: { creds: JSON.stringify(keyJson) },
});
} catch (error) {
console.log(`${error}`);
return null;
}
}
Expand All @@ -54,7 +52,6 @@ export async function getAuthKey(sessionId: string): Promise<any> {
const auth = await prisma.session.findUnique({ where: { sessionId: sessionId } });
return JSON.parse(auth?.creds);
} catch (error) {
console.log(`${error}`);
return null;
}
}
Expand All @@ -64,20 +61,20 @@ async function deleteAuthKey(sessionId: string): Promise<any> {
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<any> {
try {
const stat = await fs.stat(file);
if (stat.isFile()) return true;
} catch (error) {
return;
}
}

// async function fileExists(file: string): Promise<any> {
// try {
// const stat = await fs.stat(file);
// if (stat.isFile()) return true;
// } catch (error) {
// return;
// }
// }

export default async function useMultiFileAuthStatePrisma(
sessionId: string,
cache: CacheService,
Expand All @@ -86,7 +83,7 @@ export default async function useMultiFileAuthStatePrisma(
saveCreds: () => Promise<void>;
}> {
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<any> {
Expand Down

0 comments on commit a52a687

Please sign in to comment.