@itsliaaa/baileys 0.1.13 → 0.1.14
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.
- package/README.md +1 -1
- package/WAProto/index.js +11 -21
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/use-single-file-auth-state.js +107 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/WAProto/index.js
CHANGED
|
@@ -92815,7 +92815,7 @@ export const proto = $root.proto = (() => {
|
|
|
92815
92815
|
this[ks[i]] = p[ks[i]];
|
|
92816
92816
|
}
|
|
92817
92817
|
|
|
92818
|
-
CustomList.prototype.
|
|
92818
|
+
CustomList.prototype.listId = null;
|
|
92819
92819
|
CustomList.prototype.name = null;
|
|
92820
92820
|
CustomList.prototype.emoji = null;
|
|
92821
92821
|
CustomList.prototype.isSelected = null;
|
|
@@ -92823,8 +92823,8 @@ export const proto = $root.proto = (() => {
|
|
|
92823
92823
|
|
|
92824
92824
|
let $oneOfFields;
|
|
92825
92825
|
|
|
92826
|
-
Object.defineProperty(CustomList.prototype, "
|
|
92827
|
-
get: $util.oneOfGetter($oneOfFields = ["
|
|
92826
|
+
Object.defineProperty(CustomList.prototype, "_listId", {
|
|
92827
|
+
get: $util.oneOfGetter($oneOfFields = ["listId"]),
|
|
92828
92828
|
set: $util.oneOfSetter($oneOfFields)
|
|
92829
92829
|
});
|
|
92830
92830
|
|
|
@@ -92850,8 +92850,8 @@ export const proto = $root.proto = (() => {
|
|
|
92850
92850
|
CustomList.encode = function encode(m, w) {
|
|
92851
92851
|
if (!w)
|
|
92852
92852
|
w = $Writer.create();
|
|
92853
|
-
if (m.
|
|
92854
|
-
w.uint32(
|
|
92853
|
+
if (m.listId != null && Object.hasOwnProperty.call(m, "listId"))
|
|
92854
|
+
w.uint32(10).string(m.listId);
|
|
92855
92855
|
if (m.name != null && Object.hasOwnProperty.call(m, "name"))
|
|
92856
92856
|
w.uint32(18).string(m.name);
|
|
92857
92857
|
if (m.emoji != null && Object.hasOwnProperty.call(m, "emoji"))
|
|
@@ -92875,7 +92875,7 @@ export const proto = $root.proto = (() => {
|
|
|
92875
92875
|
break;
|
|
92876
92876
|
switch (t >>> 3) {
|
|
92877
92877
|
case 1: {
|
|
92878
|
-
m.
|
|
92878
|
+
m.listId = r.string();
|
|
92879
92879
|
break;
|
|
92880
92880
|
}
|
|
92881
92881
|
case 2: {
|
|
@@ -92908,15 +92908,8 @@ export const proto = $root.proto = (() => {
|
|
|
92908
92908
|
if (d instanceof $root.proto.SyncActionValue.StatusPrivacyAction.CustomList)
|
|
92909
92909
|
return d;
|
|
92910
92910
|
var m = new $root.proto.SyncActionValue.StatusPrivacyAction.CustomList();
|
|
92911
|
-
if (d.
|
|
92912
|
-
|
|
92913
|
-
(m.id = $util.Long.fromValue(d.id)).unsigned = false;
|
|
92914
|
-
else if (typeof d.id === "string")
|
|
92915
|
-
m.id = parseInt(d.id, 10);
|
|
92916
|
-
else if (typeof d.id === "number")
|
|
92917
|
-
m.id = d.id;
|
|
92918
|
-
else if (typeof d.id === "object")
|
|
92919
|
-
m.id = new $util.LongBits(d.id.low >>> 0, d.id.high >>> 0).toNumber();
|
|
92911
|
+
if (d.listId != null) {
|
|
92912
|
+
m.listId = String(d.listId);
|
|
92920
92913
|
}
|
|
92921
92914
|
if (d.name != null) {
|
|
92922
92915
|
m.name = String(d.name);
|
|
@@ -92945,13 +92938,10 @@ export const proto = $root.proto = (() => {
|
|
|
92945
92938
|
if (o.arrays || o.defaults) {
|
|
92946
92939
|
d.userJid = [];
|
|
92947
92940
|
}
|
|
92948
|
-
if (m.
|
|
92949
|
-
|
|
92950
|
-
d.id = o.longs === String ? String(m.id) : m.id;
|
|
92951
|
-
else
|
|
92952
|
-
d.id = o.longs === String ? longToString(m.id) : o.longs === Number ? longToNumber(m.id) : m.id;
|
|
92941
|
+
if (m.listId != null && m.hasOwnProperty("listId")) {
|
|
92942
|
+
d.listId = m.listId;
|
|
92953
92943
|
if (o.oneofs)
|
|
92954
|
-
d.
|
|
92944
|
+
d._listId = "listId";
|
|
92955
92945
|
}
|
|
92956
92946
|
if (m.name != null && m.hasOwnProperty("name")) {
|
|
92957
92947
|
d.name = m.name;
|
package/lib/Utils/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './chat-utils.js';
|
|
|
11
11
|
export * from './lt-hash.js';
|
|
12
12
|
export * from './auth-utils.js';
|
|
13
13
|
export * from './use-multi-file-auth-state.js';
|
|
14
|
+
export * from './use-single-file-auth-state.js';
|
|
14
15
|
export * from './link-preview.js';
|
|
15
16
|
export * from './event-buffer.js';
|
|
16
17
|
export * from './process-message.js';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { readFile, rename, stat, writeFile } from 'fs/promises';
|
|
2
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { initAuthCreds } from './auth-utils.js';
|
|
5
|
+
import { BufferJSON } from './generics.js';
|
|
6
|
+
import NodeCache from '@cacheable/node-cache';
|
|
7
|
+
// Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
|
|
8
|
+
const FLUSH_TIMEOUT_MS = 25
|
|
9
|
+
export const useSingleFileAuthState = async (fileName, _cache) => {
|
|
10
|
+
const cache = _cache ||
|
|
11
|
+
new NodeCache({
|
|
12
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
13
|
+
useClones: false,
|
|
14
|
+
deleteOnExpire: true
|
|
15
|
+
});
|
|
16
|
+
let isLoaded,
|
|
17
|
+
isWriting,
|
|
18
|
+
isNeedWrite,
|
|
19
|
+
flushTimeout,
|
|
20
|
+
loadPromise;
|
|
21
|
+
const loadKey = () => {
|
|
22
|
+
if (isLoaded) return;
|
|
23
|
+
if (loadPromise) return loadPromise;
|
|
24
|
+
loadPromise = (async () => {
|
|
25
|
+
try {
|
|
26
|
+
const data = JSON.parse(await readFile(fileName, 'utf-8'), BufferJSON.reviver);
|
|
27
|
+
for (const [keyName, value] of Object.entries(data)) {
|
|
28
|
+
cache.set(keyName, value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch { }
|
|
32
|
+
isLoaded = true;
|
|
33
|
+
loadPromise = null;
|
|
34
|
+
})();
|
|
35
|
+
return loadPromise;
|
|
36
|
+
};
|
|
37
|
+
const flushKey = () => {
|
|
38
|
+
if (flushTimeout) return;
|
|
39
|
+
flushTimeout = setTimeout(async () => {
|
|
40
|
+
flushTimeout = null;
|
|
41
|
+
if (isWriting) {
|
|
42
|
+
isNeedWrite = true;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
isWriting = true;
|
|
46
|
+
do {
|
|
47
|
+
isNeedWrite = false;
|
|
48
|
+
const tempFile = fileName + '.temp';
|
|
49
|
+
const value = cache.mget(cache.keys());
|
|
50
|
+
await writeFile(tempFile, JSON.stringify(value, BufferJSON.replacer));
|
|
51
|
+
await rename(tempFile, fileName);
|
|
52
|
+
}
|
|
53
|
+
while (isNeedWrite);
|
|
54
|
+
isWriting = false;
|
|
55
|
+
}, FLUSH_TIMEOUT_MS);
|
|
56
|
+
};
|
|
57
|
+
const writeKey = (keyName, value) => {
|
|
58
|
+
cache.set(keyName, value);
|
|
59
|
+
flushKey();
|
|
60
|
+
};
|
|
61
|
+
const removeKey = (keyName) => {
|
|
62
|
+
cache.del(keyName);
|
|
63
|
+
flushKey();
|
|
64
|
+
};
|
|
65
|
+
const fileInfo = await stat(fileName).catch(() => null);
|
|
66
|
+
if (!fileInfo) {
|
|
67
|
+
await writeFile(fileName, '{}');
|
|
68
|
+
}
|
|
69
|
+
else if (!fileInfo.isFile()) {
|
|
70
|
+
throw new Error(`found something that is not a file at ${fileName}, either delete it or specify a different location`);
|
|
71
|
+
}
|
|
72
|
+
await loadKey();
|
|
73
|
+
const creds = cache.get('creds') || initAuthCreds();
|
|
74
|
+
return {
|
|
75
|
+
state: {
|
|
76
|
+
creds,
|
|
77
|
+
keys: {
|
|
78
|
+
get: (type, ids) => {
|
|
79
|
+
const data = {};
|
|
80
|
+
for (const id of ids) {
|
|
81
|
+
let value = cache.get(type + '-' + id);
|
|
82
|
+
if (type === 'app-state-sync-key' && value) {
|
|
83
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
84
|
+
}
|
|
85
|
+
data[id] = value;
|
|
86
|
+
}
|
|
87
|
+
return data;
|
|
88
|
+
},
|
|
89
|
+
set: (data) => {
|
|
90
|
+
for (const category in data) {
|
|
91
|
+
for (const id in data[category]) {
|
|
92
|
+
const keyName = category + '-' + id;
|
|
93
|
+
const value = data[category][id];
|
|
94
|
+
if (value) {
|
|
95
|
+
writeKey(keyName, value);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
removeKey(keyName);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
saveCreds: () => writeKey('creds', creds)
|
|
106
|
+
};
|
|
107
|
+
};
|