@itsliaaa/baileys 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,16 +3,10 @@ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
4
|
import { initAuthCreds } from './auth-utils.js';
|
|
5
5
|
import { BufferJSON } from './generics.js';
|
|
6
|
-
import NodeCache from '@cacheable/node-cache';
|
|
7
6
|
// Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
|
|
8
|
-
const FLUSH_TIMEOUT_MS =
|
|
9
|
-
export const useSingleFileAuthState = async (fileName
|
|
10
|
-
const cache =
|
|
11
|
-
new NodeCache({
|
|
12
|
-
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
13
|
-
useClones: false,
|
|
14
|
-
deleteOnExpire: true
|
|
15
|
-
});
|
|
7
|
+
const FLUSH_TIMEOUT_MS = 3000
|
|
8
|
+
export const useSingleFileAuthState = async (fileName) => {
|
|
9
|
+
const cache = new Map();
|
|
16
10
|
let isLoaded,
|
|
17
11
|
isWriting,
|
|
18
12
|
isNeedWrite,
|
|
@@ -46,7 +40,7 @@ export const useSingleFileAuthState = async (fileName, _cache) => {
|
|
|
46
40
|
do {
|
|
47
41
|
isNeedWrite = false;
|
|
48
42
|
const tempFile = fileName + '.temp';
|
|
49
|
-
const value =
|
|
43
|
+
const value = Object.fromEntries(cache);
|
|
50
44
|
await writeFile(tempFile, JSON.stringify(value, BufferJSON.replacer));
|
|
51
45
|
await rename(tempFile, fileName);
|
|
52
46
|
}
|
|
@@ -59,7 +53,7 @@ export const useSingleFileAuthState = async (fileName, _cache) => {
|
|
|
59
53
|
flushKey();
|
|
60
54
|
};
|
|
61
55
|
const removeKey = (keyName) => {
|
|
62
|
-
cache.
|
|
56
|
+
cache.delete(keyName);
|
|
63
57
|
flushKey();
|
|
64
58
|
};
|
|
65
59
|
const fileInfo = await stat(fileName).catch(() => null);
|
|
@@ -91,15 +85,11 @@ export const useSingleFileAuthState = async (fileName, _cache) => {
|
|
|
91
85
|
for (const id in data[category]) {
|
|
92
86
|
const keyName = category + '-' + id;
|
|
93
87
|
const value = data[category][id];
|
|
94
|
-
|
|
95
|
-
writeKey(keyName, value);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
removeKey(keyName);
|
|
99
|
-
}
|
|
88
|
+
value ? writeKey(keyName, value) : removeKey(keyName)
|
|
100
89
|
}
|
|
101
90
|
}
|
|
102
|
-
}
|
|
91
|
+
},
|
|
92
|
+
clear: () => cache.clear()
|
|
103
93
|
}
|
|
104
94
|
},
|
|
105
95
|
saveCreds: () => writeKey('creds', creds)
|