mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-20 22:22:57 +03:00
This commit is contained in:
@@ -296,9 +296,14 @@ export async function createProxy(payload: ProxyPayload) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert a proxy by host+port.
|
||||
* If a proxy with the same host and port already exists, update it.
|
||||
* Otherwise, create a new one. Used by the bulk import feature.
|
||||
* Upsert a proxy by its credential tuple (host+port+username+password).
|
||||
* If a proxy with the same host, port, username AND password already exists,
|
||||
* update it. Otherwise, create a new one. Used by the bulk import feature.
|
||||
*
|
||||
* #7594: host+port alone is NOT a stable identity. Rotating residential/gateway
|
||||
* proxies route every credential through one shared host:port, so keying only on
|
||||
* host+port collapsed distinct-credential imports onto the first existing row
|
||||
* (the same entry got "updated" N times instead of N entries being created).
|
||||
*/
|
||||
export async function upsertProxy(payload: ProxyPayload): Promise<{
|
||||
proxy: ProxyRegistryRecord | null;
|
||||
@@ -307,10 +312,14 @@ export async function upsertProxy(payload: ProxyPayload): Promise<{
|
||||
const db = getDbInstance();
|
||||
const host = (payload.host || "").trim();
|
||||
const port = Number(payload.port);
|
||||
const username = (payload.username || "").trim();
|
||||
const password = (payload.password || "").trim();
|
||||
|
||||
const existing = db
|
||||
.prepare("SELECT id FROM proxy_registry WHERE host = ? AND port = ? LIMIT 1")
|
||||
.get(host, port) as { id?: string } | undefined;
|
||||
.prepare(
|
||||
"SELECT id FROM proxy_registry WHERE host = ? AND port = ? AND username = ? AND password = ? LIMIT 1"
|
||||
)
|
||||
.get(host, port, username, password) as { id?: string } | undefined;
|
||||
|
||||
if (existing?.id) {
|
||||
const updated = await updateProxy(existing.id, payload);
|
||||
|
||||
Reference in New Issue
Block a user