Skip to content

Commit

Permalink
desc
Browse files Browse the repository at this point in the history
- cache ttl should now be passed in milliseconds
- fix residents being parsed as undefined in some cases
  • Loading branch information
Owen3H committed Jul 7, 2024
1 parent 6411e93 commit 501b7b2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/api/dynmap/Dynmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Dynmap extends DataHandler {
readonly inviteRange: number
//#endregion

constructor(mapName: DynmapMap, cacheTTL: number) {
super(mapName, cacheTTL)
constructor(mapName: DynmapMap, cacheTimeoutMs = 120 * 1000) {
super(mapName, cacheTimeoutMs)

this.name = mapName
this.inviteRange = mapName == 'nova' ? 3000 : 3500
Expand Down
4 changes: 2 additions & 2 deletions src/api/squaremap/Squaremap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class Squaremap extends DataHandler {
readonly inviteRange: number = 3500
//#endregion

constructor(mapName: SquaremapMap, cacheTTL = 5) {
super(mapName, cacheTTL)
constructor(mapName: SquaremapMap, cacheTimeoutMs = 5000) {
super(mapName, cacheTimeoutMs)

this.name = mapName

Expand Down
6 changes: 2 additions & 4 deletions src/api/squaremap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import type {
StrictPoint2D
} from '../../types/index.js'

//import { endpoint } from 'src/main.js'

interface ParsedTooltip {
town: string
nation?: string
Expand Down Expand Up @@ -75,7 +73,7 @@ export const parsePopup = (popup: string): ParsedPopup => {
const info = cleaned.split(/\s{2,}/) // TODO: Future proof by regex matching instead of converting to array

// Remove board since we get that from the tooltip
if (info.length == 10)
if (info.length >= 9)
info.splice(1, 1)

const title = info[0]
Expand All @@ -98,7 +96,7 @@ export const parsePopup = (popup: string): ParsedPopup => {
councillors: councillorsStr == "None" ? [] : councillorsStr.split(", "),
founded: parseInfoString(info[3]),
wealth: parseInfoString(info[4]),
residents: info[8]?.split(", ")
residents: info[7]?.split(", ")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/DataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class DataHandler {
//this.#isNode = globalThis.process?.release?.name == 'node'

this.#cacheLock = new Mutex()
this.#cacheTTL = cacheTTL < 1 ? 1 : cacheTTL
this.#cacheTTL = cacheTTL < 1000 ? 1000 : cacheTTL
}

private createCache = async() => {
const release = await this.#cacheLock.acquire()
let cacheInstance = null

try {
cacheInstance = import('@isaacs/ttlcache').then(tc => new tc.default({ ttl: this.#cacheTTL * 1000 }))
cacheInstance = import('@isaacs/ttlcache').then(tc => new tc.default({ ttl: this.#cacheTTL }))
} catch (e) {
console.error(e)
} finally {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class OfficialAPI {
static V3 = OAPIV3
}

export const Aurora = new Squaremap('aurora', 5)
export const Nova = new Dynmap('nova', 120)
export const Aurora = new Squaremap('aurora')
export const Nova = new Dynmap('nova')

export {
Dynmap, Squaremap,
Expand Down

0 comments on commit 501b7b2

Please sign in to comment.