Update dependencies and remove unused tracks API

master
Manuel Kasper 2023-12-28 15:53:22 +01:00
rodzic 5e764a7ade
commit 157eb20bca
6 zmienionych plików z 4029 dodań i 2923 usunięć

6821
package-lock.json wygenerowano

Plik diff jest za duży Load Diff

Wyświetl plik

@ -9,8 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@turf/simplify": "^5.1.5",
"axios": "^0.21.1",
"axios": "^1.6.3",
"carrier": "^0.3.0",
"csv-parse": "^5.3.0",
"diacritics": "^1.3.0",
@ -19,7 +18,7 @@
"express": "^4.17.1",
"express-bearer-token": "^2.4.0",
"express-cache-controller": "^1.1.0",
"express-jwt": "^5.3.1",
"express-jwt": "^8.4.1",
"express-validator": "^6.10.0",
"express-ws": "^4.0.0",
"geolite2-redist": "^3.0.2",
@ -34,9 +33,7 @@
"node-cron": "^3.0.1",
"promise-retry": "^2.0.1",
"reconnect-net": "^1.1.1",
"sharp": "^0.30.7",
"togeojson": "^0.16.0",
"togpx": "^0.5.4",
"sharp": "^0.33.1",
"treemap-js": "^1.2.1"
}
}

Wyświetl plik

@ -15,7 +15,6 @@ const users = require('./users');
const activations = require('./activations');
const utils = require('./utils');
const photos_router = require('./photos_router');
const tracks_router = require('./tracks_router');
const solardata = require('./solardata');
const maxmind = require('maxmind');
const cronjobs = require('./cronjobs');
@ -51,7 +50,6 @@ app.use('/geoexport', geoexport);
app.use('/activations', activations);
app.use('/users', users);
app.use('/photos', photos_router);
app.use('/tracks', tracks_router);
app.use('/solardata', solardata);
db.waitDb(() => {

Wyświetl plik

@ -1,73 +0,0 @@
const togeojson = require('togeojson')
const fsPromises = require('fs').promises
const DOMParser = require('xmldom').DOMParser
const simplify = require('@turf/simplify')
const togpx = require('togpx')
const hasha = require('hasha')
const path = require('path')
const config = require('./config')
const db = require('./db')
module.exports = {
importTrack: async function(filename, author) {
// Hash input file to determine filename
let hash = await hasha.fromFile(filename, {algorithm: 'sha256'})
let hashFilename = hash.substr(0, 32)
let originalPath = config.tracks.paths.original + '/' + hashFilename.substr(0, 2) + '/' + hashFilename
await fsPromises.mkdir(path.dirname(originalPath), {recursive: true})
// Parse first to check if it's valid GPX/KML
let gpxData = await fsPromises.readFile(filename, 'utf-8')
let dom = new DOMParser().parseFromString(gpxData, 'text/xml')
if (!dom) {
throw new Error('Bad XML document')
}
let geojson
if (dom.documentElement.tagName === 'kml') {
geojson = togeojson.kml(dom)
originalPath += '.kml'
} else {
geojson = togeojson.gpx(dom)
originalPath += '.gpx'
}
if (geojson.type !== 'FeatureCollection') {
throw new Error('Expected feature collection')
}
if (geojson.features.length === 0) {
throw new Error('No features found')
}
await fsPromises.copyFile(filename, originalPath)
// Remove times, if present
geojson.features.forEach(feature => {
if (feature.type !== 'Feature') {
throw new Error('Expected feature')
}
if (feature.properties.coordTimes) {
delete feature.properties.coordTimes
}
})
let simplified = simplify(geojson, {tolerance: config.tracks.tolerance, highQuality: true})
let simpleGpx = togpx(simplified)
let outPath = config.tracks.paths.simple + '/' + hashFilename.substr(0, 2) + '/' + hashFilename + '.gpx'
await fsPromises.mkdir(path.dirname(outPath), {recursive: true})
await fsPromises.writeFile(outPath, simpleGpx)
db.getDb().collection('uploads').insertOne({
uploadDate: new Date(),
type: 'track',
filename: hashFilename + '.gpx',
author
})
return {
filename: hashFilename + '.gpx',
author
}
}
}

Wyświetl plik

@ -1,42 +0,0 @@
const express = require('express')
const multer = require('multer')
const config = require('./config')
const tracks = require('./tracks')
const jwt = require('express-jwt')
const jwksRsa = require('jwks-rsa')
let upload = multer({dest: config.tracks.uploadPath})
let router = express.Router()
module.exports = router
let jwtCallback = jwt({
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: config.sso.jwksUri
})
})
router.post('/upload', jwtCallback, upload.single('track'), (req, res) => {
res.cacheControl = {
noCache: true
}
if (!req.user.callsign) {
res.status(401).send('Missing callsign in SSO token').end()
return
}
if (req.file) {
tracks.importTrack(req.file.path, req.user.callsign)
.then(track => {
res.json(track)
})
.catch(err => {
console.error(err)
res.status(500).end()
})
}
})

Wyświetl plik

@ -1,7 +1,7 @@
const express = require("express");
const {body, validationResult} = require('express-validator');
const config = require('./config')
const jwt = require("express-jwt");
var { expressjwt: jwt } = require("express-jwt");
const jwksRsa = require("jwks-rsa");
const db = require("./db");
const summitUtils = require('./summits');
@ -15,7 +15,8 @@ let jwtCallback = jwt({
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: config.sso.jwksUri
})
}),
algorithms: ['RS256']
});
const DB_COLLECTION_USERS = "users";