@vanzxy/baileys 1.5.8 → 1.5.9
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/lib/Socket/chats.js
CHANGED
|
@@ -712,21 +712,46 @@ export const makeChatsSocket = (config) => {
|
|
|
712
712
|
// has a courtesy retry via blockedCollections + the creds.update listener below — the key
|
|
713
713
|
// arrives async after connect (APP_STATE_SYNC_KEY_SHARE), so calling e.g. updateProfileName()
|
|
714
714
|
// right after connection.update === 'open' would reliably fail on a fresh/early connection.
|
|
715
|
-
// Now appPatch() waits (bounded,
|
|
715
|
+
// Now appPatch() waits (bounded, 20s default) for the same creds.update event before giving up,
|
|
716
716
|
// instead of failing hard on what's usually just a timing race.
|
|
717
|
-
|
|
717
|
+
//
|
|
718
|
+
// Vanz@Fix 25-08-26 --- the event-only wait had a blind spot: if `creds.update` never actually
|
|
719
|
+
// reaches this listener (swallowed/filtered by a wrapper around `ev`, a custom auth-state
|
|
720
|
+
// adapter that patches `authState.creds` directly without re-emitting the event, etc.) this
|
|
721
|
+
// would sit for the full timeout and fail even though `authState.creds.myAppStateKeyId` was
|
|
722
|
+
// genuinely set the whole time. Added a belt-and-suspenders poll of the creds object itself
|
|
723
|
+
// alongside the event listener — whichever one notices the key first wins, and both are torn
|
|
724
|
+
// down together so there's no leaked timer/listener either way.
|
|
725
|
+
const waitForAppStateKeyId = (timeoutMs = 20_000, pollMs = 500) => {
|
|
718
726
|
if (authState.creds.myAppStateKeyId) {
|
|
719
727
|
return Promise.resolve(authState.creds.myAppStateKeyId);
|
|
720
728
|
}
|
|
721
729
|
return new Promise((resolve, reject) => {
|
|
722
|
-
|
|
730
|
+
let settled = false;
|
|
731
|
+
const cleanup = () => {
|
|
732
|
+
settled = true;
|
|
733
|
+
clearTimeout(timeout);
|
|
734
|
+
clearInterval(poller);
|
|
723
735
|
ev.off('creds.update', onUpdate);
|
|
736
|
+
};
|
|
737
|
+
const timeout = setTimeout(() => {
|
|
738
|
+
if (settled) return;
|
|
739
|
+
cleanup();
|
|
740
|
+
logger.warn(
|
|
741
|
+
{ hasMyAppStateKeyId: !!authState.creds.myAppStateKeyId, registered: authState.creds.registered },
|
|
742
|
+
'waitForAppStateKeyId timed out — APP_STATE_SYNC_KEY_SHARE was never received/applied for this session'
|
|
743
|
+
);
|
|
724
744
|
reject(new Boom('App state key not present!', { statusCode: 400 }));
|
|
725
745
|
}, timeoutMs);
|
|
746
|
+
const poller = setInterval(() => {
|
|
747
|
+
if (settled || !authState.creds.myAppStateKeyId) return;
|
|
748
|
+
const id = authState.creds.myAppStateKeyId;
|
|
749
|
+
cleanup();
|
|
750
|
+
resolve(id);
|
|
751
|
+
}, pollMs);
|
|
726
752
|
const onUpdate = ({ myAppStateKeyId }) => {
|
|
727
|
-
if (!myAppStateKeyId) return;
|
|
728
|
-
|
|
729
|
-
ev.off('creds.update', onUpdate);
|
|
753
|
+
if (settled || !myAppStateKeyId) return;
|
|
754
|
+
cleanup();
|
|
730
755
|
resolve(myAppStateKeyId);
|
|
731
756
|
};
|
|
732
757
|
ev.on('creds.update', onUpdate);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mutex } from 'async-mutex';
|
|
2
|
-
import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises';
|
|
2
|
+
import { mkdir, readFile, readdir, stat, unlink, writeFile } from 'fs/promises';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { proto } from '../../WAProto/index.js';
|
|
5
5
|
import { initAuthCreds } from './auth-utils.js';
|
|
@@ -18,6 +18,49 @@ const getFileLock = (path) => {
|
|
|
18
18
|
}
|
|
19
19
|
return mutex;
|
|
20
20
|
};
|
|
21
|
+
// Vanz@Fix 25-08-26 (ENOSPC guard) --- useMultiFileAuthState writes one small file PER key id
|
|
22
|
+
// (session-*, sender-key-*, sender-key-memory-*, pre-key-*, app-state-sync-key-*, ...) and never
|
|
23
|
+
// prunes any of them on its own. Over months of uptime — especially in busy groups, where a
|
|
24
|
+
// sender-key-memory file is created per (group, participant) pair — this silently accumulates into
|
|
25
|
+
// hundreds of thousands of tiny files. That can hit the filesystem's inode/file-count ceiling and
|
|
26
|
+
// start throwing ENOSPC on writes long before disk *space* usage looks anywhere near full (a
|
|
27
|
+
// classic symptom: panel shows plenty of free MiB/GiB, but writes still fail with ENOSPC). When
|
|
28
|
+
// that happens mid-session, auth writes (including the app-state-sync key from the "App state key
|
|
29
|
+
// not present!" issue) fail silently and never actually persist.
|
|
30
|
+
//
|
|
31
|
+
// `sender-key-memory-*` entries are pure dedup/anti-replay cache — safe to delete anytime; Baileys
|
|
32
|
+
// regenerates them on demand with zero functional loss (worst case: one redundant re-decrypt). They
|
|
33
|
+
// also tend to be the single biggest contributor to file count in active groups, so they're the
|
|
34
|
+
// safest and highest-impact thing to prune automatically. Everything else (creds, real sessions,
|
|
35
|
+
// pre-keys, app-state-sync-keys) is left completely untouched — this never touches those.
|
|
36
|
+
export const pruneStaleAuthFiles = async (folder, { maxAgeDays = 14, categories = ['sender-key-memory'], dryRun = false } = {}) => {
|
|
37
|
+
let entries;
|
|
38
|
+
try {
|
|
39
|
+
entries = await readdir(folder);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return { scanned: 0, removed: 0 };
|
|
43
|
+
}
|
|
44
|
+
const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1000;
|
|
45
|
+
let scanned = 0;
|
|
46
|
+
let removed = 0;
|
|
47
|
+
await Promise.all(entries.map(async (name) => {
|
|
48
|
+
if (!categories.some((cat) => name.startsWith(`${cat}-`) && name.endsWith('.json'))) return;
|
|
49
|
+
scanned++;
|
|
50
|
+
const filePath = join(folder, name);
|
|
51
|
+
try {
|
|
52
|
+
const info = await stat(filePath);
|
|
53
|
+
if (info.mtimeMs < cutoff) {
|
|
54
|
+
if (!dryRun) await unlink(filePath).catch(() => { });
|
|
55
|
+
removed++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// file vanished between readdir and stat — fine, nothing to prune
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
return { scanned, removed };
|
|
63
|
+
};
|
|
21
64
|
/**
|
|
22
65
|
* stores the full authentication state in a single folder.
|
|
23
66
|
* Far more efficient than singlefileauthstate
|
|
@@ -83,6 +126,9 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
83
126
|
else {
|
|
84
127
|
await mkdir(folder, { recursive: true });
|
|
85
128
|
}
|
|
129
|
+
// Vanz@Fix 25-08-26 (ENOSPC guard) --- best-effort prune on every startup. Failures here must
|
|
130
|
+
// never block auth from loading, so this is intentionally fire-and-forget with its own catch.
|
|
131
|
+
pruneStaleAuthFiles(folder).catch(() => { });
|
|
86
132
|
const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
87
133
|
const creds = (await readData('creds.json')) || initAuthCreds();
|
|
88
134
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanzxy/baileys",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
4
4
|
"description": "Enhanced Baileys fork by Vanzxy — based on @itsliaaa/baileys + @whiskeysockets/baileys with fixes for audio group status and clean media without newsletter button.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./lib/index.js",
|