diff --git a/src/Utils/use-multi-file-auth-state.ts b/src/Utils/use-multi-file-auth-state.ts index 127d8dc..1776165 100644 --- a/src/Utils/use-multi-file-auth-state.ts +++ b/src/Utils/use-multi-file-auth-state.ts @@ -15,12 +15,12 @@ import { BufferJSON } from './generics' export const useMultiFileAuthState = async(folder: string): Promise<{ state: AuthenticationState, saveCreds: () => Promise }> => { const writeData = (data: any, file: string) => { - return writeFile(join(folder, file), JSON.stringify(data, BufferJSON.replacer)) + return writeFile(join(folder, fixFileName(file)), JSON.stringify(data, BufferJSON.replacer)) } const readData = async(file: string) => { try { - const data = await readFile(join(folder, file), { encoding: 'utf-8' }) + const data = await readFile(join(folder, fixFileName(file)), { encoding: 'utf-8' }) return JSON.parse(data, BufferJSON.reviver) } catch(error) { return null @@ -29,7 +29,7 @@ export const useMultiFileAuthState = async(folder: string): Promise<{ state: Aut const removeData = async(file: string) => { try { - await unlink(file) + await unlink(fixFileName(file)) } catch{ } @@ -44,6 +44,15 @@ export const useMultiFileAuthState = async(folder: string): Promise<{ state: Aut await mkdir(folder, { recursive: true }) } + const fixFileName = (file) =>{ + if(file){ + return file.replace(/:/g, '-'); + } + else { + return file + } + } + const creds: AuthenticationCreds = await readData('creds.json') || initAuthCreds() return {