feat: 修改了upload_file消息格式,添加了文件预览部分的接口
parent
d35157e124
commit
9d495a8dbc
|
@ -37,8 +37,6 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-elasticsearch")
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
|
@ -50,17 +48,23 @@ dependencies {
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$kotlinxCoroutinesVersion")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$kotlinxCoroutinesVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk9:$kotlinxCoroutinesVersion")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk9:$kotlinxCoroutinesVersion")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion")
|
||||||
|
// kotlin 反射
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
// sa-token 安全认证框架
|
// sa-token 安全认证框架
|
||||||
implementation("cn.dev33:sa-token-spring-boot3-starter:1.35.0.RC")
|
implementation("cn.dev33:sa-token-spring-boot3-starter:1.35.0.RC")
|
||||||
// jimmer 持久层框架
|
// jimmer 持久层框架
|
||||||
implementation("org.babyfish.jimmer:jimmer-spring-boot-starter:0.7.104")
|
implementation("org.babyfish.jimmer:jimmer-spring-boot-starter:0.7.104")
|
||||||
ksp("org.babyfish.jimmer:jimmer-ksp:0.7.104")
|
ksp("org.babyfish.jimmer:jimmer-ksp:0.7.104")
|
||||||
// developmentOnly("org.springframework.boot:spring-boot-docker-compose")
|
|
||||||
implementation("org.postgresql:postgresql")
|
implementation("org.postgresql:postgresql")
|
||||||
// Kafka
|
// Kafka
|
||||||
implementation("org.springframework.kafka:spring-kafka")
|
implementation("org.springframework.kafka:spring-kafka")
|
||||||
|
// redis
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
||||||
|
// 腾讯云COS
|
||||||
|
implementation("com.qcloud:cos_api:5.6.133")
|
||||||
|
// configuration processor
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
// test
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package cn.edu.hfut.auto.knowledge
|
package cn.edu.hfut.auto.knowledge
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ConfigurationPropertiesScan
|
||||||
@RestController
|
@RestController
|
||||||
class AicsKnowledgeBaseBackendApplication {
|
class AicsKnowledgeBaseBackendApplication {
|
||||||
@RequestMapping("/hello")
|
@RequestMapping("/hello")
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cn.edu.hfut.auto.knowledge.config
|
||||||
|
|
||||||
|
import com.qcloud.cos.COSClient
|
||||||
|
import com.qcloud.cos.ClientConfig
|
||||||
|
import com.qcloud.cos.auth.BasicCOSCredentials
|
||||||
|
import com.qcloud.cos.region.Region
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class TencentAPIConfig
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class COSClientWrapper(tencentProperties: TencentProperties) : COSClient(
|
||||||
|
BasicCOSCredentials(tencentProperties.secretId, tencentProperties.secretKey),
|
||||||
|
ClientConfig(Region(tencentProperties.cosRegion))
|
||||||
|
) {
|
||||||
|
val bucketName = tencentProperties.bucketName
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigurationProperties(prefix = "tencent")
|
||||||
|
data class TencentProperties(
|
||||||
|
val secretId: String,
|
||||||
|
val secretKey: String,
|
||||||
|
val cosRegion: String,
|
||||||
|
val bucketName: String
|
||||||
|
)
|
|
@ -1,10 +1,8 @@
|
||||||
package cn.edu.hfut.auto.knowledge.controller
|
package cn.edu.hfut.auto.knowledge.controller
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckRole
|
import cn.dev33.satoken.annotation.SaCheckRole
|
||||||
import cn.edu.hfut.auto.knowledge.entity.Knowledge
|
import cn.edu.hfut.auto.knowledge.config.COSClientWrapper
|
||||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeDraft
|
import cn.edu.hfut.auto.knowledge.entity.*
|
||||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
|
||||||
import cn.edu.hfut.auto.knowledge.entity.by
|
|
||||||
import cn.edu.hfut.auto.knowledge.entity.rpc.FileTicket
|
import cn.edu.hfut.auto.knowledge.entity.rpc.FileTicket
|
||||||
import cn.edu.hfut.auto.knowledge.entity.vo.KnowledgeFileUploadVO
|
import cn.edu.hfut.auto.knowledge.entity.vo.KnowledgeFileUploadVO
|
||||||
import cn.edu.hfut.auto.knowledge.exception.BusinessError
|
import cn.edu.hfut.auto.knowledge.exception.BusinessError
|
||||||
|
@ -12,6 +10,7 @@ import cn.edu.hfut.auto.knowledge.exception.ErrorCode
|
||||||
import cn.edu.hfut.auto.knowledge.repository.KnowledgeFileAttributeRepository
|
import cn.edu.hfut.auto.knowledge.repository.KnowledgeFileAttributeRepository
|
||||||
import cn.edu.hfut.auto.knowledge.repository.KnowledgeRepository
|
import cn.edu.hfut.auto.knowledge.repository.KnowledgeRepository
|
||||||
import cn.edu.hfut.auto.knowledge.util.fileSuffix
|
import cn.edu.hfut.auto.knowledge.util.fileSuffix
|
||||||
|
import com.qcloud.cos.model.ciModel.job.DocHtmlRequest
|
||||||
import kotlinx.coroutines.future.await
|
import kotlinx.coroutines.future.await
|
||||||
import org.apache.kafka.common.KafkaException
|
import org.apache.kafka.common.KafkaException
|
||||||
import org.babyfish.jimmer.kt.new
|
import org.babyfish.jimmer.kt.new
|
||||||
|
@ -33,7 +32,8 @@ const val UPLOAD_FILE_TOPIC = "upload_file"
|
||||||
class KnowledgeController(
|
class KnowledgeController(
|
||||||
private val kafkaTemplate: KafkaTemplate<String, Any?>,
|
private val kafkaTemplate: KafkaTemplate<String, Any?>,
|
||||||
private val knowledgeRepository: KnowledgeRepository,
|
private val knowledgeRepository: KnowledgeRepository,
|
||||||
private val knowledgeFileAttributeRepository: KnowledgeFileAttributeRepository
|
private val knowledgeFileAttributeRepository: KnowledgeFileAttributeRepository,
|
||||||
|
private val cosClientWrapper: COSClientWrapper
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@GetMapping("/{knowledgeId}")
|
@GetMapping("/{knowledgeId}")
|
||||||
|
@ -84,4 +84,20 @@ class KnowledgeController(
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{knowledgeId}/preview/external")
|
||||||
|
suspend fun getExternalPreviewKnowledgeUrl(@PathVariable knowledgeId: UUID): String {
|
||||||
|
knowledgeRepository.findNullable(knowledgeId, Knowledge.BRIEF_FETCHER)
|
||||||
|
?.knowledgeFileAttribute
|
||||||
|
?.takeIf { it.externalPreviewable }
|
||||||
|
?.let {
|
||||||
|
val request = DocHtmlRequest().apply {
|
||||||
|
bucketName = cosClientWrapper.bucketName
|
||||||
|
dstType = DocHtmlRequest.DocType.html
|
||||||
|
objectKey = "${it.id}.${it.suffix}"
|
||||||
|
}
|
||||||
|
return cosClientWrapper.GenerateDocPreviewUrl(request)
|
||||||
|
}
|
||||||
|
?: throw BusinessError(ErrorCode.RESOURCE_NOT_FOUND)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,6 +31,7 @@ interface KnowledgeFileAttribute {
|
||||||
val notes: List<Note>
|
val notes: List<Note>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val EXTERNAL_PREVIEWABLE_SUFFIXES = listOf("pdf", "ppt", "pptx", "doc", "docx", "xls", "xlsx")
|
||||||
val BRIEF_FETCHER = newFetcher(KnowledgeFileAttribute::class).by {
|
val BRIEF_FETCHER = newFetcher(KnowledgeFileAttribute::class).by {
|
||||||
allScalarFields()
|
allScalarFields()
|
||||||
tags {
|
tags {
|
||||||
|
@ -38,4 +39,7 @@ interface KnowledgeFileAttribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline val KnowledgeFileAttribute.externalPreviewable: Boolean
|
||||||
|
get() = suffix in KnowledgeFileAttribute.EXTERNAL_PREVIEWABLE_SUFFIXES
|
|
@ -1,15 +1,18 @@
|
||||||
package cn.edu.hfut.auto.knowledge.entity.rpc
|
package cn.edu.hfut.auto.knowledge.entity.rpc
|
||||||
|
|
||||||
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
import cn.edu.hfut.auto.knowledge.entity.KnowledgeFileAttribute
|
||||||
|
import cn.edu.hfut.auto.knowledge.entity.externalPreviewable
|
||||||
import org.apache.commons.codec.digest.Sha2Crypt
|
import org.apache.commons.codec.digest.Sha2Crypt
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.UUID
|
import java.util.*
|
||||||
|
|
||||||
data class FileTicket(
|
data class FileTicket(
|
||||||
val ticket: String,
|
val ticket: String,
|
||||||
val id: UUID,
|
val id: UUID,
|
||||||
val md5: String,
|
val md5: String,
|
||||||
val size: Long
|
val size: Long,
|
||||||
|
val externalPreviewable: Boolean,
|
||||||
|
val suffix: String
|
||||||
) {
|
) {
|
||||||
constructor(knowledgeFileAttribute: KnowledgeFileAttribute, md5: String): this(
|
constructor(knowledgeFileAttribute: KnowledgeFileAttribute, md5: String): this(
|
||||||
buildString {
|
buildString {
|
||||||
|
@ -19,10 +22,12 @@ data class FileTicket(
|
||||||
append(LocalDateTime.now())
|
append(LocalDateTime.now())
|
||||||
}
|
}
|
||||||
}.let {
|
}.let {
|
||||||
Sha2Crypt.sha256Crypt(it.toByteArray())
|
Sha2Crypt.sha256Crypt(it.toByteArray())
|
||||||
},
|
},
|
||||||
knowledgeFileAttribute.id,
|
knowledgeFileAttribute.id,
|
||||||
md5,
|
md5,
|
||||||
knowledgeFileAttribute.size
|
knowledgeFileAttribute.size,
|
||||||
|
knowledgeFileAttribute.externalPreviewable,
|
||||||
|
knowledgeFileAttribute.suffix
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,4 +30,10 @@ logging:
|
||||||
config: classpath:log4j2-dev.xml
|
config: classpath:log4j2-dev.xml
|
||||||
|
|
||||||
aics:
|
aics:
|
||||||
max-permission-level: 3
|
max-permission-level: 3
|
||||||
|
|
||||||
|
tencent:
|
||||||
|
secret-id: AKIDSlvvhEYfYBetvYzCBvhJrDLGwNbcR2B7
|
||||||
|
secret-key: kHZigS3UkqlY8WiuypXM3ZwCHA0iHepp
|
||||||
|
cos-region: ap-nanjing
|
||||||
|
bucket-name: aics-1300085057
|
|
@ -29,4 +29,10 @@ logging:
|
||||||
config: classpath:log4j2-prod.xml
|
config: classpath:log4j2-prod.xml
|
||||||
|
|
||||||
aics:
|
aics:
|
||||||
max-permission-level: 3
|
max-permission-level: 3
|
||||||
|
|
||||||
|
tencent:
|
||||||
|
secret-id: AKIDSlvvhEYfYBetvYzCBvhJrDLGwNbcR2B7
|
||||||
|
secret-key: kHZigS3UkqlY8WiuypXM3ZwCHA0iHepp
|
||||||
|
cos-region: ap-nanjing
|
||||||
|
bucket-name: aics-1300085057
|
Loading…
Reference in New Issue