Skip to content

Commit

Permalink
guh
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Oct 10, 2023
1 parent 4555a57 commit 0403e07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/classes/Nations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ class Nations implements Base {
const town = towns[i],
nationName = town.nation

if (nationName == "No Nation") continue
if (nationName == "No Nation") {
continue
}

// Doesn't already exist, create new.
if (!raw[nationName]) {
raw[nationName] = {
name: town.nation,
name: nationName,
residents: town.residents,
towns: [],
area: 0,
Expand Down
5 changes: 3 additions & 2 deletions src/classes/Towns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ class Towns implements Base {
rawinfo = town.desc.split("<br />"),
info = rawinfo.map(i => striptags(i, ['a']))

if (info[0].includes("(Shop)")) continue
const firstEl = info[0]
if (firstEl.includes("(Shop)")) continue

const mayor = info[1].slice(7)
if (mayor == "") continue

let split: string | string[] = info[0].split(" (")
let split: string | string[] = firstEl.split(" (")
split = (split[2] ?? split[1]).slice(0, -1)

const residents = info[2].slice(9).split(", "),
Expand Down
14 changes: 7 additions & 7 deletions src/utils/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ const get = (dataType: keyof typeof endpoints, map: ValidMapName) => {
* and retrieve the response as a **JSON** object.
*
* This method does the following:
* - Uses a proxy in browser runtimed to bypass CORS.
* -
* - Uses a proxy when in browser environment to bypass CORS.
* - Retries a failed request up to 3 times by default.
*
* @param url - The full URL to send the request to.
* @param n - The number of retries to attempt.
* @param retries - The amount of retries to attempt before erroring.
*/
const asJSON = async (url: string, /** @defaultValue `3` */ n = 3) => {
const asJSON = async (url: string, retries = 3) => {
const isBrowser = typeof window === "object"
if (isBrowser) url = `https://corsproxy.io/?${encodeURIComponent(url)}`

const res = await request(url)
.then((res: any) => res.body?.json() || res.json())
.catch(async err => await retry(err, url, n))
.catch(async err => await retry(err, url, retries))

return res ?? await retry(null, url, n)
return res ?? await retry(null, url, retries)
}

const retry = (val: any, url: string, n: number): any => n === 1 ? val : asJSON(url, n - 1)
const retry = (val: any, url: string, amt: number): any => amt === 1 ? val : asJSON(url, amt - 1)

let archiveTs = 0
const useArchive = (ts: number) => archiveTs = ts
Expand Down

0 comments on commit 0403e07

Please sign in to comment.