1
0
Эх сурвалжийг харах

Fixes #13 Add city names and geo admin zone info to meta

isundil 1 жил өмнө
parent
commit
535cd9c92e

+ 1 - 1
model/mediaService.js

@@ -34,7 +34,7 @@ MediaStruct.prototype.pushMeta = function(key, value) {
         else if (['geoHash', 'gpsLocation'].indexOf(key) >= 0)
             type = 'geoData';
         else if (['artist', 'camera', 'lensModel', 'exposureTimeStr', 'libraryPath', 'compression',
-                'software', 'geoCountry'].indexOf(key) >= 0)
+                'software', 'geoCountry', 'geoAdmin', 'geoCity'].indexOf(key) >= 0)
             type = 'string';
         else if (['fileSize'].indexOf(key) >= 0)
             type = 'octet';

+ 5 - 5
package.json

@@ -16,19 +16,19 @@
     "@dashboardcode/bsmultiselect": "^1.1.18",
     "@mdi/font": "^7.3.67",
     "@popperjs/core": "^2.11.8",
+    "whiskers": "^0.4.0",
     "bootstrap": "^5.3.2",
     "bootstrap-icons": "^1.11.2",
     "craftlabhttpserver": "git:isundil/craftlabHttpServer",
     "crypto": "^1.0.1",
-    "geo-reverse": "^1.0.13",
-    "geokit": "^1.1.0",
-    "imagemagick": "^0.1.3",
     "ldap": "^0.7.1",
     "ldapjs": "^3.0.4",
+    "geokit": "^1.1.0",
+    "offline-geocoder": "^1.0.0",
+    "imagemagick": "^0.1.3",
     "mime-types": "^2.1.35",
     "node-simple-router": "^0.10.2",
     "sqlite3": "^5.1.6",
-    "tmp": "^0.2.1",
-    "whiskers": "^0.4.0"
+    "tmp": "^0.2.1"
   }
 }

+ 16 - 6
src/filetype/imagemagick.js

@@ -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)

BIN
static/db.sqlite