diff --git a/config/application.properties b/config/application.properties index 904d7494..73548c4e 100644 --- a/config/application.properties +++ b/config/application.properties @@ -122,4 +122,8 @@ aqua-net.geoip.ip-header=CF-Connecting-IP aqua-net.jwt.secret="Open Sesame!" ## Disable debug pages -server.error.whitelabel.enabled=false \ No newline at end of file +server.error.whitelabel.enabled=false + +## Adapter for Frontier (For testing only, please keep this disabled) +aqua-net.frontier.enable=false +aqua-net.frontier.ftk=0x00 diff --git a/src/main/java/icu/samnyan/aqua/net/Frontier.kt b/src/main/java/icu/samnyan/aqua/net/Frontier.kt new file mode 100644 index 00000000..306aa246 --- /dev/null +++ b/src/main/java/icu/samnyan/aqua/net/Frontier.kt @@ -0,0 +1,46 @@ +package icu.samnyan.aqua.net + +import ext.API +import ext.Doc +import ext.RP +import ext.minus +import icu.samnyan.aqua.sega.general.service.CardService +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.context.annotation.Configuration +import org.springframework.web.bind.annotation.RestController + +@Configuration +@ConfigurationProperties(prefix = "aqua-net.frontier") +class FrontierProps { + var enabled: Boolean = false + var ftk: String = "" +} + +@RestController +@ConditionalOnProperty("aqua-net.frontier.enabled", havingValue = "true") +@API("/api/v2/frontier") +class Frontier( + val cardService: CardService, + val props: FrontierProps +) { + fun String.checkFtk() { + if (this != props.ftk) 403 - "Invalid FTK" + } + + @API("/register-card") + @Doc("Register a new card by access code", "Success message") + suspend fun registerCard(@RP ftk: String, @RP accessCode: String): Any { + ftk.checkFtk() + + return cardService.registerByAccessCode(accessCode) + } + + @API("/lookup-card") + @Doc("Lookup a card by access code", "Card information") + suspend fun lookupCard(@RP ftk: String, @RP accessCode: String): Any { + ftk.checkFtk() + + return cardService.tryLookup(accessCode) ?: (404 - "Card not found") + } +}