forked from Cookies_Github_mirror/AquaDX
[+] Maimai export
This commit is contained in:
@@ -2,6 +2,7 @@ package icu.samnyan.aqua.net.db
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import ext.*
|
||||
import icu.samnyan.aqua.net.components.JWT
|
||||
import icu.samnyan.aqua.sega.allnet.AllNetProps
|
||||
import icu.samnyan.aqua.sega.allnet.KeyChipRepo
|
||||
import icu.samnyan.aqua.sega.allnet.KeychipSession
|
||||
@@ -112,7 +113,8 @@ class AquaUserServices(
|
||||
val cardRepo: CardRepository,
|
||||
val hasher: PasswordEncoder,
|
||||
val keyChipRepo: KeyChipRepo,
|
||||
val allNetProps: AllNetProps
|
||||
val allNetProps: AllNetProps,
|
||||
val jwt: JWT
|
||||
) {
|
||||
companion object {
|
||||
val SETTING_FIELDS = AquaUserServices::class.functions
|
||||
|
||||
@@ -3,13 +3,17 @@ package icu.samnyan.aqua.net.games
|
||||
import ext.API
|
||||
import ext.RP
|
||||
import ext.Str
|
||||
import ext.minus
|
||||
import icu.samnyan.aqua.api.model.resp.sega.maimai2.external.Maimai2DataExport
|
||||
import icu.samnyan.aqua.net.db.AquaUserServices
|
||||
import icu.samnyan.aqua.net.utils.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserDataRepo
|
||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserGeneralDataRepo
|
||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserPlaylogRepo
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.lang.reflect.Field
|
||||
import java.util.*
|
||||
import kotlin.reflect.full.declaredMembers
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.jvm.jvmErasure
|
||||
|
||||
@RestController
|
||||
@API("api/v2/game/mai2")
|
||||
@@ -17,7 +21,8 @@ class Maimai2(
|
||||
override val us: AquaUserServices,
|
||||
override val playlogRepo: Mai2UserPlaylogRepo,
|
||||
override val userDataRepo: Mai2UserDataRepo,
|
||||
val userGeneralDataRepository: Mai2UserGeneralDataRepo
|
||||
val userGeneralDataRepository: Mai2UserGeneralDataRepo,
|
||||
val repos: Mai2Repos
|
||||
): GameApiController("mai2")
|
||||
{
|
||||
override suspend fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||
@@ -39,4 +44,27 @@ class Maimai2(
|
||||
|
||||
genericUserSummary(card, ratingComposition)
|
||||
}
|
||||
|
||||
// Use reflection to get all properties in Mai2Repos with matching names in Maimai2DataExport
|
||||
var exportFields: Map<Field, UserLinked<*>> = listOf(*Maimai2DataExport::class.java.declaredFields)
|
||||
.filter { it.name !in arrayOf("gameId", "userData") }
|
||||
.associateWith { Mai2Repos::class.declaredMembers
|
||||
.filter { f -> f.returnType.jvmErasure.isSubclassOf(UserLinked::class) }
|
||||
.firstOrNull { f -> f.name == it.name || f.name == it.name.replace("List", "") }
|
||||
?.call(repos) as UserLinked<*>? ?: error("No matching field found for ${it.name}")
|
||||
}
|
||||
|
||||
@API("export")
|
||||
fun exportAllUserData(@RP token: Str) = us.jwt.auth(token) { u ->
|
||||
try {
|
||||
Maimai2DataExport().apply {
|
||||
gameId = "SDEZ"
|
||||
userData = repos.userData.findByCard(u.ghostCard) ?: (404 - "User not found")
|
||||
exportFields.forEach { (f, u) ->
|
||||
f.set(this, if (f.type == List::class.java) u.findByUser(userData)
|
||||
else u.findSingleByUser(userData).orElse(null))
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) { 500 - "Error during data export. Reason: ${e.message}" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user