|
|
@@ -3,7 +3,7 @@ const fs = require('fs');
|
|
|
const tmp = require('tmp');
|
|
|
const im = require('imagemagick');
|
|
|
const geokit = require('geokit');
|
|
|
-const geoRev = require('geo-reverse');
|
|
|
+const geocoder = require('offline-geocoder')({ database: 'static/db.sqlite'});
|
|
|
|
|
|
function readMeta(path) {
|
|
|
return new Promise((ok, ko) => {
|
|
|
@@ -94,10 +94,17 @@ ExifGps.prototype.toGeoHash = function() {
|
|
|
return geokit.hash({lat: this.data.lat, lng: this.data.lon});
|
|
|
}
|
|
|
|
|
|
-ExifGps.prototype.toCountry = function() {
|
|
|
- if (!this.data)
|
|
|
- return undefined;
|
|
|
- return geoRev.country(this.data.lat, this.data.lon)[0]?.name;
|
|
|
+ExifGps.prototype.toAddress = function() {
|
|
|
+ return new Promise(async (ok, ko) => {
|
|
|
+ if (!this.data)
|
|
|
+ return ok(undefined);
|
|
|
+ const data = await geocoder.reverse(this.data.lat, this.data.lon);
|
|
|
+ ok({
|
|
|
+ city: data?.name,
|
|
|
+ admin: data?.admin1?.name,
|
|
|
+ country: data?.country?.name
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function readTags(data) {
|
|
|
@@ -131,7 +138,10 @@ module.exports.parse = async (fileObj) => {
|
|
|
const gpsData = new ExifGps(imdata);
|
|
|
result.gpsLocation = gpsData.toGps();
|
|
|
result.geoHash = gpsData.toGeoHash();
|
|
|
- result.geoCountry = gpsData.toCountry();
|
|
|
+ const address = await gpsData.toAddress();
|
|
|
+ result.geoCountry = address?.country;
|
|
|
+ result.geoAdmin = address?.admin;
|
|
|
+ result.geoCity = address?.city;
|
|
|
result.tags = readTags(imdata);
|
|
|
for (let i of Object.keys(result))
|
|
|
if (result[i] === undefined || result[i].length === 0)
|