@lazyneoaz/metachat 6.0.3 → 6.0.4
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/dist/index.cjs +25 -2
- package/dist/index.mjs +25 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -90205,10 +90205,24 @@ function collectTracks(payload) {
|
|
|
90205
90205
|
}
|
|
90206
90206
|
|
|
90207
90207
|
// src/deltas/apis/music/searchMusic.ts
|
|
90208
|
+
var MUSIC_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
90208
90209
|
function nextRequestId(ctx) {
|
|
90209
90210
|
ctx.__reqCounter = (typeof ctx.__reqCounter === "number" ? ctx.__reqCounter : 0) + 1;
|
|
90210
90211
|
return ctx.__reqCounter.toString(36);
|
|
90211
90212
|
}
|
|
90213
|
+
var MUSIC_MIN_INTERVAL_MS = 1100;
|
|
90214
|
+
async function paceMusic(ctx) {
|
|
90215
|
+
const configured = Number(ctx?.globalOptions?.musicMinIntervalMs);
|
|
90216
|
+
const min = Number.isFinite(configured) && configured >= 0 ? configured : MUSIC_MIN_INTERVAL_MS;
|
|
90217
|
+
const last2 = typeof ctx.__musicLastCallAt === "number" ? ctx.__musicLastCallAt : 0;
|
|
90218
|
+
const wait = last2 + min - Date.now();
|
|
90219
|
+
if (wait > 0) await sleep(wait);
|
|
90220
|
+
ctx.__musicLastCallAt = Date.now();
|
|
90221
|
+
}
|
|
90222
|
+
function cacheResult(ctx, key, result) {
|
|
90223
|
+
const cache = ctx.__musicCache || (ctx.__musicCache = {});
|
|
90224
|
+
cache[key] = { at: Date.now(), result };
|
|
90225
|
+
}
|
|
90212
90226
|
function normalizeError(error2) {
|
|
90213
90227
|
if (!error2 || typeof error2 !== "object") {
|
|
90214
90228
|
const message2 = String(error2);
|
|
@@ -90230,6 +90244,13 @@ function normalizeError(error2) {
|
|
|
90230
90244
|
}
|
|
90231
90245
|
function searchMusic_default(defaultFuncs, _api, ctx) {
|
|
90232
90246
|
async function runSearch(text3, count, selectedOptions, callback) {
|
|
90247
|
+
const cacheKey = `${selectedOptions.product || PRODUCT}|${count}|${text3}|${selectedOptions.cursor || ""}`;
|
|
90248
|
+
if (!selectedOptions.noCache) {
|
|
90249
|
+
const cache = ctx.__musicCache || (ctx.__musicCache = {});
|
|
90250
|
+
const hit = cache[cacheKey];
|
|
90251
|
+
if (hit && Date.now() - hit.at < MUSIC_CACHE_TTL_MS) return hit.result;
|
|
90252
|
+
}
|
|
90253
|
+
await paceMusic(ctx);
|
|
90233
90254
|
const params = { first: count };
|
|
90234
90255
|
if (text3) params.search_text = text3;
|
|
90235
90256
|
if (selectedOptions.cursor) params.after = String(selectedOptions.cursor);
|
|
@@ -90302,11 +90323,12 @@ function searchMusic_default(defaultFuncs, _api, ctx) {
|
|
|
90302
90323
|
result.endCursor = page.endCursor;
|
|
90303
90324
|
result.hasNextPage = page.hasNextPage;
|
|
90304
90325
|
result.query = text3;
|
|
90326
|
+
cacheResult(ctx, cacheKey, result);
|
|
90305
90327
|
return result;
|
|
90306
90328
|
}
|
|
90307
90329
|
for (let retry = 0; retry < 3; retry++) {
|
|
90308
|
-
await sleep(
|
|
90309
|
-
const retried = await attempt(
|
|
90330
|
+
await sleep(1200 + retry * 1300 + Math.floor(Math.random() * 400));
|
|
90331
|
+
const retried = await attempt(retry === 2 || !hasCometTokens(ctx));
|
|
90310
90332
|
if (isStaleTokenError(retried) || retried?.error || (retried?.errors || []).length) continue;
|
|
90311
90333
|
const retryPage = collectTracks(retried);
|
|
90312
90334
|
const retryTracks = retryPage.tracks.slice(0, count);
|
|
@@ -90316,6 +90338,7 @@ function searchMusic_default(defaultFuncs, _api, ctx) {
|
|
|
90316
90338
|
result.endCursor = retryPage.endCursor;
|
|
90317
90339
|
result.hasNextPage = retryPage.hasNextPage;
|
|
90318
90340
|
result.query = text3;
|
|
90341
|
+
cacheResult(ctx, cacheKey, result);
|
|
90319
90342
|
return result;
|
|
90320
90343
|
}
|
|
90321
90344
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -90173,10 +90173,24 @@ function collectTracks(payload) {
|
|
|
90173
90173
|
}
|
|
90174
90174
|
|
|
90175
90175
|
// src/deltas/apis/music/searchMusic.ts
|
|
90176
|
+
var MUSIC_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
90176
90177
|
function nextRequestId(ctx) {
|
|
90177
90178
|
ctx.__reqCounter = (typeof ctx.__reqCounter === "number" ? ctx.__reqCounter : 0) + 1;
|
|
90178
90179
|
return ctx.__reqCounter.toString(36);
|
|
90179
90180
|
}
|
|
90181
|
+
var MUSIC_MIN_INTERVAL_MS = 1100;
|
|
90182
|
+
async function paceMusic(ctx) {
|
|
90183
|
+
const configured = Number(ctx?.globalOptions?.musicMinIntervalMs);
|
|
90184
|
+
const min = Number.isFinite(configured) && configured >= 0 ? configured : MUSIC_MIN_INTERVAL_MS;
|
|
90185
|
+
const last2 = typeof ctx.__musicLastCallAt === "number" ? ctx.__musicLastCallAt : 0;
|
|
90186
|
+
const wait = last2 + min - Date.now();
|
|
90187
|
+
if (wait > 0) await sleep(wait);
|
|
90188
|
+
ctx.__musicLastCallAt = Date.now();
|
|
90189
|
+
}
|
|
90190
|
+
function cacheResult(ctx, key, result) {
|
|
90191
|
+
const cache = ctx.__musicCache || (ctx.__musicCache = {});
|
|
90192
|
+
cache[key] = { at: Date.now(), result };
|
|
90193
|
+
}
|
|
90180
90194
|
function normalizeError(error2) {
|
|
90181
90195
|
if (!error2 || typeof error2 !== "object") {
|
|
90182
90196
|
const message2 = String(error2);
|
|
@@ -90198,6 +90212,13 @@ function normalizeError(error2) {
|
|
|
90198
90212
|
}
|
|
90199
90213
|
function searchMusic_default(defaultFuncs, _api, ctx) {
|
|
90200
90214
|
async function runSearch(text3, count, selectedOptions, callback) {
|
|
90215
|
+
const cacheKey = `${selectedOptions.product || PRODUCT}|${count}|${text3}|${selectedOptions.cursor || ""}`;
|
|
90216
|
+
if (!selectedOptions.noCache) {
|
|
90217
|
+
const cache = ctx.__musicCache || (ctx.__musicCache = {});
|
|
90218
|
+
const hit = cache[cacheKey];
|
|
90219
|
+
if (hit && Date.now() - hit.at < MUSIC_CACHE_TTL_MS) return hit.result;
|
|
90220
|
+
}
|
|
90221
|
+
await paceMusic(ctx);
|
|
90201
90222
|
const params = { first: count };
|
|
90202
90223
|
if (text3) params.search_text = text3;
|
|
90203
90224
|
if (selectedOptions.cursor) params.after = String(selectedOptions.cursor);
|
|
@@ -90270,11 +90291,12 @@ function searchMusic_default(defaultFuncs, _api, ctx) {
|
|
|
90270
90291
|
result.endCursor = page.endCursor;
|
|
90271
90292
|
result.hasNextPage = page.hasNextPage;
|
|
90272
90293
|
result.query = text3;
|
|
90294
|
+
cacheResult(ctx, cacheKey, result);
|
|
90273
90295
|
return result;
|
|
90274
90296
|
}
|
|
90275
90297
|
for (let retry = 0; retry < 3; retry++) {
|
|
90276
|
-
await sleep(
|
|
90277
|
-
const retried = await attempt(
|
|
90298
|
+
await sleep(1200 + retry * 1300 + Math.floor(Math.random() * 400));
|
|
90299
|
+
const retried = await attempt(retry === 2 || !hasCometTokens(ctx));
|
|
90278
90300
|
if (isStaleTokenError(retried) || retried?.error || (retried?.errors || []).length) continue;
|
|
90279
90301
|
const retryPage = collectTracks(retried);
|
|
90280
90302
|
const retryTracks = retryPage.tracks.slice(0, count);
|
|
@@ -90284,6 +90306,7 @@ function searchMusic_default(defaultFuncs, _api, ctx) {
|
|
|
90284
90306
|
result.endCursor = retryPage.endCursor;
|
|
90285
90307
|
result.hasNextPage = retryPage.hasNextPage;
|
|
90286
90308
|
result.query = text3;
|
|
90309
|
+
cacheResult(ctx, cacheKey, result);
|
|
90287
90310
|
return result;
|
|
90288
90311
|
}
|
|
90289
90312
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazyneoaz/metachat",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "A modern TypeScript Facebook Chat API client for building reliable Messenger bots, with built-in anti-detection protection, automatic cookie refresh, music search, and AI theme support.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|