Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically scrape search key #22

Merged
merged 164 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
754c510
Initial commit
DareFox Jan 31, 2023
e7538af
init package.json
DareFox Jan 31, 2023
1901df8
Init tsconfig
DareFox Jan 31, 2023
e476573
Add ts-node as dev dependency
DareFox Jan 31, 2023
5f284c4
Initial typescript express code
DareFox Jan 31, 2023
1d0fa0c
Move src to /src and build to /out
DareFox Jan 31, 2023
76dd7d3
Add function to query games from HLTB
DareFox Jan 31, 2023
286a56a
Add vscode debug config
DareFox Jan 31, 2023
e23dcc6
Trim title once
DareFox Jan 31, 2023
be517e6
Ignore build
DareFox Jan 31, 2023
f1dd1c2
Add cheerio (DOM parser) and weak-lru-cache
DareFox Jan 31, 2023
11404b4
Add global 1hr cache
DareFox Jan 31, 2023
c0371c8
Cache query
DareFox Jan 31, 2023
49f4cd6
Replace 'search' to 'query' for consistency
DareFox Jan 31, 2023
45f628c
Move howlongtobeat.ts to hltb/querty.ts
DareFox Jan 31, 2023
2cfe5e9
Add router to query
DareFox Jan 31, 2023
f1fc958
Move from express to fastify
DareFox Feb 1, 2023
4da153d
Move route to seperate file
DareFox Feb 1, 2023
ca880c8
Ignore all in build folder, not only files
DareFox Feb 1, 2023
d1308ce
Remove emptyy hltb.ts
DareFox Feb 1, 2023
f6df8b1
It is what it is
DareFox Feb 1, 2023
5eac0dd
Add coroutines
DareFox Feb 1, 2023
ebcf128
Implement Weak + Expiring + LRU cache
DareFox Feb 1, 2023
705829b
Change 'checkFullAndFree()' to 'freeLastUsedIfFull()'
DareFox Feb 1, 2023
4b3d944
gradle: Add http4k
DareFox Feb 1, 2023
e2cc962
gradle: Add SLF4J implementation
DareFox Feb 1, 2023
7609f4b
http4k: Create function for creating err response
DareFox Feb 1, 2023
6a3e715
http4k: Add routes
DareFox Feb 1, 2023
21b9fda
main+http4k: Start server in main
DareFox Feb 1, 2023
4258add
cache: rename function 'freeLatUsedIfFull' name
DareFox Feb 15, 2023
e61a8c3
http4k: move to routes to proxy folder
DareFox Feb 15, 2023
3d1a682
http4k: add client variable
DareFox Feb 15, 2023
cab248e
hltb: add Hltb singleton + query function from it
DareFox Feb 15, 2023
deddb6c
proxy: add handler for redirecting request to HLTB
DareFox Feb 15, 2023
334ad85
gradle: remove coroutines and jackson, add kotlinx json
DareFox Feb 15, 2023
3e778bd
test: remove coroutines from test
DareFox Feb 15, 2023
893d2a3
proxy: change port to 1337
DareFox Feb 15, 2023
75c8abc
http4k: use kotlinx instead of jackson on error
DareFox Feb 15, 2023
b1b7362
project: auto cleanup (imports, tabs)
DareFox Feb 15, 2023
ce54890
proxy: optimize lines code of QueryGames.kt
DareFox Feb 15, 2023
2b06135
cache: create getOrGenerateBlocking function
DareFox Feb 15, 2023
e66f6e9
hltb: make pagetotal nullable and remove counter
DareFox Feb 15, 2023
a64cf6f
mutex: create blocking withLock function
DareFox Feb 15, 2023
b6082e4
mutex: create hashmap with dispoable mutex (on no use)
DareFox Feb 15, 2023
de95637
proxy: bind /v1/query to queryGames
DareFox Feb 15, 2023
ffac5c8
json: create json instance with unknown keys
DareFox Feb 15, 2023
9d7902c
cache: put instance in another file
DareFox Feb 15, 2023
06bc02e
mutex: create top level instance of HashMutex
DareFox Feb 15, 2023
f9583a9
proxy: use "title" param, send as json, use cache
DareFox Feb 15, 2023
18b5dcd
proxy: i forgor to start server in main
DareFox Feb 15, 2023
40eae50
project: move to java package structure
DareFox Feb 15, 2023
1334e6f
cache: add KDoc to getOrGenerateBlocking
DareFox Feb 15, 2023
4ae4906
hltb: create extension function simplyfing building requests
DareFox Feb 17, 2023
ab97650
hltb: use extensions and rename query create func
DareFox Feb 17, 2023
6ae9148
hltb: simplify query function
DareFox Feb 17, 2023
25ffc13
hltb: rename file
DareFox Feb 17, 2023
0231722
gradle: add delecious jsoup
DareFox Feb 21, 2023
e644b3b
hltb: create parser for tables
DareFox Feb 20, 2023
848ab0f
hltb: create parser for overview page
DareFox Feb 20, 2023
3a0129c
hltb: change tabletime parser name to table parser
DareFox Feb 20, 2023
99e5eb1
hltb: for single, convert parser to immutable data class
DareFox Feb 21, 2023
b08e72e
hltb: add function in parser to convert time
DareFox Feb 21, 2023
7cf1657
hltb: add function to convert to multiplayer table
DareFox Feb 21, 2023
84e6b3f
hltb: extract function getting table
DareFox Feb 21, 2023
0e04c1e
hltb: use seconds during parsing instead of minutes
DareFox Feb 21, 2023
91ef036
hltb: add speedrun data class parser
DareFox Feb 21, 2023
f69347b
hltb: add platform data class for overview parser
DareFox Feb 21, 2023
556f1e1
hltb: make hltb___table serailizable
DareFox Feb 21, 2023
cb29f94
hltb: add function to request overview
DareFox Feb 21, 2023
d108fa0
hltb: add polled field
DareFox Feb 21, 2023
ba61d29
htlb: make region nullable and class based selector for devs/pubs
DareFox Feb 21, 2023
35f9829
proxy: create http handler for /v1/overview?id
DareFox Feb 21, 2023
784a244
proxy: add handler to /v1/overview route
DareFox Feb 21, 2023
e4881cb
hltb: add support for plural
DareFox Feb 21, 2023
39082b3
hltb: make overview null on 404 error
DareFox Feb 21, 2023
fd94154
cache: save response instead of only body
DareFox Feb 21, 2023
32fca02
hltb: add title field in overview
DareFox Feb 21, 2023
1ec90fa
hltb: parse multiple dateformats
DareFox Feb 21, 2023
644f347
hltb: return empty array if no data
DareFox Feb 21, 2023
d3b0f4e
project: clean up code (format, imports...)
DareFox Feb 21, 2023
89bdfe8
hltb: parse ½ symbol as additional 30 minutes
DareFox Feb 21, 2023
d4bf3f7
hltb: fix parsing time if empty or Hours without 1/2 symbol
DareFox Feb 21, 2023
f93def2
Merge pull request #1 from DareFox/kotlin
DareFox Feb 21, 2023
e5e61af
hltb: add steamId field
DareFox Feb 21, 2023
ee2f2d6
hltb: simplify null check
DareFox Feb 21, 2023
bc0c204
gradle: add shadow plugin to create far jar
DareFox Feb 21, 2023
135f228
gradle: use jdk 17
DareFox Feb 21, 2023
577098a
gradle: use jsoup 1.15.4
DareFox Feb 21, 2023
1dada01
proxy: get port from env variables (if empty, default is 443)
DareFox Feb 21, 2023
98305f5
proxy: use CAPTIAL LETTERS variable
DareFox Feb 21, 2023
114924f
idea: add run profile
DareFox Feb 21, 2023
8e0a8b2
proxy: fix spliting by space to comma+space
DareFox Feb 21, 2023
36e2b3e
docker: create Dockerfile
DareFox Feb 21, 2023
ad59e37
Merge pull request #2 from DareFox/kotlin
DareFox Feb 21, 2023
ea18ed1
proxy: set default port to 8080
DareFox Feb 22, 2023
627af2c
hltb: make rows in table nullable (execpt "all styles")
DareFox Feb 22, 2023
35f4535
hosting: push fly.toml file
DareFox Feb 22, 2023
adce337
github: add action to deploy to hosting on push
DareFox Feb 22, 2023
46fa7c2
Merge pull request #3 from DareFox/kotlin
DareFox Feb 22, 2023
afb191e
github: fix yaml action
DareFox Feb 22, 2023
4d17986
Merge pull request #4 from DareFox/kotlin
DareFox Feb 22, 2023
6c1545b
hltb: remove force non-null conversion
DareFox Feb 22, 2023
92ae7fc
hltb-fix: add support for only YEAR date such as 1987
DareFox Feb 22, 2023
e2906cc
Merge pull request #5 from DareFox/kotlin
DareFox Feb 22, 2023
642b98c
tests-siege: script for generating urls for test
DareFox Feb 22, 2023
1d4bd1f
tests-siege: add readme.md
DareFox Feb 22, 2023
be7054d
siege: add "what is siege" part
DareFox Feb 22, 2023
462b0e2
siege: provide allGames.txt for script
DareFox Feb 22, 2023
29bcae8
Merge pull request #6 from DareFox/kotlin
DareFox Feb 22, 2023
92d56d1
cache: use weakreference values
DareFox Feb 22, 2023
45f9829
cache: use seperate key for mutex map (cause WeakMap reffers to it)
DareFox Feb 22, 2023
394aa10
map: add gc key-pair collectable map
DareFox Feb 27, 2023
96762e2
map+gradle: replace DIY map with Apache
DareFox Feb 27, 2023
04b9f14
cache: use referencemap (strong key, weak value)
DareFox Feb 27, 2023
db7dd83
cache: set value ref type to soft
DareFox Feb 27, 2023
593cfb7
proxy: add handler for cache info
DareFox Feb 27, 2023
967e1e7
proxy: send json about cache info
DareFox Feb 27, 2023
7090ec3
mutex: synchronize creation and use referencemap
DareFox Feb 27, 2023
8d17aa9
Cache disappering fixes / HashMutex changes / Cache info address
DareFox Feb 27, 2023
6b7c232
hltb: add function to parse numbers with K at the end
DareFox Feb 27, 2023
98193bd
hltb: parse polls with .parseLongWithK()
DareFox Feb 27, 2023
706f822
hltb: fix platform decleration crash by renaming function
DareFox Feb 27, 2023
a05540b
hltb: fix regex for K in number
DareFox Feb 27, 2023
018477c
Fix parsing numbers in HLTB parser with K at the end
DareFox Feb 27, 2023
ac33ee1
update readme
DareFox Feb 28, 2023
8927cfb
update readme with spaces
DareFox Feb 28, 2023
d267858
update readme format
DareFox Feb 28, 2023
9f3fd26
update readme again and again
DareFox Feb 28, 2023
cb878cc
Show endpoints in readme
DareFox Feb 28, 2023
eac2976
update /v1/overview codes
DareFox Feb 28, 2023
248e5f4
Fix /v1/overview codes
DareFox Feb 28, 2023
3741ac5
proxy: add filter to allow all CORS
DareFox Mar 1, 2023
42dedf1
proxy: use CORS all filter to all routes
DareFox Mar 1, 2023
9492f8e
CORS: Allow all
DareFox Mar 1, 2023
cc7ed42
proxy: add url to github in index.html
DareFox Mar 2, 2023
2d306c8
hltb: fix parsing year from week year to regular
DareFox Mar 2, 2023
c855948
Fix parsing year from HLTB + link to github in index
DareFox Mar 2, 2023
0b94239
Date.kt: remove useless lateinit
DareFox Oct 3, 2023
c40e046
HltbQueryResponse: fix "Field 'count' is required for type..."
DareFox Oct 3, 2023
8d5a153
Merge pull request #13 from DareFox/kotlin
DareFox Oct 3, 2023
29be658
refactor(route: /): Redirect to github page
DareFox Feb 10, 2024
a10393f
Merge pull request #14 from DareFox/kotlin
DareFox Feb 10, 2024
6239321
fix: Change search url
DareFox Aug 6, 2024
fa00337
Merge pull request #18 from DareFox/kotlin
DareFox Aug 6, 2024
72658e6
fix: Remove syntax typo
DareFox Aug 6, 2024
f3c2c6b
Merge pull request #19 from DareFox/kotlin
DareFox Aug 6, 2024
3e4f40b
fix: Update search URL
DareFox Aug 8, 2024
75b8fab
fix: Update search URL
DareFox Aug 8, 2024
e194a7a
fix: Update search URL (#20)
DareFox Aug 8, 2024
01377c0
fix: Update search URL
DareFox Aug 9, 2024
62bbd29
fix: Update search URL
DareFox Sep 15, 2024
e47c758
chore: Update gradle, kotlin and dependencies
DareFox Sep 15, 2024
9b5f3d4
chore: Update gradle, kotlin and dependencies
DareFox Sep 15, 2024
e2f170a
fix: Deprecated fields because they were removed from search
DareFox Sep 15, 2024
16aeee8
fix: Deprecated fields because they were removed from search
DareFox Sep 15, 2024
27c713d
Merge branch 'main' into kotlin
DareFox Sep 15, 2024
0037082
Merge branch 'main' into kotlin
DareFox Sep 15, 2024
63abc21
build(gradle): Download docs for IDEA automatically
DareFox Oct 10, 2024
d0cf98c
build(gradle): Download docs for IDEA automatically
DareFox Oct 10, 2024
b13673e
fix: Dynamically scrape search key
DareFox Oct 10, 2024
71a573f
fix: Dynamically scrape search key
DareFox Oct 10, 2024
1374d19
Merge branch 'kotlin' of https://github.com/DareFox/HowLongToBeat-Pro…
DareFox Oct 10, 2024
bf8a1c2
Merge branch 'kotlin' of https://github.com/DareFox/HowLongToBeat-Pro…
DareFox Oct 10, 2024
3e699d9
Merge branch 'kotlin' of https://github.com/DareFox/HowLongToBeat-Pro…
DareFox Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM gradle:8.0.1-jdk17 AS build
FROM gradle:8.10.1-jdk21 AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle shadowJar --no-daemon

FROM eclipse-temurin:17-jre-alpine
FROM eclipse-temurin:21-jre-alpine

COPY --from=build /home/gradle/src/build/libs/ /app/
ENTRYPOINT ["java","-jar","/app/HowLongToBeat-Proxy-API-1.0-SNAPSHOT-all.jar"]
29 changes: 16 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
val coroutinesVersion = "1.6.4"
val http4kVersion = "4.37.0.0"
val http4kVersion = "5.26.0.0"

plugins {
kotlin("jvm") version "1.8.0"
kotlin("plugin.serialization") version "1.8.0"
kotlin("jvm") version "2.0.20"
kotlin("plugin.serialization") version "2.0.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
application
idea
}

group = "io.github.darefox"
Expand All @@ -15,6 +16,12 @@ repositories {
mavenCentral()
}

idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}

