Compare commits
No commits in common. "5a5dcb63344e7c849343874f79c9dd554ae2f9c8cfca6f4cf883b36541e62ac8" and "6d9626eaa220039343e60859f40bebd14bdcc192095ab6b6909fb94a027c6183" have entirely different histories.
5a5dcb6334
...
6d9626eaa2
@ -8,3 +8,6 @@ WEBHOOK_TOKEN="" #Token that is placed a the TTN Webhook auth
|
|||||||
WIGLE_TOKEN="" # Go to account and generate token "Encoded for use"
|
WIGLE_TOKEN="" # Go to account and generate token "Encoded for use"
|
||||||
WIGLE_BASE_URL="https://api.wigle.net"
|
WIGLE_BASE_URL="https://api.wigle.net"
|
||||||
WIGLE_NETWORK_SEARCH="/api/v2/network/search"
|
WIGLE_NETWORK_SEARCH="/api/v2/network/search"
|
||||||
|
GET_LOCATION_WIFI_MAX_AGE=1209600000 # 14 days in milliseconds (14 * 24 * 60 * 60 * 1000)
|
||||||
|
GET_LOCATION_WIFI_MAX=10000
|
||||||
|
GET_LOCATION_WIFI_PRIMITIVE=true
|
169
server/package-lock.json
generated
169
server/package-lock.json
generated
@ -7,13 +7,14 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "locationhub",
|
"name": "locationhub",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"http-status-codes": "^2.3.0",
|
"http-status-codes": "^2.3.0",
|
||||||
"mariadb": "^3.4.0",
|
"mariadb": "^3.4.0",
|
||||||
|
"memoizee": "^0.4.17",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"sequelize": "^6.37.5",
|
"sequelize": "^6.37.5",
|
||||||
"swagger-jsdoc": "^6.2.8",
|
"swagger-jsdoc": "^6.2.8",
|
||||||
@ -23,6 +24,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
|
"@types/memoizee": "^0.4.11",
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
"nodemon": "^3.1.9",
|
"nodemon": "^3.1.9",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
@ -230,6 +232,13 @@
|
|||||||
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/memoizee": {
|
||||||
|
"version": "0.4.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/memoizee/-/memoizee-0.4.11.tgz",
|
||||||
|
"integrity": "sha512-2gyorIBZu8GoDr9pYjROkxWWcFtHCquF7TVbN2I+/OvgZhnIGQS0vX5KJz4lXNKb8XOSfxFOSG5OLru1ESqLUg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/mime": {
|
"node_modules/@types/mime": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",
|
||||||
@ -573,6 +582,19 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/d": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"es5-ext": "^0.10.64",
|
||||||
|
"type": "^2.7.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
@ -709,12 +731,79 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/es5-ext": {
|
||||||
|
"version": "0.10.64",
|
||||||
|
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz",
|
||||||
|
"integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"es6-iterator": "^2.0.3",
|
||||||
|
"es6-symbol": "^3.1.3",
|
||||||
|
"esniff": "^2.0.1",
|
||||||
|
"next-tick": "^1.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/es6-iterator": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"d": "1",
|
||||||
|
"es5-ext": "^0.10.35",
|
||||||
|
"es6-symbol": "^3.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/es6-symbol": {
|
||||||
|
"version": "3.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz",
|
||||||
|
"integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d": "^1.0.2",
|
||||||
|
"ext": "^1.7.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/es6-weak-map": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d": "1",
|
||||||
|
"es5-ext": "^0.10.46",
|
||||||
|
"es6-iterator": "^2.0.3",
|
||||||
|
"es6-symbol": "^3.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/escape-html": {
|
"node_modules/escape-html": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
||||||
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/esniff": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d": "^1.0.1",
|
||||||
|
"es5-ext": "^0.10.62",
|
||||||
|
"event-emitter": "^0.3.5",
|
||||||
|
"type": "^2.7.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/esutils": {
|
"node_modules/esutils": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
|
||||||
@ -733,6 +822,16 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/event-emitter": {
|
||||||
|
"version": "0.3.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz",
|
||||||
|
"integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"d": "1",
|
||||||
|
"es5-ext": "~0.10.14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/express": {
|
"node_modules/express": {
|
||||||
"version": "4.21.2",
|
"version": "4.21.2",
|
||||||
"resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz",
|
||||||
@ -779,6 +878,15 @@
|
|||||||
"url": "https://opencollective.com/express"
|
"url": "https://opencollective.com/express"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ext": {
|
||||||
|
"version": "1.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
|
||||||
|
"integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"type": "^2.7.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
@ -1084,6 +1192,12 @@
|
|||||||
"node": ">=0.12.0"
|
"node": ">=0.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-promise": {
|
||||||
|
"version": "2.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz",
|
||||||
|
"integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/js-yaml": {
|
"node_modules/js-yaml": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||||
@ -1126,6 +1240,15 @@
|
|||||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/lru-queue": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz",
|
||||||
|
"integrity": "sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"es5-ext": "~0.10.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/make-error": {
|
"node_modules/make-error": {
|
||||||
"version": "1.3.6",
|
"version": "1.3.6",
|
||||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||||
@ -1179,6 +1302,25 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/memoizee": {
|
||||||
|
"version": "0.4.17",
|
||||||
|
"resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.17.tgz",
|
||||||
|
"integrity": "sha512-DGqD7Hjpi/1or4F/aYAspXKNm5Yili0QDAFAY4QYvpqpgiY6+1jOfqpmByzjxbWd/T9mChbCArXAbDAsTm5oXA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d": "^1.0.2",
|
||||||
|
"es5-ext": "^0.10.64",
|
||||||
|
"es6-weak-map": "^2.0.3",
|
||||||
|
"event-emitter": "^0.3.5",
|
||||||
|
"is-promise": "^2.2.2",
|
||||||
|
"lru-queue": "^0.1.0",
|
||||||
|
"next-tick": "^1.1.0",
|
||||||
|
"timers-ext": "^0.1.7"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/merge-descriptors": {
|
"node_modules/merge-descriptors": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
||||||
@ -1278,6 +1420,12 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/next-tick": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/nodemon": {
|
"node_modules/nodemon": {
|
||||||
"version": "3.1.9",
|
"version": "3.1.9",
|
||||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.9.tgz",
|
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.9.tgz",
|
||||||
@ -1873,6 +2021,19 @@
|
|||||||
"express": ">=4.0.0 || >=5.0.0-beta"
|
"express": ">=4.0.0 || >=5.0.0-beta"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/timers-ext": {
|
||||||
|
"version": "0.1.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.8.tgz",
|
||||||
|
"integrity": "sha512-wFH7+SEAcKfJpfLPkrgMPvvwnEtj8W4IurvEyrKsDleXnKLCDw71w8jltvfLa8Rm4qQxxT4jmDBYbJG/z7qoww==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"es5-ext": "^0.10.64",
|
||||||
|
"next-tick": "^1.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/to-regex-range": {
|
"node_modules/to-regex-range": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||||
@ -1973,6 +2134,12 @@
|
|||||||
"node": ">= 6.0.0"
|
"node": ">= 6.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/type": {
|
||||||
|
"version": "2.7.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz",
|
||||||
|
"integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==",
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
"node_modules/type-is": {
|
"node_modules/type-is": {
|
||||||
"version": "1.6.18",
|
"version": "1.6.18",
|
||||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||||
|
@ -10,9 +10,10 @@
|
|||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Hendrik Schutter, Philipp Schweizer",
|
"author": "Hendrik Schutter, Philipp Schweizer",
|
||||||
"license": "MIT",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
|
"@types/memoizee": "^0.4.11",
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
"nodemon": "^3.1.9",
|
"nodemon": "^3.1.9",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
@ -24,6 +25,7 @@
|
|||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"http-status-codes": "^2.3.0",
|
"http-status-codes": "^2.3.0",
|
||||||
"mariadb": "^3.4.0",
|
"mariadb": "^3.4.0",
|
||||||
|
"memoizee": "^0.4.17",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"sequelize": "^6.37.5",
|
"sequelize": "^6.37.5",
|
||||||
"swagger-jsdoc": "^6.2.8",
|
"swagger-jsdoc": "^6.2.8",
|
||||||
|
@ -16,28 +16,11 @@ CREATE TABLE IF NOT EXISTS wifi_scan (
|
|||||||
lp_ttn_end_device_uplinks_id UUID,
|
lp_ttn_end_device_uplinks_id UUID,
|
||||||
mac VARCHAR(255),
|
mac VARCHAR(255),
|
||||||
rssi NUMERIC,
|
rssi NUMERIC,
|
||||||
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (lp_ttn_end_device_uplinks_id) REFERENCES lp_ttn_end_device_uplinks(lp_ttn_end_device_uplinks_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS wifi_location (
|
|
||||||
mac VARCHAR(255) PRIMARY KEY,
|
|
||||||
latitude DOUBLE,
|
|
||||||
longitude DOUBLE,
|
|
||||||
request_limit_exceeded boolean NOT NULL,
|
|
||||||
location_not_resolvable boolean NOT NULL,
|
|
||||||
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS wifi_location_history (
|
|
||||||
wifi_location_history_id UUID PRIMARY KEY,
|
|
||||||
mac VARCHAR(255),
|
|
||||||
latitude DOUBLE NOT NULL,
|
latitude DOUBLE NOT NULL,
|
||||||
longitude DOUBLE NOT NULL,
|
longitude DOUBLE NOT NULL,
|
||||||
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (lp_ttn_end_device_uplinks_id) REFERENCES lp_ttn_end_device_uplinks(lp_ttn_end_device_uplinks_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS ttn_gateway_reception (
|
CREATE TABLE IF NOT EXISTS ttn_gateway_reception (
|
||||||
|
@ -17,6 +17,7 @@ const ttnGatewayReceptionService = container.resolve(
|
|||||||
TtnGatewayReceptionService
|
TtnGatewayReceptionService
|
||||||
);
|
);
|
||||||
const wifiScanService = container.resolve(WifiScanService);
|
const wifiScanService = container.resolve(WifiScanService);
|
||||||
|
|
||||||
const locationService = container.resolve(LocationService);
|
const locationService = container.resolve(LocationService);
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -60,6 +61,8 @@ router.post(
|
|||||||
rssi: w.rssi,
|
rssi: w.rssi,
|
||||||
})) ?? [];
|
})) ?? [];
|
||||||
|
|
||||||
|
console.log(wifiScans);
|
||||||
|
|
||||||
const ttnGatewayReceptions = message.uplink_message.rx_metadata.map(
|
const ttnGatewayReceptions = message.uplink_message.rx_metadata.map(
|
||||||
(g) => ({
|
(g) => ({
|
||||||
lp_ttn_end_device_uplinks_id,
|
lp_ttn_end_device_uplinks_id,
|
||||||
@ -82,8 +85,9 @@ router.post(
|
|||||||
|
|
||||||
locationService.createLocationFromTriangulation({
|
locationService.createLocationFromTriangulation({
|
||||||
lp_ttn_end_device_uplinks_id,
|
lp_ttn_end_device_uplinks_id,
|
||||||
wifi: wifiResults.map(({ mac, rssi }) => ({
|
wifi: wifiResults.map(({ latitude, longitude, rssi }) => ({
|
||||||
mac,
|
latitude,
|
||||||
|
longitude,
|
||||||
rssi,
|
rssi,
|
||||||
})),
|
})),
|
||||||
ttn_gw: gatewayResults.map(({ latitude, longitude, rssi }) => ({
|
ttn_gw: gatewayResults.map(({ latitude, longitude, rssi }) => ({
|
||||||
|
@ -29,7 +29,8 @@ export function authenticateHeader(req: Request, res: Response, next: NextFuncti
|
|||||||
res.status(StatusCodes.UNAUTHORIZED).json({ error: "Authentication failed" });
|
res.status(StatusCodes.UNAUTHORIZED).json({ error: "Authentication failed" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//console.log("Bearer token is correct!");
|
console.log("Bearer token is correct!");
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(StatusCodes.INTERNAL_SERVER_ERROR)
|
res.status(StatusCodes.INTERNAL_SERVER_ERROR)
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
import { DataTypes, Model } from "sequelize";
|
|
||||||
import { sequelize } from "../database/database";
|
|
||||||
|
|
||||||
export class WifiLocation extends Model {
|
|
||||||
public mac!: string;
|
|
||||||
public latitude!: number;
|
|
||||||
public longitude!: number;
|
|
||||||
public request_limit_exceeded!: boolean;
|
|
||||||
public location_not_resolvable!: boolean;
|
|
||||||
public created_at_utc!: Date;
|
|
||||||
public updated_at_utc!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
WifiLocation.init(
|
|
||||||
{
|
|
||||||
mac: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
primaryKey: true,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
latitude: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
},
|
|
||||||
longitude: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
},
|
|
||||||
request_limit_exceeded: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false,
|
|
||||||
},
|
|
||||||
location_not_resolvable: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
defaultValue: false,
|
|
||||||
},
|
|
||||||
created_at_utc: {
|
|
||||||
type: DataTypes.DATE,
|
|
||||||
defaultValue: DataTypes.NOW,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
updated_at_utc: {
|
|
||||||
type: DataTypes.DATE,
|
|
||||||
defaultValue: DataTypes.NOW,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sequelize,
|
|
||||||
modelName: "WifiLocation",
|
|
||||||
tableName: "wifi_location",
|
|
||||||
timestamps: false,
|
|
||||||
}
|
|
||||||
);
|
|
@ -1,50 +0,0 @@
|
|||||||
import { DataTypes, Model } from "sequelize";
|
|
||||||
import { sequelize } from "../database/database";
|
|
||||||
|
|
||||||
export class WifiLocationHistory extends Model {
|
|
||||||
public wifi_location_history_id!: string;
|
|
||||||
public mac!: string;
|
|
||||||
public latitude!: number;
|
|
||||||
public longitude!: number;
|
|
||||||
public created_at_utc!: Date;
|
|
||||||
public updated_at_utc!: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
WifiLocationHistory.init(
|
|
||||||
{
|
|
||||||
wifi_location_history_id: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
mac: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
latitude: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
longitude: {
|
|
||||||
type: DataTypes.NUMBER,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
created_at_utc: {
|
|
||||||
type: DataTypes.DATE,
|
|
||||||
defaultValue: DataTypes.NOW,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
updated_at_utc: {
|
|
||||||
type: DataTypes.DATE,
|
|
||||||
defaultValue: DataTypes.NOW,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sequelize,
|
|
||||||
modelName: "WifiLocationHistory",
|
|
||||||
tableName: "wifi_location_history",
|
|
||||||
timestamps: false,
|
|
||||||
}
|
|
||||||
);
|
|
@ -6,6 +6,8 @@ export class WifiScan extends Model {
|
|||||||
public wifi_scan_id!: string;
|
public wifi_scan_id!: string;
|
||||||
public mac!: string;
|
public mac!: string;
|
||||||
public rssi!: number;
|
public rssi!: number;
|
||||||
|
public latitude!: number;
|
||||||
|
public longitude!: number;
|
||||||
public created_at_utc!: Date;
|
public created_at_utc!: Date;
|
||||||
public updated_at_utc!: Date;
|
public updated_at_utc!: Date;
|
||||||
}
|
}
|
||||||
@ -30,6 +32,14 @@ WifiScan.init(
|
|||||||
type: DataTypes.NUMBER,
|
type: DataTypes.NUMBER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
|
latitude: {
|
||||||
|
type: DataTypes.NUMBER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
longitude: {
|
||||||
|
type: DataTypes.NUMBER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
created_at_utc: {
|
created_at_utc: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
defaultValue: DataTypes.NOW,
|
defaultValue: DataTypes.NOW,
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
interface WigleApiResonse {
|
import memoizee from "memoizee";
|
||||||
response?: WifiLocationResponse,
|
|
||||||
status_code: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WifiLocationResponse {
|
interface WifiLocationResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@ -46,7 +43,7 @@ interface Result {
|
|||||||
|
|
||||||
export const getLocationForWifi = async (
|
export const getLocationForWifi = async (
|
||||||
mac: string
|
mac: string
|
||||||
): Promise<WigleApiResonse | undefined> => {
|
): Promise<WifiLocationResponse | undefined> => {
|
||||||
try {
|
try {
|
||||||
const url = `${process.env.WIGLE_BASE_URL!}${process.env
|
const url = `${process.env.WIGLE_BASE_URL!}${process.env
|
||||||
.WIGLE_NETWORK_SEARCH!}?netid=${encodeURIComponent(mac)}`;
|
.WIGLE_NETWORK_SEARCH!}?netid=${encodeURIComponent(mac)}`;
|
||||||
@ -60,12 +57,17 @@ export const getLocationForWifi = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return { status_code: response.status, response: await response.json() };
|
return await response.json();
|
||||||
}
|
}
|
||||||
console.log(response.status);
|
console.log(response.status);
|
||||||
return { status_code: response.status };
|
return undefined;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error during call of API wigle.net:", error);
|
console.error("Error during call of API wigle.net:", error);
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getLocationForWifiMemoized = memoizee(getLocationForWifi, {
|
||||||
|
maxAge: Number(process.env.GET_LOCATION_WIFI_MAX_AGE),
|
||||||
|
max: Number(process.env.GET_LOCATION_WIFI_MAX),
|
||||||
|
primitive: process.env.GET_LOCATION_WIFI_PRIMITIVE === "true",
|
||||||
|
});
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
import { Attributes, FindOptions } from "sequelize";
|
|
||||||
import { injectable } from "tsyringe";
|
|
||||||
import { WifiLocationHistory } from "../models/wifiLocationHistory";
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class WifiLocationHistoryRepository {
|
|
||||||
public async findAll() {
|
|
||||||
return await WifiLocationHistory.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findOne(options?: FindOptions<Attributes<WifiLocationHistory>>) {
|
|
||||||
return await WifiLocationHistory.findOne(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findById(id: string) {
|
|
||||||
return await WifiLocationHistory.findByPk(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async create(data: Partial<WifiLocationHistory>) {
|
|
||||||
return await WifiLocationHistory.create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createMany(data: Partial<WifiLocationHistory>[]) {
|
|
||||||
return await WifiLocationHistory.bulkCreate(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update(id: string, data: Partial<WifiLocationHistory>) {
|
|
||||||
const wifiScan = await this.findById(id);
|
|
||||||
if (wifiScan) {
|
|
||||||
return await wifiScan.update(data);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async delete(id: string) {
|
|
||||||
const wifiScan = await this.findById(id);
|
|
||||||
if (wifiScan) {
|
|
||||||
await wifiScan.destroy();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
import { Attributes, FindOptions } from "sequelize";
|
|
||||||
import { injectable } from "tsyringe";
|
|
||||||
import { WifiLocation } from "../models/wifiLocation";
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class WifiLocationRepository {
|
|
||||||
public async findAll(options?: FindOptions<Attributes<WifiLocation>>) {
|
|
||||||
return await WifiLocation.findAll(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async findById(id: string) {
|
|
||||||
return await WifiLocation.findByPk(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async create(data: Partial<WifiLocation>) {
|
|
||||||
return await WifiLocation.create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createMany(data: Partial<WifiLocation>[]) {
|
|
||||||
return await WifiLocation.bulkCreate(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update(id: string, data: Partial<WifiLocation>) {
|
|
||||||
const wifiScan = await this.findById(id);
|
|
||||||
if (wifiScan) {
|
|
||||||
return await wifiScan.update(data);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async delete(id: string) {
|
|
||||||
const wifiScan = await this.findById(id);
|
|
||||||
if (wifiScan) {
|
|
||||||
await wifiScan.destroy();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
import { inject, injectable } from "tsyringe";
|
import { inject, injectable } from "tsyringe";
|
||||||
import { Location } from "../models/location";
|
import { Location } from "../models/location";
|
||||||
import { LocationRepository } from "../repositories/locationRepository";
|
import { LocationRepository } from "../repositories/locationRepository";
|
||||||
import { WifiLocationService } from "./wifiLocationService";
|
|
||||||
|
|
||||||
interface CreateLocationParams {
|
interface CreateLocationParams {
|
||||||
lp_ttn_end_device_uplinks_id: string;
|
lp_ttn_end_device_uplinks_id: string;
|
||||||
@ -12,10 +11,7 @@ interface CreateLocationParams {
|
|||||||
|
|
||||||
interface CreateLocationTriangulationParams {
|
interface CreateLocationTriangulationParams {
|
||||||
lp_ttn_end_device_uplinks_id: string;
|
lp_ttn_end_device_uplinks_id: string;
|
||||||
wifi: {
|
wifi: LocationSignal[];
|
||||||
mac: string;
|
|
||||||
rssi: number;
|
|
||||||
}[];
|
|
||||||
ttn_gw: LocationSignal[];
|
ttn_gw: LocationSignal[];
|
||||||
gnss?: Coordinates;
|
gnss?: Coordinates;
|
||||||
}
|
}
|
||||||
@ -43,10 +39,8 @@ interface UpdateTtnGatewayReceptionParams {
|
|||||||
export class LocationService {
|
export class LocationService {
|
||||||
constructor(
|
constructor(
|
||||||
@inject(LocationRepository)
|
@inject(LocationRepository)
|
||||||
private repository: LocationRepository,
|
private repository: LocationRepository
|
||||||
@inject(WifiLocationService)
|
) {}
|
||||||
private wifiLocationService: WifiLocationService
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public async getAllLocations() {
|
public async getAllLocations() {
|
||||||
return this.repository.findAll();
|
return this.repository.findAll();
|
||||||
@ -71,9 +65,7 @@ export class LocationService {
|
|||||||
public async createLocationFromTriangulation(
|
public async createLocationFromTriangulation(
|
||||||
data: CreateLocationTriangulationParams
|
data: CreateLocationTriangulationParams
|
||||||
) {
|
) {
|
||||||
const wifi_location = this.calculateVirtualLocation(
|
const wifi_location = this.calculateVirtualLocation(data.wifi);
|
||||||
await this.enrichWifiObjectWithLocation(data.wifi)
|
|
||||||
);
|
|
||||||
const gateway_location = this.calculateVirtualLocation(data.ttn_gw);
|
const gateway_location = this.calculateVirtualLocation(data.ttn_gw);
|
||||||
|
|
||||||
return this.createLocation({
|
return this.createLocation({
|
||||||
@ -92,29 +84,6 @@ export class LocationService {
|
|||||||
return this.repository.delete(id);
|
return this.repository.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async enrichWifiObjectWithLocation(
|
|
||||||
wifis: CreateLocationTriangulationParams["wifi"]
|
|
||||||
) {
|
|
||||||
const enrichedWifi = await Promise.all(
|
|
||||||
wifis.map(async (wifi) => {
|
|
||||||
const location = await this.wifiLocationService.getWifiLocationByMac(
|
|
||||||
wifi.mac
|
|
||||||
);
|
|
||||||
|
|
||||||
return location?.latitude !== undefined &&
|
|
||||||
location.longitude !== undefined
|
|
||||||
? {
|
|
||||||
rssi: wifi.rssi,
|
|
||||||
latitude: location.latitude,
|
|
||||||
longitude: location.longitude,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return enrichedWifi.filter((wifi) => wifi !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private calculateVirtualLocation(locations: LocationSignal[]) {
|
private calculateVirtualLocation(locations: LocationSignal[]) {
|
||||||
if (locations.length === 0) return undefined;
|
if (locations.length === 0) return undefined;
|
||||||
|
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
import { inject, injectable } from "tsyringe";
|
|
||||||
import { WifiLocationHistoryRepository } from "../repositories/wifiLocationHistoryRepository";
|
|
||||||
|
|
||||||
interface CreateWifiLocationHistoryParams {
|
|
||||||
mac: string;
|
|
||||||
latitude: number;
|
|
||||||
longitude: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UpdateWifiLocationHistoryParams {
|
|
||||||
mac: string;
|
|
||||||
latitude: number;
|
|
||||||
longitude: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class WifiLocationHistoryService {
|
|
||||||
constructor(
|
|
||||||
@inject(WifiLocationHistoryRepository)
|
|
||||||
private repository: WifiLocationHistoryRepository
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public async getAllWifiLocationHistories() {
|
|
||||||
return this.repository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getWifiLocationHistoryById(id: string) {
|
|
||||||
return this.repository.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createWifiLocationHistory(
|
|
||||||
data: CreateWifiLocationHistoryParams
|
|
||||||
) {
|
|
||||||
const existingEntry = await this.repository.findOne({
|
|
||||||
where: {
|
|
||||||
mac: data.mac,
|
|
||||||
},
|
|
||||||
order: [["updated_at_utc", "DESC"]],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!existingEntry || existingEntry.latitude !== data.latitude || existingEntry.longitude !== data.longitude) {
|
|
||||||
return await this.repository.create(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return existingEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async updateWifiLocationHistory(
|
|
||||||
data: UpdateWifiLocationHistoryParams
|
|
||||||
) {
|
|
||||||
return this.repository.update(data.mac, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async deleteWifiLocationHistory(id: string) {
|
|
||||||
return this.repository.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
import { Op } from "sequelize";
|
|
||||||
import { inject, injectable } from "tsyringe";
|
|
||||||
import { getLocationForWifi } from "../proxy/wigle";
|
|
||||||
import { WifiLocationRepository } from "../repositories/wifiLocationRepository";
|
|
||||||
import { WifiLocationHistoryService } from "./wifiLocationHistoryService";
|
|
||||||
import { StatusCodes } from "http-status-codes";
|
|
||||||
|
|
||||||
interface UpdateWifiLocationParams {
|
|
||||||
mac: string;
|
|
||||||
latitude: number;
|
|
||||||
longitude: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class WifiLocationService {
|
|
||||||
constructor(
|
|
||||||
@inject(WifiLocationRepository) private repository: WifiLocationRepository,
|
|
||||||
@inject(WifiLocationHistoryService)
|
|
||||||
private wifiLocationHistory: WifiLocationHistoryService
|
|
||||||
) { }
|
|
||||||
|
|
||||||
public async getAllWifiLocations() {
|
|
||||||
return this.repository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getAllWifiLocationsByAddresses(macAddresses: string[]) {
|
|
||||||
return this.repository.findAll({
|
|
||||||
where: { mac: { [Op.in]: macAddresses } },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getWifiLocationByMac(mac: string) {
|
|
||||||
let wifiLocation = await this.repository.findById(mac);
|
|
||||||
|
|
||||||
if (wifiLocation) return wifiLocation;
|
|
||||||
|
|
||||||
const apiResponse = await getLocationForWifi(mac);
|
|
||||||
|
|
||||||
if (apiResponse == undefined) {
|
|
||||||
await this.repository.create({
|
|
||||||
mac,
|
|
||||||
});
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiResponse.response == undefined) {
|
|
||||||
const request_limit_exceeded = apiResponse.status_code === StatusCodes.TOO_MANY_REQUESTS;
|
|
||||||
await this.repository.create({
|
|
||||||
mac,
|
|
||||||
request_limit_exceeded,
|
|
||||||
});
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiResponse.response.totalResults == 0) {
|
|
||||||
await this.repository.create({ mac, location_not_resolvable: true });
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
wifiLocation = await this.repository.create({
|
|
||||||
mac,
|
|
||||||
latitude: apiResponse.response.results[0].trilat,
|
|
||||||
longitude: apiResponse.response.results[0].trilong,
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.wifiLocationHistory.createWifiLocationHistory(
|
|
||||||
wifiLocation.dataValues
|
|
||||||
);
|
|
||||||
|
|
||||||
return wifiLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async updateWifiLocation(data: UpdateWifiLocationParams) {
|
|
||||||
return this.repository.update(data.mac, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async deleteWifiLocation(id: string) {
|
|
||||||
return this.repository.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
import { inject, injectable } from "tsyringe";
|
import { inject, injectable } from "tsyringe";
|
||||||
|
import { getLocationForWifiMemoized } from "../proxy/wigle";
|
||||||
import { WifiScanRepository } from "../repositories/wifiScanRepository";
|
import { WifiScanRepository } from "../repositories/wifiScanRepository";
|
||||||
|
|
||||||
interface CreateWifiScanParams {
|
interface CreateWifiScanParams {
|
||||||
@ -11,6 +12,8 @@ interface UpdateWifiScanParams {
|
|||||||
wifi_scan_id: string;
|
wifi_scan_id: string;
|
||||||
mac?: string;
|
mac?: string;
|
||||||
rssi?: number;
|
rssi?: number;
|
||||||
|
latitude?: number;
|
||||||
|
longitude?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
@ -28,11 +31,23 @@ export class WifiScanService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createWifiScan(data: CreateWifiScanParams) {
|
public async createWifiScan(data: CreateWifiScanParams) {
|
||||||
return this.repository.create(data);
|
const apiResponse = await getLocationForWifiMemoized(data.mac);
|
||||||
|
|
||||||
|
if (apiResponse !== undefined && apiResponse.results.length > 0)
|
||||||
|
return this.repository.create({
|
||||||
|
...data,
|
||||||
|
latitude: apiResponse.results[0].trilat,
|
||||||
|
longitude: apiResponse.results[0].trilong,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createWifiScans(data: CreateWifiScanParams[]) {
|
public async createWifiScans(data: CreateWifiScanParams[]) {
|
||||||
return await this.repository.createMany(data);
|
let wifiScans = await Promise.all(
|
||||||
|
data.map(async (wifi) => {
|
||||||
|
return await this.createWifiScan(wifi);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return wifiScans.filter((wifi) => wifi !== undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateWifiScan(data: UpdateWifiScanParams) {
|
public async updateWifiScan(data: UpdateWifiScanParams) {
|
||||||
|
Loading…
Reference in New Issue
Block a user