qwenproxy-cli 1.4.0 → 1.4.2
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.pt-BR.md +7 -5
- package/dist/clean-cache.js +167 -68
- package/dist/delete-chats.js +212 -88
- package/dist/index.js +392 -267
- package/dist/login.js +172 -73
- package/dist/reset-cooldowns.js +167 -68
- package/dist/sync-clients.js +136 -126
- package/package.json +8 -6
- package/src/core/config.ts +13 -0
- package/src/core/version.ts +1 -1
- package/src/routes/chat/index.ts +1 -0
- package/src/services/playwright.ts +137 -43
- package/src/services/qwen.ts +47 -19
package/dist/reset-cooldowns.js
CHANGED
|
@@ -1206,6 +1206,8 @@ var init_errors = __esm({
|
|
|
1206
1206
|
});
|
|
1207
1207
|
|
|
1208
1208
|
// src/core/config.ts
|
|
1209
|
+
import fs6 from "node:fs";
|
|
1210
|
+
import dotenv from "dotenv";
|
|
1209
1211
|
import { z } from "zod";
|
|
1210
1212
|
function normalizeChatMode(mode) {
|
|
1211
1213
|
if (!mode) return "thread";
|
|
@@ -1225,6 +1227,15 @@ var envSchema, env, config;
|
|
|
1225
1227
|
var init_config = __esm({
|
|
1226
1228
|
"src/core/config.ts"() {
|
|
1227
1229
|
"use strict";
|
|
1230
|
+
init_paths();
|
|
1231
|
+
if (!isRunningUnderNodeTest()) {
|
|
1232
|
+
const envPath = getEnvFilePath();
|
|
1233
|
+
if (fs6.existsSync(envPath)) {
|
|
1234
|
+
dotenv.config({ path: envPath, quiet: true });
|
|
1235
|
+
} else {
|
|
1236
|
+
dotenv.config({ quiet: true });
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1228
1239
|
envSchema = z.object({
|
|
1229
1240
|
PORT: z.string().regex(/^\d+$/, "PORT must be a number").refine((value) => {
|
|
1230
1241
|
const port = Number(value);
|
|
@@ -2686,7 +2697,7 @@ __export(clean_cache_exports, {
|
|
|
2686
2697
|
getDirStats: () => getDirStats
|
|
2687
2698
|
});
|
|
2688
2699
|
import "dotenv/config";
|
|
2689
|
-
import
|
|
2700
|
+
import fs7 from "node:fs";
|
|
2690
2701
|
import path4 from "node:path";
|
|
2691
2702
|
import os3 from "node:os";
|
|
2692
2703
|
import { chromium } from "patchright";
|
|
@@ -2701,14 +2712,14 @@ function getDirStats(dir) {
|
|
|
2701
2712
|
let files = 0;
|
|
2702
2713
|
function walk(d) {
|
|
2703
2714
|
try {
|
|
2704
|
-
const entries =
|
|
2715
|
+
const entries = fs7.readdirSync(d, { withFileTypes: true });
|
|
2705
2716
|
for (const e of entries) {
|
|
2706
2717
|
const full = path4.join(d, e.name);
|
|
2707
2718
|
if (e.isDirectory()) {
|
|
2708
2719
|
walk(full);
|
|
2709
2720
|
} else if (e.isFile()) {
|
|
2710
2721
|
try {
|
|
2711
|
-
bytes +=
|
|
2722
|
+
bytes += fs7.statSync(full).size;
|
|
2712
2723
|
files++;
|
|
2713
2724
|
} catch {
|
|
2714
2725
|
}
|
|
@@ -2737,17 +2748,17 @@ async function cleanPlaywrightBrowsers(cleanUnused) {
|
|
|
2737
2748
|
}
|
|
2738
2749
|
} catch {
|
|
2739
2750
|
}
|
|
2740
|
-
if (!msPlaywrightDir || !
|
|
2751
|
+
if (!msPlaywrightDir || !fs7.existsSync(msPlaywrightDir)) {
|
|
2741
2752
|
const defaultPlaywrightDir = process.env.PLAYWRIGHT_BROWSERS_PATH || (process.platform === "win32" ? path4.join(os3.homedir(), "AppData", "Local", "ms-playwright") : process.platform === "darwin" ? path4.join(os3.homedir(), "Library", "Caches", "ms-playwright") : path4.join(os3.homedir(), ".cache", "ms-playwright"));
|
|
2742
|
-
if (
|
|
2753
|
+
if (fs7.existsSync(defaultPlaywrightDir)) {
|
|
2743
2754
|
msPlaywrightDir = defaultPlaywrightDir;
|
|
2744
2755
|
}
|
|
2745
2756
|
}
|
|
2746
2757
|
const unusedDirs = [];
|
|
2747
2758
|
let freedBytes = 0;
|
|
2748
|
-
if (msPlaywrightDir &&
|
|
2759
|
+
if (msPlaywrightDir && fs7.existsSync(msPlaywrightDir)) {
|
|
2749
2760
|
try {
|
|
2750
|
-
const entries =
|
|
2761
|
+
const entries = fs7.readdirSync(msPlaywrightDir, { withFileTypes: true });
|
|
2751
2762
|
for (const entry of entries) {
|
|
2752
2763
|
if (!entry.isDirectory()) continue;
|
|
2753
2764
|
const folderName = entry.name;
|
|
@@ -2770,7 +2781,7 @@ async function cleanPlaywrightBrowsers(cleanUnused) {
|
|
|
2770
2781
|
if (cleanUnused && unusedDirs.length > 0) {
|
|
2771
2782
|
for (const item of unusedDirs) {
|
|
2772
2783
|
try {
|
|
2773
|
-
|
|
2784
|
+
fs7.rmSync(item.path, { recursive: true, force: true });
|
|
2774
2785
|
freedBytes += item.bytes;
|
|
2775
2786
|
} catch (err) {
|
|
2776
2787
|
console.warn(`[CleanCache] Warning: could not remove ${item.name}:`, err);
|
|
@@ -2859,7 +2870,7 @@ var init_clean_cache = __esm({
|
|
|
2859
2870
|
// src/services/playwright.ts
|
|
2860
2871
|
import { chromium as chromium2 } from "patchright";
|
|
2861
2872
|
import path5 from "path";
|
|
2862
|
-
import
|
|
2873
|
+
import fs8 from "fs";
|
|
2863
2874
|
import crypto3 from "crypto";
|
|
2864
2875
|
import { spawnSync } from "child_process";
|
|
2865
2876
|
import { createRequire } from "module";
|
|
@@ -2873,7 +2884,7 @@ function autoInstallPlaywrightChromium() {
|
|
|
2873
2884
|
try {
|
|
2874
2885
|
const patchrightEntry = requireLocal.resolve("patchright");
|
|
2875
2886
|
const cliPath = path5.join(path5.dirname(patchrightEntry), "cli.js");
|
|
2876
|
-
if (
|
|
2887
|
+
if (fs8.existsSync(cliPath)) {
|
|
2877
2888
|
console.log("\u23F3 [Playwright] Navegador Chromium n\xE3o encontrado. Instalando automaticamente...");
|
|
2878
2889
|
const res2 = spawnSync(process.execPath, [cliPath, "install", "chromium"], {
|
|
2879
2890
|
stdio: "inherit",
|
|
@@ -3006,10 +3017,10 @@ function getStorageStatePath(accountId) {
|
|
|
3006
3017
|
function loadStorageState(accountId) {
|
|
3007
3018
|
const p1 = getStorageStatePath(accountId);
|
|
3008
3019
|
const p2 = path5.join(path5.dirname(p1), `${accountId}_state.json`);
|
|
3009
|
-
const chosenPath =
|
|
3020
|
+
const chosenPath = fs8.existsSync(p1) ? p1 : fs8.existsSync(p2) ? p2 : void 0;
|
|
3010
3021
|
if (!chosenPath) return void 0;
|
|
3011
3022
|
try {
|
|
3012
|
-
const raw =
|
|
3023
|
+
const raw = fs8.readFileSync(chosenPath, "utf8");
|
|
3013
3024
|
const state = JSON.parse(raw);
|
|
3014
3025
|
if (!state || typeof state !== "object" || !Array.isArray(state.cookies)) {
|
|
3015
3026
|
return void 0;
|
|
@@ -3023,8 +3034,8 @@ async function saveStorageState(context, accountId, timeoutMs = 5e3) {
|
|
|
3023
3034
|
try {
|
|
3024
3035
|
const stateFile = getStorageStatePath(accountId);
|
|
3025
3036
|
const dir = path5.dirname(stateFile);
|
|
3026
|
-
if (!
|
|
3027
|
-
|
|
3037
|
+
if (!fs8.existsSync(dir)) {
|
|
3038
|
+
fs8.mkdirSync(dir, { recursive: true });
|
|
3028
3039
|
}
|
|
3029
3040
|
await withTimeout(
|
|
3030
3041
|
context.storageState({ path: stateFile }),
|
|
@@ -3134,13 +3145,40 @@ async function isPageLoggedIn(page, timeoutMs = SESSION_PROBE_NAVIGATION_TIMEOUT
|
|
|
3134
3145
|
}
|
|
3135
3146
|
}
|
|
3136
3147
|
async function clearVisibleChallenge(page) {
|
|
3137
|
-
if (
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3148
|
+
if (page.isClosed()) return;
|
|
3149
|
+
if (config.captcha.enabled) {
|
|
3150
|
+
await solveBaxiaCaptcha(page, {
|
|
3151
|
+
waitForMs: 0,
|
|
3152
|
+
maxAttempts: config.captcha.maxAttempts,
|
|
3153
|
+
retryDelayMs: config.captcha.retryDelayMs,
|
|
3154
|
+
settleMs: config.captcha.settleMs
|
|
3155
|
+
}).catch(() => false);
|
|
3156
|
+
}
|
|
3157
|
+
try {
|
|
3158
|
+
const modalCloseSelectors = [
|
|
3159
|
+
".ant-modal-close",
|
|
3160
|
+
".ant-modal-close-x",
|
|
3161
|
+
"button.ant-modal-close",
|
|
3162
|
+
"button[aria-label*='Close' i]",
|
|
3163
|
+
"button[aria-label*='Fechar' i]",
|
|
3164
|
+
".index-module__whats-new-modal-close",
|
|
3165
|
+
"button:has-text('Cancel')",
|
|
3166
|
+
"button:has-text('Cancelar')",
|
|
3167
|
+
"button:has-text('I understand')",
|
|
3168
|
+
"button:has-text('Entendi')",
|
|
3169
|
+
"button:has-text('OK')"
|
|
3170
|
+
];
|
|
3171
|
+
for (const sel of modalCloseSelectors) {
|
|
3172
|
+
if (page.isClosed()) return;
|
|
3173
|
+
const btn = page.locator(sel).first();
|
|
3174
|
+
if (await btn.isVisible({ timeout: 150 }).catch(() => false)) {
|
|
3175
|
+
await btn.click({ timeout: 500 }).catch(() => {
|
|
3176
|
+
});
|
|
3177
|
+
await sleep2(200);
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
} catch {
|
|
3181
|
+
}
|
|
3144
3182
|
}
|
|
3145
3183
|
function getErrorMessage(error) {
|
|
3146
3184
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -3568,6 +3606,21 @@ function getStealthScript(profile) {
|
|
|
3568
3606
|
spoofedFunctions.add(window.performance.getEntriesByType);
|
|
3569
3607
|
}
|
|
3570
3608
|
} catch(e) {}
|
|
3609
|
+
|
|
3610
|
+
// --- Auto-resolve birthday compliance & eliminate false logout markers ---
|
|
3611
|
+
try {
|
|
3612
|
+
localStorage.removeItem("qwen_token_logged_out_marker");
|
|
3613
|
+
const b = localStorage.getItem("qwen_account_birthday");
|
|
3614
|
+
if (b) {
|
|
3615
|
+
try {
|
|
3616
|
+
const parsed = JSON.parse(b);
|
|
3617
|
+
if (!parsed.birthday) {
|
|
3618
|
+
parsed.birthday = "1995-06-15";
|
|
3619
|
+
localStorage.setItem("qwen_account_birthday", JSON.stringify(parsed));
|
|
3620
|
+
}
|
|
3621
|
+
} catch {}
|
|
3622
|
+
}
|
|
3623
|
+
} catch(e) {}
|
|
3571
3624
|
})();
|
|
3572
3625
|
`;
|
|
3573
3626
|
}
|
|
@@ -3603,7 +3656,7 @@ async function resolveAccountCredentials(account) {
|
|
|
3603
3656
|
}
|
|
3604
3657
|
return account;
|
|
3605
3658
|
}
|
|
3606
|
-
async function initPlaywrightForAccount(rawAccount, headless =
|
|
3659
|
+
async function initPlaywrightForAccount(rawAccount, headless = config.playwright.headless, browserType = "chromium", options = {}) {
|
|
3607
3660
|
const account = await resolveAccountCredentials(rawAccount);
|
|
3608
3661
|
if (accountPages.has(account.id)) {
|
|
3609
3662
|
console.log(
|
|
@@ -3729,7 +3782,7 @@ async function initPlaywrightForAccount(rawAccount, headless = true, browserType
|
|
|
3729
3782
|
const storageState = loadStorageState(account.id);
|
|
3730
3783
|
if (storageState) {
|
|
3731
3784
|
try {
|
|
3732
|
-
const raw =
|
|
3785
|
+
const raw = fs8.readFileSync(storageState, "utf8");
|
|
3733
3786
|
const parsed = JSON.parse(raw);
|
|
3734
3787
|
if (Array.isArray(parsed.cookies) && parsed.cookies.length > 0) {
|
|
3735
3788
|
const currentCookies = await acctContext.cookies();
|
|
@@ -3816,11 +3869,19 @@ async function initPlaywrightForAccount(rawAccount, headless = true, browserType
|
|
|
3816
3869
|
}
|
|
3817
3870
|
if (restoredFromDb) {
|
|
3818
3871
|
if (!acctPage.isClosed() && (acctPage.url() === "about:blank" || !acctPage.url().startsWith(qwenOrigin()))) {
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3872
|
+
try {
|
|
3873
|
+
await acctPage.goto(qwenUrl("/"), {
|
|
3874
|
+
waitUntil: "domcontentloaded",
|
|
3875
|
+
timeout: config.timeouts.navigation
|
|
3876
|
+
});
|
|
3877
|
+
await sleep2(300);
|
|
3878
|
+
} catch (err) {
|
|
3879
|
+
if (!err?.message?.includes("ERR_ABORTED")) {
|
|
3880
|
+
console.warn(
|
|
3881
|
+
`\u26A0\uFE0F [Playwright] Background navigation warning for ${maskEmail(account.email)}: ${err.message}`
|
|
3882
|
+
);
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3824
3885
|
}
|
|
3825
3886
|
return;
|
|
3826
3887
|
}
|
|
@@ -3940,18 +4001,34 @@ async function loginToQwen(accountId, email, password) {
|
|
|
3940
4001
|
const apiResult = await loginViaApi(page, email, password);
|
|
3941
4002
|
if (apiResult.success) {
|
|
3942
4003
|
cookieCaches.delete(accountId);
|
|
3943
|
-
|
|
3944
|
-
if (cache) {
|
|
3945
|
-
cache.headers = {};
|
|
3946
|
-
cache.lastRefresh = 0;
|
|
3947
|
-
}
|
|
3948
|
-
unmarkAccountHeadersReady(accountId);
|
|
4004
|
+
await saveStorageState(page.context(), accountId);
|
|
3949
4005
|
try {
|
|
3950
|
-
const
|
|
3951
|
-
|
|
4006
|
+
const liveCookies = await page.context().cookies();
|
|
4007
|
+
const tokenCookie = liveCookies.find((c) => c.name === "token");
|
|
4008
|
+
if (tokenCookie) {
|
|
4009
|
+
const cookieStr = liveCookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
4010
|
+
const cache = getHeaderCache(accountId);
|
|
4011
|
+
cache.headers.cookie = cookieStr;
|
|
4012
|
+
cache.lastRefresh = Date.now();
|
|
4013
|
+
markAccountHeadersReady(accountId);
|
|
4014
|
+
const { saveAuthSession: saveAuthSession2 } = await Promise.resolve().then(() => (init_database(), database_exports));
|
|
4015
|
+
const exp = parseJwtExpiry(tokenCookie.value);
|
|
4016
|
+
saveAuthSession2(accountId, {
|
|
4017
|
+
cookie: cookieStr,
|
|
4018
|
+
userAgent: cache.headers["user-agent"] || "",
|
|
4019
|
+
bxV: cache.headers["bx-v"] || "2.5.37",
|
|
4020
|
+
bxUa: cache.headers["bx-ua"] || "",
|
|
4021
|
+
bxUmidtoken: cache.headers["bx-umidtoken"] || "",
|
|
4022
|
+
secChUa: cache.headers["sec-ch-ua"] || void 0,
|
|
4023
|
+
secChUaMobile: cache.headers["sec-ch-ua-mobile"] || void 0,
|
|
4024
|
+
secChUaPlatform: cache.headers["sec-ch-ua-platform"] || void 0,
|
|
4025
|
+
version: cache.headers["version"] || void 0,
|
|
4026
|
+
tokenExpiresAt: exp || void 0,
|
|
4027
|
+
capturedAt: Date.now()
|
|
4028
|
+
});
|
|
4029
|
+
}
|
|
3952
4030
|
} catch {
|
|
3953
4031
|
}
|
|
3954
|
-
await saveStorageState(page.context(), accountId);
|
|
3955
4032
|
return true;
|
|
3956
4033
|
}
|
|
3957
4034
|
if (apiResult.permanentFailure) {
|
|
@@ -3968,18 +4045,34 @@ async function loginToQwen(accountId, email, password) {
|
|
|
3968
4045
|
const uiResult = await loginViaUi(page, email, password);
|
|
3969
4046
|
if (uiResult.success) {
|
|
3970
4047
|
cookieCaches.delete(accountId);
|
|
3971
|
-
|
|
3972
|
-
if (cache) {
|
|
3973
|
-
cache.headers = {};
|
|
3974
|
-
cache.lastRefresh = 0;
|
|
3975
|
-
}
|
|
3976
|
-
unmarkAccountHeadersReady(accountId);
|
|
4048
|
+
await saveStorageState(page.context(), accountId);
|
|
3977
4049
|
try {
|
|
3978
|
-
const
|
|
3979
|
-
|
|
4050
|
+
const liveCookies = await page.context().cookies();
|
|
4051
|
+
const tokenCookie = liveCookies.find((c) => c.name === "token");
|
|
4052
|
+
if (tokenCookie) {
|
|
4053
|
+
const cookieStr = liveCookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
4054
|
+
const cache = getHeaderCache(accountId);
|
|
4055
|
+
cache.headers.cookie = cookieStr;
|
|
4056
|
+
cache.lastRefresh = Date.now();
|
|
4057
|
+
markAccountHeadersReady(accountId);
|
|
4058
|
+
const { saveAuthSession: saveAuthSession2 } = await Promise.resolve().then(() => (init_database(), database_exports));
|
|
4059
|
+
const exp = parseJwtExpiry(tokenCookie.value);
|
|
4060
|
+
saveAuthSession2(accountId, {
|
|
4061
|
+
cookie: cookieStr,
|
|
4062
|
+
userAgent: cache.headers["user-agent"] || "",
|
|
4063
|
+
bxV: cache.headers["bx-v"] || "2.5.37",
|
|
4064
|
+
bxUa: cache.headers["bx-ua"] || "",
|
|
4065
|
+
bxUmidtoken: cache.headers["bx-umidtoken"] || "",
|
|
4066
|
+
secChUa: cache.headers["sec-ch-ua"] || void 0,
|
|
4067
|
+
secChUaMobile: cache.headers["sec-ch-ua-mobile"] || void 0,
|
|
4068
|
+
secChUaPlatform: cache.headers["sec-ch-ua-platform"] || void 0,
|
|
4069
|
+
version: cache.headers["version"] || void 0,
|
|
4070
|
+
tokenExpiresAt: exp || void 0,
|
|
4071
|
+
capturedAt: Date.now()
|
|
4072
|
+
});
|
|
4073
|
+
}
|
|
3980
4074
|
} catch {
|
|
3981
4075
|
}
|
|
3982
|
-
await saveStorageState(page.context(), accountId);
|
|
3983
4076
|
return true;
|
|
3984
4077
|
}
|
|
3985
4078
|
if (uiResult.permanentFailure) {
|
|
@@ -4178,10 +4271,16 @@ async function loginViaUi(page, email, password) {
|
|
|
4178
4271
|
);
|
|
4179
4272
|
return { success: false, reason: "Campo de e-mail n\xE3o encontrado (poss\xEDvel captcha)" };
|
|
4180
4273
|
}
|
|
4274
|
+
await clearVisibleChallenge(page);
|
|
4275
|
+
const findPasswordModeButton = () => {
|
|
4276
|
+
return page.locator('button, [role="button"], a, div').filter({
|
|
4277
|
+
hasText: /(?:log\s*in\s*with\s*(?:a\s*)?password|fazer\s*login\s*com\s*senha|entrar\s*com\s*(?:uma\s*)?senha|iniciar\s*sesi[oó]n\s*con\s*contrase[nñ]a|密码登录)/i
|
|
4278
|
+
}).first();
|
|
4279
|
+
};
|
|
4181
4280
|
try {
|
|
4182
|
-
const pwdModeBtn =
|
|
4183
|
-
if (await pwdModeBtn.isVisible({ timeout:
|
|
4184
|
-
await pwdModeBtn.click().catch(() => {
|
|
4281
|
+
const pwdModeBtn = findPasswordModeButton();
|
|
4282
|
+
if (await pwdModeBtn.isVisible({ timeout: 2e3 }).catch(() => false)) {
|
|
4283
|
+
await pwdModeBtn.click({ timeout: 2e3 }).catch(() => {
|
|
4185
4284
|
});
|
|
4186
4285
|
await sleep2(500);
|
|
4187
4286
|
}
|
|
@@ -4190,9 +4289,9 @@ async function loginViaUi(page, email, password) {
|
|
|
4190
4289
|
await page.fill(emailSelector, email);
|
|
4191
4290
|
await sleep2(300);
|
|
4192
4291
|
try {
|
|
4193
|
-
const pwdModeBtn =
|
|
4194
|
-
if (await pwdModeBtn.isVisible({ timeout:
|
|
4195
|
-
await pwdModeBtn.click().catch(() => {
|
|
4292
|
+
const pwdModeBtn = findPasswordModeButton();
|
|
4293
|
+
if (await pwdModeBtn.isVisible({ timeout: 1500 }).catch(() => false)) {
|
|
4294
|
+
await pwdModeBtn.click({ timeout: 2e3 }).catch(() => {
|
|
4196
4295
|
});
|
|
4197
4296
|
await sleep2(500);
|
|
4198
4297
|
}
|
|
@@ -4217,7 +4316,7 @@ async function loginViaUi(page, email, password) {
|
|
|
4217
4316
|
}
|
|
4218
4317
|
await page.fill(passwordSelector, password);
|
|
4219
4318
|
await sleep2(500);
|
|
4220
|
-
const submitSelector = 'button.qwenchat-auth-pc-submit-button, button[type="submit"], button:has-text("Log in"), button:has-text("Sign in")';
|
|
4319
|
+
const submitSelector = 'button.qwenchat-auth-pc-submit-button, button[type="submit"], button:has-text("Log in"), button:has-text("Sign in"), button:has-text("Fazer login"), button:has-text("Entrar"), button:has-text("Iniciar sesi\xF3n"), button:has-text("\u767B\u5F55")';
|
|
4221
4320
|
const submitButton = page.locator(submitSelector).first();
|
|
4222
4321
|
try {
|
|
4223
4322
|
await page.waitForSelector('button[type="submit"]:not([disabled])', {
|
|
@@ -4744,12 +4843,12 @@ async function resetPlaywrightProfileLocked(accountId) {
|
|
|
4744
4843
|
removePlaywrightProfile(profilePath);
|
|
4745
4844
|
const stateFile2 = path5.join(path5.dirname(profilePath), `${accountId}_state.json`);
|
|
4746
4845
|
try {
|
|
4747
|
-
|
|
4846
|
+
fs8.rmSync(stateFile2, { force: true });
|
|
4748
4847
|
} catch {
|
|
4749
4848
|
}
|
|
4750
4849
|
}
|
|
4751
4850
|
function removePlaywrightProfile(profilePath, rmSyncOverride) {
|
|
4752
|
-
const doRemove = rmSyncOverride ?? ((p, opts) =>
|
|
4851
|
+
const doRemove = rmSyncOverride ?? ((p, opts) => fs8.rmSync(p, opts));
|
|
4753
4852
|
try {
|
|
4754
4853
|
doRemove(profilePath, { recursive: true, force: true });
|
|
4755
4854
|
} catch (error) {
|
|
@@ -4758,7 +4857,7 @@ function removePlaywrightProfile(profilePath, rmSyncOverride) {
|
|
|
4758
4857
|
if (message.includes("EPERM") || message.includes("EBUSY") || message.includes("Permission denied")) {
|
|
4759
4858
|
try {
|
|
4760
4859
|
const stalePath = `${profilePath}.stale-${Date.now()}`;
|
|
4761
|
-
|
|
4860
|
+
fs8.renameSync(profilePath, stalePath);
|
|
4762
4861
|
} catch {
|
|
4763
4862
|
}
|
|
4764
4863
|
return;
|
|
@@ -4781,23 +4880,23 @@ function prunePlaywrightProfileCaches(profilePath) {
|
|
|
4781
4880
|
let freedFiles = 0;
|
|
4782
4881
|
try {
|
|
4783
4882
|
const defaultDir = path5.join(profilePath, "Default");
|
|
4784
|
-
if (!
|
|
4883
|
+
if (!fs8.existsSync(defaultDir)) {
|
|
4785
4884
|
return { freedBytes, freedFiles };
|
|
4786
4885
|
}
|
|
4787
4886
|
for (const dirName of transientDirNames) {
|
|
4788
4887
|
const targetDir = path5.join(defaultDir, dirName);
|
|
4789
|
-
if (
|
|
4888
|
+
if (fs8.existsSync(targetDir)) {
|
|
4790
4889
|
try {
|
|
4791
4890
|
const countAndRemove = (d) => {
|
|
4792
4891
|
try {
|
|
4793
|
-
const entries =
|
|
4892
|
+
const entries = fs8.readdirSync(d, { withFileTypes: true });
|
|
4794
4893
|
for (const e of entries) {
|
|
4795
4894
|
const full = path5.join(d, e.name);
|
|
4796
4895
|
if (e.isDirectory()) {
|
|
4797
4896
|
countAndRemove(full);
|
|
4798
4897
|
} else if (e.isFile()) {
|
|
4799
4898
|
try {
|
|
4800
|
-
freedBytes +=
|
|
4899
|
+
freedBytes += fs8.statSync(full).size;
|
|
4801
4900
|
freedFiles++;
|
|
4802
4901
|
} catch {
|
|
4803
4902
|
}
|
|
@@ -4807,7 +4906,7 @@ function prunePlaywrightProfileCaches(profilePath) {
|
|
|
4807
4906
|
}
|
|
4808
4907
|
};
|
|
4809
4908
|
countAndRemove(targetDir);
|
|
4810
|
-
|
|
4909
|
+
fs8.rmSync(targetDir, { recursive: true, force: true });
|
|
4811
4910
|
} catch {
|
|
4812
4911
|
}
|
|
4813
4912
|
}
|
|
@@ -4821,10 +4920,10 @@ function pruneAllPlaywrightProfiles(baseDir = getProfilesDir()) {
|
|
|
4821
4920
|
let totalFreedFiles = 0;
|
|
4822
4921
|
let profilesCleaned = 0;
|
|
4823
4922
|
try {
|
|
4824
|
-
if (!
|
|
4923
|
+
if (!fs8.existsSync(baseDir)) {
|
|
4825
4924
|
return { totalFreedBytes, totalFreedFiles, profilesCleaned };
|
|
4826
4925
|
}
|
|
4827
|
-
const entries =
|
|
4926
|
+
const entries = fs8.readdirSync(baseDir, { withFileTypes: true });
|
|
4828
4927
|
for (const entry of entries) {
|
|
4829
4928
|
if (entry.isDirectory()) {
|
|
4830
4929
|
const profilePath = path5.join(baseDir, entry.name);
|
|
@@ -4844,11 +4943,11 @@ function cleanupOrphanProfiles(baseDir = getProfilesDir(), activeAccountIds) {
|
|
|
4844
4943
|
let removedCount = 0;
|
|
4845
4944
|
let freedBytes = 0;
|
|
4846
4945
|
try {
|
|
4847
|
-
if (!
|
|
4946
|
+
if (!fs8.existsSync(baseDir)) {
|
|
4848
4947
|
return { removedCount, freedBytes };
|
|
4849
4948
|
}
|
|
4850
4949
|
const activeIds = activeAccountIds ?? new Set(loadAccounts().map((a) => a.id));
|
|
4851
|
-
const entries =
|
|
4950
|
+
const entries = fs8.readdirSync(baseDir, { withFileTypes: true });
|
|
4852
4951
|
for (const entry of entries) {
|
|
4853
4952
|
if (!entry.isDirectory()) continue;
|
|
4854
4953
|
const isStale = entry.name.includes(".stale-");
|
|
@@ -4859,13 +4958,13 @@ function cleanupOrphanProfiles(baseDir = getProfilesDir(), activeAccountIds) {
|
|
|
4859
4958
|
let bytes = 0;
|
|
4860
4959
|
const countSize = (d) => {
|
|
4861
4960
|
try {
|
|
4862
|
-
const subEntries =
|
|
4961
|
+
const subEntries = fs8.readdirSync(d, { withFileTypes: true });
|
|
4863
4962
|
for (const e of subEntries) {
|
|
4864
4963
|
const full = path5.join(d, e.name);
|
|
4865
4964
|
if (e.isDirectory()) countSize(full);
|
|
4866
4965
|
else if (e.isFile()) {
|
|
4867
4966
|
try {
|
|
4868
|
-
bytes +=
|
|
4967
|
+
bytes += fs8.statSync(full).size;
|
|
4869
4968
|
} catch {
|
|
4870
4969
|
}
|
|
4871
4970
|
}
|
|
@@ -4875,7 +4974,7 @@ function cleanupOrphanProfiles(baseDir = getProfilesDir(), activeAccountIds) {
|
|
|
4875
4974
|
};
|
|
4876
4975
|
countSize(targetPath);
|
|
4877
4976
|
removePlaywrightProfile(targetPath);
|
|
4878
|
-
if (!
|
|
4977
|
+
if (!fs8.existsSync(targetPath)) {
|
|
4879
4978
|
removedCount++;
|
|
4880
4979
|
freedBytes += bytes;
|
|
4881
4980
|
}
|