dependencies {
testImplementation(kotlin("test"))
Expand All @@ -26,30 +33,26 @@ dependencies {
implementation("org.http4k:http4k-format-kotlinx-serialization:$http4kVersion")

// loggers
implementation("org.slf4j:slf4j-simple:2.0.6")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.4")
implementation("org.slf4j:slf4j-simple:2.0.13")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.5")

// serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")

// dependency for mutex
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

// html parser
implementation("org.jsoup:jsoup:1.15.4")
implementation("org.jsoup:jsoup:1.18.1")

implementation("org.apache.commons:commons-collections4:4.1")
implementation("org.apache.commons:commons-collections4:4.4")
}


tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(17)
}

tasks.jar {
manifest.attributes["Main-Class"] = "io.github.darefox.hltbproxy.MainKt"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified gradlew
100755 → 100644
Empty file.
121 changes: 116 additions & 5 deletions src/main/kotlin/io/github/darefox/hltbproxy/hltb/HLTB.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
package io.github.darefox.hltbproxy.hltb

import io.github.darefox.hltbproxy.http4k.client
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import mu.KotlinLogging
import org.http4k.core.Body
import org.http4k.core.Method.GET
import org.http4k.core.Method.POST
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.format.KotlinxSerialization.auto
import org.jsoup.Jsoup
import org.jsoup.select.Elements
import java.net.URLEncoder

object HLTB {
fun queryGames(title: String, page: Int): HltbQueryResponse {
private val log = KotlinLogging.logger { }
lateinit var searchKey: String
private val keyMutex = Mutex()
private val updateMutex = Mutex()
private val initMutex = Mutex()

suspend fun queryGames(title: String, page: Int): HltbQueryResponse {
val encoded = URLEncoder.encode(title, "utf-8")
val url = "https://howlongtobeat.com/?q=$encoded"

val queryObj = createQueryObj(title, page)
val response = client(
Request(POST, "https://howlongtobeat.com/api/search/43ff72690aa2496d").hltbJsonRequest(url, queryObj)
)

var keyIsNotUpdated = true
lateinit var response: Response
while (true) {
val call = client(
Request(POST, "https://howlongtobeat.com/api/search/${getSearchKey()}")
.hltbJsonRequest(url, queryObj)
)

if (call.bodyString().startsWith("<!DOCTYPE html>") && keyIsNotUpdated) {
log.info("Search key is no longer valid, calling update")
updateSearchKey()
keyIsNotUpdated = false
} else {
response = call
break
}
}

if (response.bodyString().startsWith("<!DOCTYPE html>")) {
updateSearchKey()
}

return Body.auto<HltbQueryResponse>().toLens().invoke(response)
}

fun getOverviewInfoAboutGame(id: Long): HltbOverviewParser? {
suspend fun getOverviewInfoAboutGame(id: Long): HltbOverviewParser? {
val url = "https://howlongtobeat.com/game/$id"
val response = client(Request(GET, url).hltbDefaultHeaders(url, false))

Expand All @@ -33,4 +64,84 @@ object HLTB {
val html = Jsoup.parse(response.bodyString())
return HltbOverviewParser(html)
}

private suspend fun getSearchKey(): String {
if (!this::searchKey.isInitialized) {
initMutex.withLock {
if (!this::searchKey.isInitialized) {
return updateSearchKey()
} else {
return keyMutex.withLock { searchKey }
}
}
} else {
keyMutex.withLock { return searchKey }
}
}

private suspend fun updateSearchKey(): String {
// Prevent creating multiple calls to updateSearchKey
// First call updates key, remaining calls wait for new key
return if (updateMutex.isLocked) getSearchKey() else {
return updateMutex.withLock {
log.info("Updating key...")
keyMutex.withLock { // keyMutex needed for API calls to wait new key
val url = "https://howlongtobeat.com"
val response = client(Request(GET, url).hltbDefaultHeaders(url, false))

if (response.status != Status.OK) {
error("Response is not 199 from HLTB server, can't get search key")
}

val html = Jsoup.parse(response.bodyString())
html.setBaseUri(url)

val scripts = html.select("script")

val codeOfScripts = getCodeOfInlineScripts(scripts) + getCodeOfExternalScripts(scripts)
val key = findKeyInScripts(codeOfScripts)

searchKey = key
key
}
}
}
}

private fun getCodeOfInlineScripts(scripts: Elements): Sequence<String> {
val inlinedScripts = scripts.filter { element ->
val isJS = element.attr("type") == "text/javascript"
val isExternal = element.attr("src").isNotEmpty()
isJS && !isExternal
}
return inlinedScripts.asSequence().map { it.text() }
}

private fun getCodeOfExternalScripts(scripts: Elements): Sequence<String> {
val externalScripts = scripts.filter { element ->
val isExternal = element.attr("src").isNotEmpty()
isExternal
}.map {
it.attr("abs:src")
}

return externalScripts.asSequence().map { scriptUrl ->
log.info("Downloading script: $scriptUrl")
val response = client(Request(GET, scriptUrl).hltbDefaultHeaders(scriptUrl, false))
if (response.status != Status.OK) {
error("On downloading script ($scriptUrl), server returned ${response.status}")
}
response.bodyString()
}
}

private fun findKeyInScripts(codes: Sequence<String>): String {
val regex = "(?<=api/search/\"\\.concat\\(\")[a-zA-Z0-9]+".toRegex()
for (code in codes) {
val result = regex.find(code)?.value ?: continue
return result
}

error("Can't find search key")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ data class HltbGameData(
val compLvlCo: Long,
@JsonNames("comp_lvl_mp")
val compLvlMp: Long,
@JsonNames("comp_lvl_spd")
val compLvlSpd: Long,
@JsonNames("comp_main")
val compMain: Long,
@JsonNames("comp_plus")
Expand Down Expand Up @@ -76,14 +74,8 @@ data class HltbGameData(
val countPlaying: Long,
@JsonNames("count_retired")
val countRetired: Long,
@JsonNames("profile_dev")
val profileDev: String,
@JsonNames("profile_popular")
val profilePopular: Long,
@JsonNames("profile_steam")
val profileSteam: Long,
@JsonNames("profile_platform")
val profilePlatform: String,
@JsonNames("release_world")
val releaseWorld: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.darefox.hltbproxy.proxy
import io.github.darefox.hltbproxy.cache.getOrGenerateBlocking
import io.github.darefox.hltbproxy.hltb.*
import io.github.darefox.hltbproxy.http4k.ErrorResponse
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable
import org.http4k.core.*
import org.http4k.format.KotlinxSerialization.auto
Expand All @@ -15,7 +16,7 @@ val getOverviewInfo: HttpHandler = { req ->

val key = "overviewInfo;$id"
cache.getOrGenerateBlocking(mutexMap, key) {
val obj = HLTB.getOverviewInfoAboutGame(id)?.toProxy()
val obj = runBlocking { HLTB.getOverviewInfoAboutGame(id)?.toProxy() }
?: return@getOrGenerateBlocking ErrorResponse(Status.NOT_FOUND, "Not Found")
Response(Status.OK).with(Body.auto<OverviewInfo>().toLens() of obj)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.darefox.hltbproxy.proxy

import io.github.darefox.hltbproxy.cache.getOrGenerateBlocking
import io.github.darefox.hltbproxy.hltb.HLTB
import kotlinx.coroutines.runBlocking
import org.http4k.core.*
import org.http4k.format.KotlinxSerialization.auto
import org.http4k.lens.Query
Expand All @@ -16,7 +17,7 @@ val queryGames: HttpHandler = { req ->
val key = "queryGames;$name;$page"

cache.getOrGenerateBlocking(mutexMap, key) {
val body = HLTB.queryGames(name, page).data.map {
val body = runBlocking { HLTB.queryGames(name, page) }.data.map {
it.toProxyObj()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fun HltbGameData.toProxyObj(): QueryGamesResponse {
type = this.gameType,
gameId = this.gameId,
gameImage = this.gameImage,
dev = this.profileDev,
platforms = this.profilePlatform.trim().split(", "),
dev = "API Deprecated",
platforms = listOf(),
releaseYear = this.releaseWorld.toInt(),
beatTime = QueryGamesBeatTime(
main = QueryGamesBeatTimeEntry(compMain, compMainCount),
Expand All @@ -62,6 +62,6 @@ fun HltbGameData.toProxyObj(): QueryGamesResponse {
retired = countRetired,
reviews = countReview,
),
steamId = if (profileSteam == 0L) null else profileSteam
steamId = null
)
}