Compare commits

...

3 Commits

Author SHA1 Message Date
Raymond Yang
de7171b72b 新增get(id: String)功能 2023-05-23 14:19:16 +08:00
Raymond Yang
b811352620 修正put model功能 2023-05-18 11:35:10 +08:00
Raymond Yang
51d5eae6c0 修正create model功能 2023-05-18 11:33:12 +08:00
5 changed files with 166 additions and 74 deletions

View File

@ -20,9 +20,17 @@
"modelData": { "modelData": {
"type": 0, "type": 0,
"material": { "material": {
"_id": "6464410c9c67517fcbccf447",
"ownerId": "646435a39c67517fcbccf426",
"name": "奸笑的綿芽",
"path": "/upload/1684291852002.jpeg",
"contentType": "image/jpeg", "contentType": "image/jpeg",
"id": "d6350683.jpg", "fileTag": [
"textureUrl": "https://cdn2.ettoday.net/images/6350/d6350683.jpg" "圖片",
"Hololive"
],
"createAt": 1684291852023,
"updatedAt": 1684294290879
}, },
"params": { "params": {
"width": 1, "width": 1,
@ -100,9 +108,17 @@
}, },
"modelData": { "modelData": {
"material": { "material": {
"_id": "6464410c9c67517fcbccf447",
"ownerId": "646435a39c67517fcbccf426",
"name": "奸笑的綿芽",
"path": "/upload/1684291852002.jpeg",
"contentType": "image/jpeg", "contentType": "image/jpeg",
"id": "d6350683.jpg", "fileTag": [
"textureUrl": "https://cdn2.ettoday.net/images/6350/d6350683.jpg" "圖片",
"Hololive"
],
"createAt": 1684291852023,
"updatedAt": 1684294290879
}, },
"params": { "params": {
"width": 0.75, "width": 0.75,
@ -133,9 +149,17 @@
"modelData": { "modelData": {
"type": 2, "type": 2,
"material": { "material": {
"_id": "6464410c9c67517fcbccf447",
"ownerId": "646435a39c67517fcbccf426",
"name": "奸笑的綿芽",
"path": "/upload/1684291852002.jpeg",
"contentType": "image/jpeg", "contentType": "image/jpeg",
"id": "d6350683.jpg", "fileTag": [
"textureUrl": "https://cdn2.ettoday.net/images/6350/d6350683.jpg" "圖片",
"Hololive"
],
"createAt": 1684291852023,
"updatedAt": 1684294290879
}, },
"params": { "params": {
"availableRange": 20, "availableRange": 20,
@ -168,9 +192,17 @@
}, },
"modelData": { "modelData": {
"material": { "material": {
"_id": "6464410c9c67517fcbccf447",
"ownerId": "646435a39c67517fcbccf426",
"name": "奸笑的綿芽",
"path": "/upload/1684291852002.jpeg",
"contentType": "image/jpeg", "contentType": "image/jpeg",
"id": "d6350683.jpg", "fileTag": [
"textureUrl": "https://cdn2.ettoday.net/images/6350/d6350683.jpg" "圖片",
"Hololive"
],
"createAt": 1684291852023,
"updatedAt": 1684294290879
}, },
"params": { "params": {
"availableRange": 20, "availableRange": 20,
@ -205,9 +237,17 @@
}, },
"modelData": { "modelData": {
"material": { "material": {
"contentType": "model/gltf-binary", "_id": "6464410c9c67517fcbccf447",
"id": "spiderbot.glb", "ownerId": "646435a39c67517fcbccf426",
"textureUrl": "https://www.ray650128.com/spiderbot.glb" "name": "奸笑的綿芽",
"path": "/upload/1684291852002.jpeg",
"contentType": "image/jpeg",
"fileTag": [
"圖片",
"Hololive"
],
"createAt": 1684291852023,
"updatedAt": 1684294290879
}, },
"params": { "params": {
"availableRange": 20, "availableRange": 20,
@ -247,9 +287,12 @@
}, },
"modelData": { "modelData": {
"material": { "material": {
"contentType": "video/mpeg4", "_id": "6465a6e2f5c86b7c50520486",
"id": "ker1.mp4", "ownerId": "646435a39c67517fcbccf426",
"textureUrl": "https://www.ray650128.com/video/ker1.mp4" "name": "獅子影片",
"path": "/upload/1684383458922.mp4",
"contentType": "video/mp4",
"createAt": 1684383458939
}, },
"params": { "params": {
"availableRange": 20, "availableRange": 20,
@ -288,9 +331,12 @@
}, },
"modelData": { "modelData": {
"material": { "material": {
"contentType": "video/mpeg4", "_id": "6465a6e2f5c86b7c50520486",
"id": "ker2.mp4", "ownerId": "646435a39c67517fcbccf426",
"textureUrl": "https://www.ray650128.com/video/ker2.mp4" "name": "獅子影片",
"path": "/upload/1684383458922.mp4",
"contentType": "video/mp4",
"createAt": 1684383458939
}, },
"params": { "params": {
"availableRange": 20, "availableRange": 20,
@ -326,9 +372,17 @@
}, },
"modelData": { "modelData": {
"material": { "material": {
"contentType": "video/mpeg4", "_id": "6464410c9c67517fcbccf447",
"id": "hou1.mp4", "ownerId": "646435a39c67517fcbccf426",
"textureUrl": "https://www.ray650128.com/video/hou1.mp4" "name": "奸笑的綿芽",
"path": "/upload/1684291852002.jpeg",
"contentType": "image/jpeg",
"fileTag": [
"圖片",
"Hololive"
],
"createAt": 1684291852023,
"updatedAt": 1684294290879
}, },
"params": { "params": {
"availableRange": 20, "availableRange": 20,
@ -378,10 +432,10 @@
}, },
{ {
"id": 9, "id": 9,
"name": "MultiFace", "name": "MultiplePlane",
"position": { "position": {
"x": 0, "x": 1,
"y": 1, "y": -1,
"z": 0 "z": 0
}, },
"rotation": { "rotation": {
@ -395,56 +449,59 @@
"z": 1 "z": 1
}, },
"modelData": { "modelData": {
"material": { "materials": [
"contentTypes": [ {
"image/jpeg", "_id": "6464410c9c67517fcbccf447",
"image/jpeg", "ownerId": "646435a39c67517fcbccf426",
"image/jpeg", "name": "奸笑的綿芽",
"image/jpeg", "path": "/upload/1684291852002.jpeg",
"image/jpeg", "contentType": "image/jpeg",
"image/jpeg", "fileTag": [
"image/jpeg", "圖片",
"image/jpeg", "Hololive"
"image/jpeg", ],
"image/jpeg", "createAt": 1684291852023,
"image/jpeg", "updatedAt": 1684294290879
"image/jpeg", },
"image/jpeg", {
"image/jpeg", "_id": "646590294df2e46df0f7a51b",
"image/jpeg" "ownerId": "646435a39c67517fcbccf426",
], "name": "供三小",
"textureUrls": [ "path": "/upload/1684377641965.jpeg",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "contentType": "image/jpeg",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "createAt": 1684377641977
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", },
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", {
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "_id": "646590674df2e46df0f7a524",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "ownerId": "646435a39c67517fcbccf426",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "name": "解散囉",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "path": "/upload/1684377703013.png",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "contentType": "image/png",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "createAt": 1684377703020
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", },
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", {
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "_id": "646590e04df2e46df0f7a52f",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg", "ownerId": "646435a39c67517fcbccf426",
"https://cdn2.ettoday.net/images/6350/d6350683.jpg" "name": "QRCode",
] "path": "/upload/1684377824564.png",
}, "contentType": "image/png",
"createAt": 1684377824573
},
{
"_id": "646593304df2e46df0f7a54b",
"ownerId": "646435a39c67517fcbccf426",
"name": "煙霧",
"path": "/upload/1684378416412.png",
"contentType": "image/png",
"createAt": 1684378416417
}
],
"params": { "params": {
"levelAngles": [ "levelAngles": [ 0 ],
45, "levelBorders": [ 0 ],
0, "levelCount": 1,
-45
],
"levelBorders": [
0.1,
0.1,
0.1
],
"levelCount": 3,
"planeBorder": 0.1, "planeBorder": 0.1,
"planeCount": 5, "planeCount": 4,
"speed": 1 "speed": 1
}, },
"type": 6 "type": 6

View File

@ -1,14 +1,28 @@
package com.ray650128.extension package com.ray650128.extension
import com.ray650128.model.pojo.Material
import com.ray650128.model.pojo.arModel.ModelData import com.ray650128.model.pojo.arModel.ModelData
import com.ray650128.model.pojo.arModelDto.ModelDataDto import com.ray650128.model.pojo.arModelDto.ModelDataDto
import com.ray650128.service.MaterialService import com.ray650128.service.MaterialService
import org.litote.kmongo.Id
fun ModelData.toDto(): ModelDataDto { fun ModelData.toDto(): ModelDataDto {
val service = MaterialService() val service = MaterialService()
return ModelDataDto( return ModelDataDto(
type = this.type, type = this.type,
material = service.findById(this.material.toString()), material = if (this.material != null) {
service.findById(this.material.toString())
} else null,
materials = if (this.materials != null) {
ArrayList<Material>().apply {
materials?.forEach { id ->
val material = service.findById(id.toString())
if (material != null) {
add(material)
}
}
}
} else null,
params = this.params params = this.params
) )
} }
@ -18,5 +32,10 @@ fun ModelDataDto.toModelData(): ModelData =
ModelData( ModelData(
type = this.type, type = this.type,
material = this.material?._id, material = this.material?._id,
materials = ArrayList<Id<Material>>().apply {
materials?.forEach { material ->
add(material._id)
}
},
params = this.params params = this.params
) )

View File

@ -9,5 +9,6 @@ import org.litote.kmongo.Id
data class ModelData( data class ModelData(
var type: Int = -1, var type: Int = -1,
@Contextual var material: Id<Material>? = null, @Contextual var material: Id<Material>? = null,
@Contextual var materials: List<Id<Material>>? = null,
var params: ModelParams var params: ModelParams
) )

View File

@ -10,5 +10,6 @@ import org.litote.kmongo.Id
data class ModelDataDto( data class ModelDataDto(
var type: Int = -1, var type: Int = -1,
var material: Material? = null, var material: Material? = null,
var materials: List<Material>? = null,
var params: ModelParams var params: ModelParams
) )

View File

@ -4,6 +4,7 @@ import com.ray650128.extension.*
import com.ray650128.model.ErrorResponse import com.ray650128.model.ErrorResponse
import com.ray650128.model.pojo.arModel.ArModel import com.ray650128.model.pojo.arModel.ArModel
import com.ray650128.model.pojo.User import com.ray650128.model.pojo.User
import com.ray650128.model.pojo.arModelDto.ArModelDto
import com.ray650128.service.ModelService import com.ray650128.service.ModelService
import com.ray650128.service.UserService import com.ray650128.service.UserService
import io.ktor.server.application.* import io.ktor.server.application.*
@ -34,12 +35,25 @@ fun Application.configureArModelRouting() {
call.sendSuccess(list) call.sendSuccess(list)
} }
get("/{id}") {
call.authentication.principal<User>()?.account ?: run {
call.sendUnauthorized()
return@get
}
val id = call.parameters["id"].toString()
val arModel = modelService.findById(id) ?: run {
call.sendNotFound()
return@get
}
call.sendSuccess(arModel.toDto())
}
post("/create") { post("/create") {
val user = call.authentication.principal<User>() ?: run { val user = call.authentication.principal<User>() ?: run {
call.sendUnauthorized() call.sendUnauthorized()
return@post return@post
} }
val body = call.receive<ArModel>() val body = call.receive<ArModelDto>().toArModel()
body.apply { body.apply {
ownerId = user._id ownerId = user._id
createAt = System.currentTimeMillis() createAt = System.currentTimeMillis()
@ -58,7 +72,7 @@ fun Application.configureArModelRouting() {
call.sendUnauthorized() call.sendUnauthorized()
return@put return@put
} }
val body = call.receive<ArModel>() val body = call.receive<ArModelDto>().toArModel()
val id = call.parameters["id"].toString() val id = call.parameters["id"].toString()
val isSuccess = modelService.updateById(id, body) val isSuccess = modelService.updateById(id, body)
call.sendSuccess(mapOf("success" to isSuccess)) call.sendSuccess(mapOf("success" to isSuccess))