@gruu6y/page-clean-login 0.2.6 → 0.2.8

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.
@@ -34,8 +34,19 @@ export function accountView(account) {
34
34
  ? value.lastCheck
35
35
  : checks[0] || null;
36
36
  const note = typeof value.note === "string" ? value.note : "";
37
+ const email = typeof value.email === "string" ? value.email.trim() : "";
38
+ const methodLabel = typeof value.methodLabel === "string" ? value.methodLabel.trim() : "";
37
39
  const unverified = Boolean(value.unverified);
38
40
  const hosting = normalizeHosting(value.hosting);
41
+ const rawExpiry = value.expiresAt ?? hosting.expiresAt;
42
+ const expiresAt = (() => {
43
+ if (typeof rawExpiry === "string" && rawExpiry.trim()) return rawExpiry.trim();
44
+ if (typeof rawExpiry === "number" && Number.isFinite(rawExpiry) && rawExpiry > 0) {
45
+ const date = new Date(rawExpiry);
46
+ return Number.isNaN(date.getTime()) ? null : date.toISOString();
47
+ }
48
+ return null;
49
+ })();
39
50
 
40
51
  return {
41
52
  name,
@@ -43,9 +54,12 @@ export function accountView(account) {
43
54
  providerLabel,
44
55
  key,
45
56
  uid,
57
+ email,
58
+ methodLabel,
46
59
  fingerprint,
47
60
  signedIn,
48
61
  signedInAt,
62
+ expiresAt,
49
63
  lastLogin,
50
64
  exit,
51
65
  lastCheck,
@@ -173,7 +187,68 @@ export function formatCheckSummary(check, labels = {}) {
173
187
  return lines;
174
188
  }
175
189
 
176
- export function filterAccounts(accounts, { query = "", filter = "all", provider = ALL_PROVIDERS } = {}) {
190
+ export const EXPIRING_SOON_MS = 24 * 60 * 60 * 1000;
191
+
192
+ export function isHostingPaused(account) {
193
+ return accountView(account).hosting.state === "paused";
194
+ }
195
+
196
+ export function formatExpiryBadge(expiresAt, nowMs = Date.now(), labels = {}) {
197
+ const expiryMs =
198
+ typeof expiresAt === "number" && Number.isFinite(expiresAt) && expiresAt > 0
199
+ ? expiresAt
200
+ : typeof expiresAt === "string" && expiresAt.trim()
201
+ ? Date.parse(expiresAt.trim())
202
+ : NaN;
203
+ if (!Number.isFinite(expiryMs) || expiryMs <= 0) {
204
+ return { state: "none", label: "", tone: "none" };
205
+ }
206
+ const diff = expiryMs - nowMs;
207
+ if (diff <= 0) {
208
+ return {
209
+ state: "expired",
210
+ label: labels.expired || "已过期",
211
+ tone: "bad",
212
+ };
213
+ }
214
+ if (diff <= EXPIRING_SOON_MS) {
215
+ const hours = Math.max(1, Math.ceil(diff / 3_600_000));
216
+ const template = labels.soon || "{hours} 小时后到期";
217
+ return {
218
+ state: "soon",
219
+ label: template.replace("{hours}", String(hours)),
220
+ tone: "warn",
221
+ };
222
+ }
223
+ const days = Math.max(1, Math.floor(diff / 86_400_000));
224
+ const template = labels.ok || "{days} 天后到期";
225
+ return {
226
+ state: "ok",
227
+ label: template.replace("{days}", String(days)),
228
+ tone: "good",
229
+ };
230
+ }
231
+
232
+ export function countAccountsByProxy(accounts = []) {
233
+ const counts = {};
234
+ for (const account of Array.isArray(accounts) ? accounts : []) {
235
+ if (!account || typeof account !== "object") continue;
236
+ const current = account.exit && typeof account.exit === "object"
237
+ ? account.exit
238
+ : account.lastLogin && typeof account.lastLogin === "object"
239
+ ? account.lastLogin
240
+ : null;
241
+ const proxyId = typeof current?.proxyId === "string" ? current.proxyId.trim() : "";
242
+ if (!proxyId) continue;
243
+ counts[proxyId] = (counts[proxyId] || 0) + 1;
244
+ }
245
+ return counts;
246
+ }
247
+
248
+ export function filterAccounts(
249
+ accounts,
250
+ { query = "", filter = "all", provider = ALL_PROVIDERS, nowMs = Date.now() } = {},
251
+ ) {
177
252
  const list = Array.isArray(accounts) ? accounts : [];
178
253
  const normalizedQuery = typeof query === "string" ? query.trim().toLowerCase() : "";
179
254
 
@@ -181,6 +256,12 @@ export function filterAccounts(accounts, { query = "", filter = "all", provider
181
256
  const view = accountView(account);
182
257
  if (filter === "signedIn" && !view.signedIn) return false;
183
258
  if (filter === "signedOut" && view.signedIn) return false;
259
+ if (filter === "hostingPaused" && view.hosting.state !== "paused") return false;
260
+ if (filter === "hostingActive" && !view.hosting.enabled) return false;
261
+ if (filter === "expiringSoon") {
262
+ const expiry = formatExpiryBadge(view.expiresAt, nowMs);
263
+ if (expiry.state !== "soon" && expiry.state !== "expired") return false;
264
+ }
184
265
  if (provider !== ALL_PROVIDERS) {
185
266
  const accountProvider = typeof view.provider === "string" ? view.provider.trim() : "";
186
267
  if (provider === UNKNOWN_PROVIDER) {
@@ -196,11 +277,12 @@ export function filterAccounts(accounts, { query = "", filter = "all", provider
196
277
  view.name,
197
278
  view.key,
198
279
  view.uid,
280
+ view.email,
199
281
  view.provider,
200
282
  view.providerLabel,
201
283
  view.note,
202
284
  view.fingerprint.id,
203
- formatExit(view.lastLogin, ""),
285
+ formatExit(view.exit ?? view.lastLogin, ""),
204
286
  ]
205
287
  .filter(Boolean)
206
288
  .join(" ")