@gruu6y/page-clean-login 0.2.9 → 0.2.11
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/account-browser.mjs +459 -0
- package/lib/account-exit.mjs +604 -0
- package/lib/account-proxies.mjs +376 -36
- package/lib/agent-cli.mjs +22 -0
- package/lib/agent-surface.mjs +41 -2
- package/lib/browser-launcher.mjs +142 -36
- package/lib/renew-hosting.mjs +90 -38
- package/lib/server.mjs +247 -83
- package/lib/signin-flow.mjs +51 -25
- package/package.json +1 -1
- package/ui/account-view.js +178 -6
- package/ui/app.js +422 -2
- package/ui/index.html +5 -0
- package/ui/style.css +33 -0
package/ui/account-view.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// and formatting check summaries and exits. Keeping these helpers free of DOM
|
|
3
3
|
// dependencies allows comprehensive headless testing.
|
|
4
4
|
|
|
5
|
-
import { accountLabel } from "./account-state.js";
|
|
5
|
+
import { accountIdentityPath, accountLabel } from "./account-state.js";
|
|
6
6
|
import { ALL_PROVIDERS, UNKNOWN_PROVIDER } from "./account-provider-filter.js";
|
|
7
7
|
|
|
8
8
|
export function accountView(account) {
|
|
@@ -38,6 +38,7 @@ export function accountView(account) {
|
|
|
38
38
|
const methodLabel = typeof value.methodLabel === "string" ? value.methodLabel.trim() : "";
|
|
39
39
|
const unverified = Boolean(value.unverified);
|
|
40
40
|
const hosting = normalizeHosting(value.hosting);
|
|
41
|
+
const browser = normalizeAccountBrowser(value.browser);
|
|
41
42
|
const rawExpiry = value.expiresAt ?? hosting.expiresAt;
|
|
42
43
|
const expiresAt = (() => {
|
|
43
44
|
if (typeof rawExpiry === "string" && rawExpiry.trim()) return rawExpiry.trim();
|
|
@@ -67,6 +68,7 @@ export function accountView(account) {
|
|
|
67
68
|
note,
|
|
68
69
|
unverified,
|
|
69
70
|
hosting,
|
|
71
|
+
browser,
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -145,20 +147,190 @@ export function hostingTone(hosting) {
|
|
|
145
147
|
return "none";
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
// Per-account fingerprint browser endpoint. URL-encodes both segments via
|
|
151
|
+
// accountIdentityPath so `#` and `/` in keys stay safe.
|
|
152
|
+
export function accountBrowserPath(provider, key) {
|
|
153
|
+
return `${accountIdentityPath(provider, key)}/browser`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Credential-free normalization of the account browser state returned by
|
|
157
|
+
// GET /api/accounts, GET/POST/DELETE /api/accounts/:provider/:key/browser,
|
|
158
|
+
// and PATCH account/exit responses. Unknown fields (like raw URLs or auth)
|
|
159
|
+
// are never forwarded.
|
|
160
|
+
export function normalizeAccountBrowser(value) {
|
|
161
|
+
const raw = value && typeof value === "object" ? value : {};
|
|
162
|
+
const open = raw.open === true;
|
|
163
|
+
if (!open) {
|
|
164
|
+
return {
|
|
165
|
+
open: false,
|
|
166
|
+
openedAt: null,
|
|
167
|
+
exit: null,
|
|
168
|
+
exitChanged: false,
|
|
169
|
+
warning: null,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const openedAt = (() => {
|
|
173
|
+
if (typeof raw.openedAt === "string" && raw.openedAt.trim()) return raw.openedAt.trim();
|
|
174
|
+
if (typeof raw.openedAt === "number" && Number.isFinite(raw.openedAt) && raw.openedAt > 0) {
|
|
175
|
+
const date = new Date(raw.openedAt);
|
|
176
|
+
return Number.isNaN(date.getTime()) ? null : date.toISOString();
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
})();
|
|
180
|
+
const rawExit = raw.exit && typeof raw.exit === "object" ? raw.exit : null;
|
|
181
|
+
const exit = rawExit
|
|
182
|
+
? {
|
|
183
|
+
ok: rawExit.ok !== false,
|
|
184
|
+
mode: typeof rawExit.mode === "string" ? rawExit.mode : null,
|
|
185
|
+
effectiveMode: typeof rawExit.effectiveMode === "string" ? rawExit.effectiveMode : null,
|
|
186
|
+
proxyId: typeof rawExit.proxyId === "string" && rawExit.proxyId ? rawExit.proxyId : null,
|
|
187
|
+
proxyName: typeof rawExit.proxyName === "string" ? rawExit.proxyName : "",
|
|
188
|
+
region: typeof rawExit.region === "string" ? rawExit.region : "",
|
|
189
|
+
type: typeof rawExit.type === "string" && rawExit.type ? rawExit.type : null,
|
|
190
|
+
displayUrl: typeof rawExit.displayUrl === "string" && rawExit.displayUrl.trim()
|
|
191
|
+
? rawExit.displayUrl.trim()
|
|
192
|
+
: null,
|
|
193
|
+
providerProxy: typeof rawExit.providerProxy === "string" && rawExit.providerProxy.trim()
|
|
194
|
+
? rawExit.providerProxy.trim()
|
|
195
|
+
: null,
|
|
196
|
+
matchedStore: Boolean(rawExit.matchedStore),
|
|
197
|
+
}
|
|
198
|
+
: null;
|
|
199
|
+
const rawWarning = raw.warning && typeof raw.warning === "object" ? raw.warning : null;
|
|
200
|
+
const warning = rawWarning && typeof rawWarning.code === "string" && rawWarning.code.trim()
|
|
201
|
+
? {
|
|
202
|
+
code: rawWarning.code.trim(),
|
|
203
|
+
status: Number.isFinite(rawWarning.status) ? rawWarning.status : 0,
|
|
204
|
+
message: typeof rawWarning.message === "string" ? rawWarning.message : "",
|
|
205
|
+
}
|
|
206
|
+
: null;
|
|
207
|
+
return {
|
|
208
|
+
open: true,
|
|
209
|
+
openedAt,
|
|
210
|
+
exit,
|
|
211
|
+
exitChanged: raw.exitChanged === true,
|
|
212
|
+
warning,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Formats the publicAccountExit projection attached to an open browser.
|
|
217
|
+
// External custom URLs (effectiveMode === "proxy" without a stored proxyId)
|
|
218
|
+
// never fall back to "Direct".
|
|
219
|
+
export function formatBrowserExit(exit, directText = "直连", labels = {}) {
|
|
220
|
+
if (!exit || typeof exit !== "object") return directText;
|
|
221
|
+
if (exit.effectiveMode === "direct") {
|
|
222
|
+
if (exit.mode === "inherit") {
|
|
223
|
+
return formatExit({ mode: "inherit", proxyId: null, displayUrl: null, custom: false }, directText, labels);
|
|
224
|
+
}
|
|
225
|
+
return directText;
|
|
226
|
+
}
|
|
227
|
+
const displayUrl =
|
|
228
|
+
(typeof exit.displayUrl === "string" && exit.displayUrl.trim()) ||
|
|
229
|
+
(exit.mode === "inherit" && typeof exit.providerProxy === "string" && exit.providerProxy.trim()) ||
|
|
230
|
+
null;
|
|
231
|
+
const isExternalCustom =
|
|
232
|
+
(exit.effectiveMode === "proxy" && !exit.proxyId) ||
|
|
233
|
+
(exit.mode === "custom" && !exit.proxyId && exit.matchedStore !== true);
|
|
234
|
+
return formatExit(
|
|
235
|
+
{
|
|
236
|
+
...exit,
|
|
237
|
+
displayUrl,
|
|
238
|
+
custom: Boolean(exit.custom || isExternalCustom),
|
|
239
|
+
},
|
|
240
|
+
directText,
|
|
241
|
+
labels,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Pure display summary for an account's fingerprint browser state. Used by
|
|
246
|
+
// both the table row and the account detail dialog so status wording, opening
|
|
247
|
+
// exit label, exit-changed warning, and visual tone stay identical.
|
|
248
|
+
export function browserStateSummary(browser, labels = {}) {
|
|
249
|
+
const state = normalizeAccountBrowser(browser);
|
|
250
|
+
if (!state.open) {
|
|
251
|
+
return {
|
|
252
|
+
open: false,
|
|
253
|
+
exitChanged: false,
|
|
254
|
+
exitLabel: "",
|
|
255
|
+
statusText: typeof labels?.closed === "string" ? labels.closed : "",
|
|
256
|
+
noticeText: "",
|
|
257
|
+
tone: "none",
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const directText = typeof labels?.direct === "string" && labels.direct ? labels.direct : "直连";
|
|
261
|
+
const exitLabel = formatBrowserExit(state.exit, directText, {
|
|
262
|
+
custom: labels?.custom,
|
|
263
|
+
inherit: labels?.inherit,
|
|
264
|
+
});
|
|
265
|
+
const openTemplate =
|
|
266
|
+
typeof labels?.openWithExit === "string" && labels.openWithExit.trim()
|
|
267
|
+
? labels.openWithExit.trim()
|
|
268
|
+
: "浏览器已打开 · {exit}";
|
|
269
|
+
const statusText = openTemplate.includes("{exit}")
|
|
270
|
+
? openTemplate.replace("{exit}", exitLabel)
|
|
271
|
+
: `${openTemplate} · ${exitLabel}`;
|
|
272
|
+
const noticeText = state.exitChanged
|
|
273
|
+
? (typeof labels?.exitChanged === "string" && labels.exitChanged.trim()
|
|
274
|
+
? labels.exitChanged.trim()
|
|
275
|
+
: "出口已变更,关闭并重新打开浏览器后生效。")
|
|
276
|
+
: "";
|
|
277
|
+
return {
|
|
278
|
+
open: true,
|
|
279
|
+
exitChanged: state.exitChanged,
|
|
280
|
+
exitLabel,
|
|
281
|
+
statusText,
|
|
282
|
+
noticeText,
|
|
283
|
+
tone: state.exitChanged ? "warn" : "good",
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function formatNamedExit(login, directText) {
|
|
151
288
|
const region = typeof login.region === "string" ? login.region.trim() : "";
|
|
152
289
|
const name = typeof login.proxyName === "string"
|
|
153
290
|
? login.proxyName.trim()
|
|
154
291
|
: typeof login.name === "string" ? login.name.trim() : "";
|
|
155
|
-
if (!region && !name) return
|
|
292
|
+
if (!region && !name) return "";
|
|
156
293
|
if (name === "直连" || name === directText) return directText;
|
|
157
294
|
if (region && name) {
|
|
158
295
|
if (name.includes(region)) return name;
|
|
159
296
|
return `${region} · ${name}`;
|
|
160
297
|
}
|
|
161
|
-
return name || region
|
|
298
|
+
return name || region;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function formatExit(login, directText = "直连", labels = {}) {
|
|
302
|
+
if (!login || typeof login !== "object") return directText;
|
|
303
|
+
const customText =
|
|
304
|
+
typeof labels?.custom === "string" && labels.custom.trim()
|
|
305
|
+
? labels.custom.trim()
|
|
306
|
+
: "自定义出口";
|
|
307
|
+
const inheritTemplate =
|
|
308
|
+
typeof labels?.inherit === "string" && labels.inherit.trim()
|
|
309
|
+
? labels.inherit.trim()
|
|
310
|
+
: "跟随供应商({exit})";
|
|
311
|
+
const displayUrl = typeof login.displayUrl === "string" ? login.displayUrl.trim() : "";
|
|
312
|
+
const named = formatNamedExit(login, directText);
|
|
313
|
+
|
|
314
|
+
if (login.mode === "inherit") {
|
|
315
|
+
const target =
|
|
316
|
+
login.proxyId !== null && named
|
|
317
|
+
? named
|
|
318
|
+
: displayUrl
|
|
319
|
+
? displayUrl
|
|
320
|
+
: login.custom
|
|
321
|
+
? customText
|
|
322
|
+
: directText;
|
|
323
|
+
return inheritTemplate.includes("{exit}")
|
|
324
|
+
? inheritTemplate.replace("{exit}", target)
|
|
325
|
+
: `${inheritTemplate} · ${target}`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (login.custom) {
|
|
329
|
+
return displayUrl ? `${customText} · ${displayUrl}` : customText;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (login.proxyId === null) return directText;
|
|
333
|
+
return named || directText;
|
|
162
334
|
}
|
|
163
335
|
|
|
164
336
|
// The check job's exposure/summary as display lines. `labels.exposure` is a
|