(server)
| 171 | } |
| 172 | |
| 173 | function normalizeDoHServerForStorage(server) { |
| 174 | if (!server || typeof server !== 'object') return null; |
| 175 | const name = typeof server.name === 'string' ? server.name.trim() : ''; |
| 176 | const url = typeof server.url === 'string' ? server.url.trim() : ''; |
| 177 | if (!name || !url) return null; |
| 178 | |
| 179 | try { |
| 180 | const parsedUrl = new URL(url); |
| 181 | if (parsedUrl.protocol !== 'https:') return null; |
| 182 | } catch { |
| 183 | return null; |
| 184 | } |
| 185 | |
| 186 | const defaultServer = findDefaultDoHServer({ name, url }); |
| 187 | const countryCode = normalizeCountryCode(server.countryCode) || (defaultServer && defaultServer.countryCode) || ''; |
| 188 | const country = typeof server.country === 'string' && server.country.trim() |
| 189 | ? server.country.trim() |
| 190 | : (defaultServer && defaultServer.country) || ''; |
| 191 | |
| 192 | const normalized = { name, url }; |
| 193 | if (countryCode && country) { |
| 194 | normalized.countryCode = countryCode; |
| 195 | normalized.country = country; |
| 196 | } |
| 197 | if (server.type === 'get' || server.type === 'post') normalized.type = server.type; |
| 198 | if (typeof server.allowCors === 'boolean') normalized.allowCors = server.allowCors; |
| 199 | normalized.ips = Array.isArray(server.ips) |
| 200 | ? server.ips.filter(ip => typeof ip === 'string' && ip.trim()).map(ip => ip.trim()) |
| 201 | : []; |
| 202 | return normalized; |
| 203 | } |
| 204 | |
| 205 | function dedupeDoHServers(servers) { |
| 206 | const seenNames = new Set(); |
nothing calls this directly
no test coverage detected