diff --git a/server.js b/server.js index 10d73c0..5b11ffe 100644 --- a/server.js +++ b/server.js @@ -497,7 +497,28 @@ async function extractMetadata(buf) { if (exif.Photo?.FNumber) removed["Aperture"] = `f/${exif.Photo.FNumber}`; if (exif.Photo?.ISOSpeedRatings) removed["ISO"] = String(exif.Photo.ISOSpeedRatings); if (exif.Photo?.FocalLength) removed["Focal Length"] = `${exif.Photo.FocalLength}mm`; - if (exif.GPSInfo?.GPSLatitude) removed["GPS Location"] = "Removed ⚠️"; + if (exif.GPSInfo?.GPSLatitude && exif.GPSInfo?.GPSLongitude) { + const lat = exif.GPSInfo.GPSLatitude; + const lng = exif.GPSInfo.GPSLongitude; + const latRef = exif.GPSInfo.GPSLatitudeRef || "N"; + const lngRef = exif.GPSInfo.GPSLongitudeRef || "E"; + const latVal = typeof lat === "number" ? lat : (lat[0] + lat[1] / 60 + lat[2] / 3600); + const lngVal = typeof lng === "number" ? lng : (lng[0] + lng[1] / 60 + lng[2] / 3600); + const latFinal = latRef === "S" ? -latVal : latVal; + const lngFinal = lngRef === "W" ? -lngVal : lngVal; + let loc = `${latFinal.toFixed(4)}, ${lngFinal.toFixed(4)}`; + try { + const geoRes = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latFinal}&lon=${lngFinal}&format=json&zoom=14`, { + headers: { "User-Agent": "PostConvert/1.0" }, + signal: AbortSignal.timeout(3000), + }); + if (geoRes.ok) { + const geo = await geoRes.json(); + if (geo.display_name) loc = geo.display_name; + } + } catch {} + removed["GPS Location"] = loc + " — Removed!"; + } if (exif.Photo?.ImageUniqueID) removed["Unique ID"] = "Removed"; if (exif.Image?.HostComputer) removed["Device"] = String(exif.Image.HostComputer); } catch {}