forked from Cookies_Github_mirror/AquaDX
[+] Add change name for maimai and refactor settings page
This commit is contained in:
@@ -47,7 +47,9 @@ annotation class Doc(
|
||||
|
||||
@Target(AnnotationTarget.PROPERTY)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class SettingField
|
||||
annotation class SettingField(
|
||||
val game: String
|
||||
)
|
||||
|
||||
// Reflection
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
@@ -21,7 +21,8 @@ class SettingsApi(
|
||||
.mapNotNull { it.findAnnotation<SettingField>()?.let { an -> it to an } }
|
||||
val fieldMap = fields.associate { (f, _) -> f.name to f }
|
||||
val fieldDesc = fields.map { (f, _) -> mapOf(
|
||||
"key" to f.name, "type" to f.returnType.jvmErasure.simpleName
|
||||
"key" to f.name, "type" to f.returnType.jvmErasure.simpleName,
|
||||
"game" to f.findAnnotation<SettingField>()!!.game,
|
||||
) }
|
||||
|
||||
@API("get")
|
||||
@@ -42,4 +43,4 @@ class SettingsApi(
|
||||
field.setCast(options, value)
|
||||
goRepo.save(options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,23 +14,23 @@ class AquaGameOptions(
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
var id: Long = 0,
|
||||
|
||||
@SettingField
|
||||
@SettingField("mai2")
|
||||
var unlockMusic: Boolean = false,
|
||||
|
||||
@SettingField
|
||||
@SettingField("mai2")
|
||||
var unlockChara: Boolean = false,
|
||||
|
||||
@SettingField
|
||||
@SettingField("mai2")
|
||||
var unlockCollectables: Boolean = false,
|
||||
|
||||
@SettingField
|
||||
@SettingField("mai2")
|
||||
var unlockTickets: Boolean = false,
|
||||
|
||||
@SettingField
|
||||
@SettingField("wacca")
|
||||
var waccaInfiniteWp: Boolean = false,
|
||||
|
||||
@SettingField
|
||||
@SettingField("wacca")
|
||||
var waccaAlwaysVip: Boolean = false,
|
||||
)
|
||||
|
||||
interface AquaGameOptionsRepo : JpaRepository<AquaGameOptions, Long>
|
||||
interface AquaGameOptionsRepo : JpaRepository<AquaGameOptions, Long>
|
||||
|
||||
@@ -23,6 +23,18 @@ fun usernameCheck(chars: String): (IUserData, String) -> Unit = { u, v ->
|
||||
v.find { it !in chars }?.let { 400 - "Invalid character '$it' in username" }
|
||||
}
|
||||
|
||||
fun toFullWidth(input: String): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
for (char in input.toCharArray()) {
|
||||
if (char.code in 33..126) {
|
||||
stringBuilder.append((char.code + 65248).toChar())
|
||||
} else {
|
||||
stringBuilder.append(char)
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
data class TrendLog(val date: String, val rating: Int)
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ import icu.samnyan.aqua.net.games.*
|
||||
import icu.samnyan.aqua.net.utils.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.*
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.util.*
|
||||
|
||||
@@ -39,4 +40,15 @@ class Maimai2(
|
||||
|
||||
genericUserSummary(card, ratingComposition)
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("change-name")
|
||||
suspend fun changeName(@RP token: String, @RP newName: String) = us.jwt.auth(token) { u ->
|
||||
val newNameFull = toFullWidth(newName)
|
||||
us.cardByName(u.username) { card ->
|
||||
val user = userDataRepo.findByCard(card) ?: (404 - "User not found")
|
||||
settableFields["userName"]?.invoke(user, newNameFull)
|
||||
userDataRepo.save(user)
|
||||
}
|
||||
mapOf("newName" to newNameFull)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user