mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: remove data in multifileauthstate too
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { mkdir, readFile, stat, writeFile } from 'fs/promises'
|
import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { AuthenticationCreds, AuthenticationState, SignalDataTypeMap } from '../Types'
|
import { AuthenticationCreds, AuthenticationState, SignalDataTypeMap } from '../Types'
|
||||||
@@ -27,6 +27,14 @@ export const useMultiFileAuthState = async(folder: string): Promise<{ state: Aut
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const removeData = async(file: string) => {
|
||||||
|
try {
|
||||||
|
await unlink(file)
|
||||||
|
} catch{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const folderInfo = await stat(folder).catch(() => { })
|
const folderInfo = await stat(folder).catch(() => { })
|
||||||
if(folderInfo) {
|
if(folderInfo) {
|
||||||
if(!folderInfo.isDirectory()) {
|
if(!folderInfo.isDirectory()) {
|
||||||
@@ -63,7 +71,9 @@ export const useMultiFileAuthState = async(folder: string): Promise<{ state: Aut
|
|||||||
const tasks: Promise<void>[] = []
|
const tasks: Promise<void>[] = []
|
||||||
for(const category in data) {
|
for(const category in data) {
|
||||||
for(const id in data[category]) {
|
for(const id in data[category]) {
|
||||||
tasks.push(writeData(data[category][id], `${category}-${id}.json`))
|
const value = data[category][id]
|
||||||
|
const file = `${category}-${id}.json`
|
||||||
|
tasks.push(value ? writeData(value, file) : removeData(file))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user