mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Fix status@broadcast file name (#1696)
user-multi-file-auth-state fails to write/read status@broadcast files because they have a colon. To fix it, we replaced the colon with a dash. This might solve the issues below https://github.com/adiwajshing/Baileys/issues/1589#issue-1229804957 https://github.com/adiwajshing/Baileys/issues/1693#issue-1260676356
This commit is contained in:
@@ -15,12 +15,12 @@ import { BufferJSON } from './generics'
|
|||||||
export const useMultiFileAuthState = async(folder: string): Promise<{ state: AuthenticationState, saveCreds: () => Promise<void> }> => {
|
export const useMultiFileAuthState = async(folder: string): Promise<{ state: AuthenticationState, saveCreds: () => Promise<void> }> => {
|
||||||
|
|
||||||
const writeData = (data: any, file: string) => {
|
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) => {
|
const readData = async(file: string) => {
|
||||||
try {
|
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)
|
return JSON.parse(data, BufferJSON.reviver)
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
return null
|
return null
|
||||||
@@ -29,7 +29,7 @@ export const useMultiFileAuthState = async(folder: string): Promise<{ state: Aut
|
|||||||
|
|
||||||
const removeData = async(file: string) => {
|
const removeData = async(file: string) => {
|
||||||
try {
|
try {
|
||||||
await unlink(file)
|
await unlink(fixFileName(file))
|
||||||
} catch{
|
} catch{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,15 @@ export const useMultiFileAuthState = async(folder: string): Promise<{ state: Aut
|
|||||||
await mkdir(folder, { recursive: true })
|
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()
|
const creds: AuthenticationCreds = await readData('creds.json') || initAuthCreds()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user