Merge remote-tracking branch 'origin' into feat-pedidos
This commit is contained in:
@@ -526,10 +526,97 @@ async function obterLocalizacaoMultipla(): Promise<{
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtém localização via GPS de forma rápida (uma única leitura, sem reverse geocoding)
|
||||
* Usado para login - não bloqueia o fluxo
|
||||
*/
|
||||
export async function obterLocalizacaoRapida(): Promise<{
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
precisao?: number;
|
||||
endereco?: string;
|
||||
cidade?: string;
|
||||
estado?: string;
|
||||
pais?: string;
|
||||
}> {
|
||||
if (typeof navigator === 'undefined' || !navigator.geolocation) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
// Uma única leitura rápida com timeout curto
|
||||
const leitura = await capturarLocalizacaoUnica(true, 3000); // 3 segundos máximo
|
||||
|
||||
if (!leitura.latitude || !leitura.longitude || leitura.confiabilidade === 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Tentar obter endereço via reverse geocoding (com timeout curto)
|
||||
let endereco = '';
|
||||
let cidade = '';
|
||||
let estado = '';
|
||||
let pais = '';
|
||||
|
||||
try {
|
||||
const geocodePromise = fetch(
|
||||
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${leitura.latitude}&lon=${leitura.longitude}&zoom=18&addressdetails=1`,
|
||||
{
|
||||
headers: {
|
||||
'User-Agent': 'SGSE-App/1.0'
|
||||
}
|
||||
}
|
||||
);
|
||||
const geocodeTimeout = new Promise<Response>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Timeout')), 2000)
|
||||
);
|
||||
|
||||
const response = await Promise.race([geocodePromise, geocodeTimeout]);
|
||||
|
||||
if (response.ok) {
|
||||
const data = (await response.json()) as {
|
||||
address?: {
|
||||
road?: string;
|
||||
house_number?: string;
|
||||
city?: string;
|
||||
town?: string;
|
||||
state?: string;
|
||||
country?: string;
|
||||
};
|
||||
};
|
||||
if (data.address) {
|
||||
const addr = data.address;
|
||||
if (addr.road) {
|
||||
endereco = `${addr.road}${addr.house_number ? `, ${addr.house_number}` : ''}`;
|
||||
}
|
||||
cidade = addr.city || addr.town || '';
|
||||
estado = addr.state || '';
|
||||
pais = addr.country || '';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignorar erro de geocoding - não é crítico
|
||||
console.warn('Erro ao obter endereço (não crítico):', error);
|
||||
}
|
||||
|
||||
return {
|
||||
latitude: leitura.latitude,
|
||||
longitude: leitura.longitude,
|
||||
precisao: leitura.precisao,
|
||||
endereco,
|
||||
cidade,
|
||||
estado,
|
||||
pais
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn('Erro ao obter localização rápida:', error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtém localização via GPS com múltiplas tentativas e validações anti-spoofing
|
||||
*/
|
||||
async function obterLocalizacao(): Promise<{
|
||||
export async function obterLocalizacao(): Promise<{
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
precisao?: number;
|
||||
@@ -644,7 +731,7 @@ async function obterLocalizacao(): Promise<{
|
||||
/**
|
||||
* Obtém IP público
|
||||
*/
|
||||
async function obterIPPublico(): Promise<string | undefined> {
|
||||
export async function obterIPPublico(): Promise<string | undefined> {
|
||||
try {
|
||||
const response = await fetch('https://api.ipify.org?format=json');
|
||||
if (response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user