Files
OmniRoute/src/lib/db/oneproxy.ts
Diego Rodrigues de Sa e Souza 412298b624 chore(proxy): purge the legacy 1proxy residue — sync/rotator modules, dead DB exports, dead settings tab and flag, docs (#12091) (#12290)
The 1proxy marketplace integration was decommissioned in v3.8.4; the code
survived only through the localDb barrel, deleted in #12055. Everything below
had zero consumers (grep-proven across src/, open-sse/, bin/, electron/,
scripts/ and tests/):

- src/lib/oneproxySync.ts and src/lib/oneproxyRotator.ts deleted.
- src/lib/db/oneproxy.ts: upsertOneproxyProxy, getOneproxyProxyById,
  getOneproxyProxyForRotation and markOneproxyProxyFailed removed (their only
  consumers were the two deleted modules); listOneproxyProxies and the record
  interface stay — open-sse/utils/proxyFallback.ts still uses them.
- src/shared/validation/oneproxySchemas.ts and the unmounted
  settings/components/OneproxyTab.tsx deleted (no importer anywhere; the live
  UI is the FreePool* tabs over /api/settings/free-proxies).
- ONEPROXY_ENABLED feature flag removed (readerless since oneproxySync died —
  the toggle no longer controlled anything); flag-count contract test aligned
  54 → 53.
- Docs: PROXY_GUIDE (component rows, env rows, the three omniroute/
  oneproxyRotator snippet sections), CODEBASE_DOCUMENTATION, REPOSITORY_MAP,
  ENVIRONMENT (ONEPROXY_* rows), FEATURE_FLAGS, .env.example — canonical +
  pl/zh-CN/zh-TW mirrors.
- The 308 compat redirects under /api/settings/oneproxy/ stay (deliberate API
  compat), as do the live free-proxy provider and proxy_registry rows.

check:dead-code drops 424 → 417 (baseline kept at the velocity-phase 500 —
banking shrinks is paused until v4.0, headroom grows to 16.6%).
check:docs-all, check:env-doc-sync, typecheck:core and the 8 free-proxy/
proxy-fallback test files are green.

Closes #12091
2026-09-01 09:22:26 -03:00

86 lines
2.6 KiB
TypeScript

import { getDbInstance } from "./core";
type JsonRecord = Record<string, unknown>;
export interface OneproxyProxyRecord {
id: string;
name: string;
type: string;
host: string;
port: number;
region: string | null;
notes: string | null;
status: string;
source: string;
qualityScore: number | null;
latencyMs: number | null;
anonymity: string | null;
googleAccess: boolean;
lastValidated: string | null;
countryCode: string | null;
createdAt: string;
updatedAt: string;
}
function toRecord(value: unknown): JsonRecord {
return value && typeof value === "object" ? (value as JsonRecord) : {};
}
function mapProxyRow(row: unknown): OneproxyProxyRecord {
const r = toRecord(row);
return {
id: typeof r.id === "string" ? r.id : "",
name: typeof r.name === "string" ? r.name : "",
type: typeof r.type === "string" ? r.type : "http",
host: typeof r.host === "string" ? r.host : "",
port: Number(r.port) || 0,
region: typeof r.region === "string" ? r.region : null,
notes: typeof r.notes === "string" ? r.notes : null,
status: typeof r.status === "string" ? r.status : "active",
source: typeof r.source === "string" ? r.source : "oneproxy",
qualityScore: typeof r.quality_score === "number" ? r.quality_score : null,
latencyMs: typeof r.latency_ms === "number" ? r.latency_ms : null,
anonymity: typeof r.anonymity === "string" ? r.anonymity : null,
googleAccess: r.google_access === 1 || r.google_access === true,
lastValidated: typeof r.last_validated === "string" ? r.last_validated : null,
countryCode: typeof r.country_code === "string" ? r.country_code : null,
createdAt: typeof r.created_at === "string" ? r.created_at : "",
updatedAt: typeof r.updated_at === "string" ? r.updated_at : "",
};
}
export async function listOneproxyProxies(options?: {
protocol?: string;
countryCode?: string;
minQuality?: number;
limit?: number;
}): Promise<OneproxyProxyRecord[]> {
const db = getDbInstance();
let sql = "SELECT * FROM proxy_registry WHERE source = 'oneproxy' AND status = 'active'";
const params: unknown[] = [];
if (options?.protocol) {
sql += " AND type = ?";
params.push(options.protocol);
}
if (options?.countryCode) {
sql += " AND country_code = ?";
params.push(options.countryCode);
}
if (options?.minQuality != null) {
sql += " AND quality_score >= ?";
params.push(options.minQuality);
}
sql += " ORDER BY quality_score DESC, last_validated DESC";
if (options?.limit) {
sql += " LIMIT ?";
params.push(options.limit);
}
const rows = db.prepare(sql).all(...params);
return rows.map(mapProxyRow);
}