Finish avatar api
This commit is contained in:
@@ -8,12 +8,12 @@ import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import top.fatweb.api.entity.common.ResponseCode
|
||||
import top.fatweb.api.entity.common.ResponseResult
|
||||
import top.fatweb.api.param.api.v1.avatar.AvatarBaseParam
|
||||
import top.fatweb.api.param.api.v1.avatar.AvatarEightBitParam
|
||||
import top.fatweb.api.param.api.v1.avatar.AvatarGitHubParam
|
||||
import top.fatweb.api.service.api.v1.IAvatarService
|
||||
import top.fatweb.api.vo.api.v1.avatar.DefaultBase64Vo
|
||||
import top.fatweb.api.vo.api.v1.avatar.AvatarBase64Vo
|
||||
|
||||
/**
|
||||
* Avatar controller
|
||||
@@ -27,10 +27,45 @@ import top.fatweb.api.vo.api.v1.avatar.DefaultBase64Vo
|
||||
class AvatarController(
|
||||
private val avatarService: IAvatarService
|
||||
) {
|
||||
@Operation(summary = "获取默认随机头像")
|
||||
@GetMapping
|
||||
fun getDefault(@PathVariable apiVersion: String): ResponseResult<DefaultBase64Vo> {
|
||||
return ResponseResult.success(data = avatarService.getDefault())
|
||||
@Operation(summary = "获取随机头像")
|
||||
@GetMapping(produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun getDefault(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return when ((1..4).random()) {
|
||||
1 -> avatarService.triangle(avatarBaseParam)
|
||||
2 -> avatarService.square(avatarBaseParam)
|
||||
3 -> avatarService.identicon(avatarBaseParam)
|
||||
else -> avatarService.github(AvatarGitHubParam().apply {
|
||||
seed = avatarBaseParam?.seed
|
||||
size = avatarBaseParam?.size
|
||||
margin = avatarBaseParam?.margin
|
||||
padding = avatarBaseParam?.padding
|
||||
colors = avatarBaseParam?.colors
|
||||
background = avatarBaseParam?.background
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取随机头像 Base64")
|
||||
@GetMapping("base64")
|
||||
fun getDefaultBase64(
|
||||
@PathVariable apiVersion: String,
|
||||
@Valid avatarBaseParam: AvatarBaseParam?
|
||||
): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS, data = when ((1..4).random()) {
|
||||
1 -> avatarService.triangleBase64(avatarBaseParam)
|
||||
2 -> avatarService.squareBase64(avatarBaseParam)
|
||||
3 -> avatarService.identiconBase64(avatarBaseParam)
|
||||
else -> avatarService.githubBase64(AvatarGitHubParam().apply {
|
||||
seed = avatarBaseParam?.seed
|
||||
size = avatarBaseParam?.size
|
||||
margin = avatarBaseParam?.margin
|
||||
padding = avatarBaseParam?.padding
|
||||
colors = avatarBaseParam?.colors
|
||||
background = avatarBaseParam?.background
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Operation(summary = "三角形头像")
|
||||
@@ -39,29 +74,57 @@ class AvatarController(
|
||||
return avatarService.triangle(avatarBaseParam)
|
||||
}
|
||||
|
||||
@Operation(summary = "三角形头像 Base64")
|
||||
@GetMapping("/triangle/base64")
|
||||
fun triangleBase64(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.triangleBase64(avatarBaseParam)
|
||||
)
|
||||
}
|
||||
|
||||
@Operation(summary = "正方形头像")
|
||||
@GetMapping("/square", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun square(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return avatarService.square(avatarBaseParam)
|
||||
}
|
||||
|
||||
@Operation(summary = "正方形头像 Base64")
|
||||
@GetMapping("/square/base64")
|
||||
fun squareBase64(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.squareBase64(avatarBaseParam)
|
||||
)
|
||||
}
|
||||
|
||||
@Operation(summary = "Identicon 头像")
|
||||
@GetMapping("/identicon", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun identicon(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ByteArray {
|
||||
return avatarService.identicon(avatarBaseParam)
|
||||
}
|
||||
|
||||
@Operation(summary = "Identicon 头像 Base64")
|
||||
@GetMapping("/identicon/base64")
|
||||
fun identiconBase64(@PathVariable apiVersion: String, @Valid avatarBaseParam: AvatarBaseParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.identiconBase64(avatarBaseParam)
|
||||
)
|
||||
}
|
||||
|
||||
@Operation(summary = "GitHub 头像")
|
||||
@GetMapping("/github", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun github(@PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam?): ByteArray {
|
||||
return avatarService.github(avatarGitHubParam)
|
||||
}
|
||||
|
||||
/*
|
||||
@Operation(summary = "8 Bit 头像")
|
||||
@GetMapping("/8bit", produces = [MediaType.IMAGE_PNG_VALUE])
|
||||
fun eightBit(@PathVariable apiVersion: String, @Valid avatarEightBitParam: AvatarEightBitParam): ByteArray {
|
||||
return avatarService.eightBit(avatarEightBitParam)
|
||||
@Operation(summary = "GitHub 头像 Base64")
|
||||
@GetMapping("/github/base64")
|
||||
fun githubBase64(@PathVariable apiVersion: String, @Valid avatarGitHubParam: AvatarGitHubParam?): ResponseResult<AvatarBase64Vo> {
|
||||
return ResponseResult.success(
|
||||
ResponseCode.API_AVATAR_SUCCESS,
|
||||
data = avatarService.githubBase64(avatarGitHubParam)
|
||||
)
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user