Make tilecountserver accept arguments

This commit is contained in:
Pieter Vander Vennet 2024-03-19 00:12:12 +01:00
parent da1eca797c
commit caaaff45da

View file

@ -1,6 +1,7 @@
import { Client } from "pg"
import { Tiles } from "../../src/Models/TileRange"
import { Server } from "../server"
import Script from "../Script"
/**
* Just the OSM2PGSL default database
@ -114,7 +115,7 @@ class OsmPoiDatabase {
meta[property] = value
}
this.metaCacheDate = now
this.metaCache = <any>meta
this.metaCache = <PoiDatabaseMeta> meta
return this.metaCache
}
}
@ -160,14 +161,22 @@ class CachedSqlCount {
}
}
const connectionString = "postgresql://user:password@localhost:5444/osm-poi"
class TileCountServer extends Script {
constructor() {
super("Starts the tilecount server which calculates summary for a given tile, based on the database. Usage: [db-connection-string] [port=2345]")
}
async main(args: string[]): Promise<void> {
const connectionString = args[0] ?? "postgresql://user:password@localhost:5444/osm-poi"
const port = Number(args[1] ?? 2345)
const tcs = new OsmPoiDatabase(connectionString)
const withCache = new CachedSqlCount(tcs, 14 * 60 * 60 * 24)
new Server(2345, { ignorePathPrefix: ["summary"] }, [
new Server(port, { ignorePathPrefix: ["summary"] }, [
{
mustMatch: "status.json",
mimetype: "application/json",
handle: async (path: string) => {
handle: async () => {
const layers = await tcs.getLayers()
const meta = await tcs.getMeta()
return JSON.stringify({ meta, layers: Array.from(layers) })
@ -180,7 +189,7 @@ new Server(2345, { ignorePathPrefix: ["summary"] }, [
const [layers, z, x, y] = path.split(".")[0].split("/")
let sum = 0
let properties: Record<string, number> = {}
const properties: Record<string, number> = {}
const availableLayers = await tcs.getLayers()
let latSum = 0
let lonSum = 0
@ -215,3 +224,8 @@ console.log(
[3.2839964396059145, 51.172701162680994],
])
)
}
}
new TileCountServer().run()