mirror of https://github.com/hykilpikonna/AquaDX
[+] Net photo APIs
parent
547ad4d0f8
commit
6bdfc69668
|
@ -4,8 +4,10 @@ import ext.*
|
|||
import icu.samnyan.aqua.net.db.AquaUserServices
|
||||
import icu.samnyan.aqua.net.games.*
|
||||
import icu.samnyan.aqua.net.utils.*
|
||||
import icu.samnyan.aqua.sega.maimai2.handler.UploadUserPhotoHandler
|
||||
import icu.samnyan.aqua.sega.maimai2.model.*
|
||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.*
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.util.*
|
||||
|
@ -172,4 +174,22 @@ class Maimai2(
|
|||
}
|
||||
SUCCESS
|
||||
}
|
||||
|
||||
@API("my-photo")
|
||||
suspend fun myPhoto(@RP token: Str) = us.jwt.auth(token) { u ->
|
||||
val find = "${u.ghostCard.extId}-"
|
||||
UploadUserPhotoHandler.uploadDir.toFile().listFiles()
|
||||
?.map { it.name }
|
||||
?.filter { it.startsWith(find) }
|
||||
?.sorted()
|
||||
?: emptyList()
|
||||
}
|
||||
|
||||
@API("my-photo/{fileName}", produces = [MediaType.IMAGE_JPEG_VALUE])
|
||||
suspend fun myPhoto(@RP token: Str, @PV fileName: Str) = us.jwt.auth(token) { u ->
|
||||
if (!fileName.startsWith("${u.ghostCard.extId}-")) (403 - "Not your photo")
|
||||
val f = (UploadUserPhotoHandler.uploadDir / fileName).toFile()
|
||||
if (!f.exists()) (404 - "Photo not found")
|
||||
f.readBytes()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@ import ext.path
|
|||
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||
import icu.samnyan.aqua.sega.maimai2.model.request.UploadUserPhoto
|
||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Component
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
|
@ -20,8 +18,6 @@ import java.util.*
|
|||
@Component("Maimai2UploadUserPhotoHandler")
|
||||
class UploadUserPhotoHandler(private val mapper: BasicMapper) :
|
||||
BaseHandler {
|
||||
val tmpDir = "data/tmp".path().apply { toFile().mkdirs() }
|
||||
val uploadDir = "data/upload/mai2/plays".path().apply { toFile().mkdirs() }
|
||||
|
||||
override fun handle(request: Map<String, Any>): String {
|
||||
// Maimai DX sends split base64 data for one jpeg image.
|
||||
|
@ -49,5 +45,8 @@ class UploadUserPhotoHandler(private val mapper: BasicMapper) :
|
|||
|
||||
companion object {
|
||||
private val logger = logger()
|
||||
|
||||
val tmpDir = "data/tmp".path().apply { toFile().mkdirs() }
|
||||
val uploadDir = "data/upload/mai2/plays".path().apply { toFile().mkdirs() }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue