[+] Frontier endpoint

pull/23/head
Azalea 2024-03-06 10:34:12 -05:00
parent f9af23dbca
commit bc246f39d2
2 changed files with 51 additions and 1 deletions

View File

@ -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
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

View File

@ -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")
}
}