File size: 1,900 Bytes
98277cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { apiGetWrapped, apiPostWrapped } from './api'

export type AccountSnapshotItem = {
  id: string
  tags: string[]
  risk_score: number
  enabled: boolean
  available: boolean
  cooldown_remaining_s: number
  cooldown_until: string | null
  last_error_kind: string | null
  last_error_at: string | null
}

export type AccountPoolSnapshotResponse = {
  now: string
  accounts: AccountSnapshotItem[]
  seed: number
}

export type SessionLightReport = {
  id: string
  account_id: string | null
  has_cookie: boolean
  has_storage_state: boolean
  cookie_ok: boolean
  storage_state_ok: boolean
  cookie_reason: string | null
  storage_state_reason: string | null
  checked_at: string
}

export type SessionPoolLightCheckResponse = {
  now: string
  sessions: SessionLightReport[]
}

export type ProxyPoolSnapshotResponse = {
  available_count: number
  avg_score: number
  ejected_total: number
  failures_total_by_reason: Record<string, number>
  recent_failures_by_reason: Record<string, number>
  last_fail_reasons_by_reason: Record<string, number>
}

export async function getResourceAccounts() {
  return apiGetWrapped<AccountPoolSnapshotResponse>('resources/accounts')
}

export async function getResourceSessions() {
  return apiGetWrapped<SessionPoolLightCheckResponse>('resources/sessions')
}

export async function getResourceProxies() {
  return apiGetWrapped<ProxyPoolSnapshotResponse>('resources/proxies')
}

export async function cooldownAccount(accountId: string, seconds: number) {
  return apiPostWrapped<{ account_id: string, cooldown_seconds: number }, { seconds: number }>(
    `resources/accounts/${encodeURIComponent(accountId)}/cooldown`,
    { seconds }
  )
}

export async function disableAccount(accountId: string) {
  return apiPostWrapped<{ account_id: string, disabled: boolean }, {}>(
    `resources/accounts/${encodeURIComponent(accountId)}/disable`,
    {}
  )
}