Updated UI
This commit is contained in:
parent
ac227f075f
commit
6f0ff2da7c
@ -3,6 +3,7 @@ package no.iktdev.mediaprocessing.ui
|
|||||||
import no.iktdev.mediaprocessing.shared.common.Defaults
|
import no.iktdev.mediaprocessing.shared.common.Defaults
|
||||||
import no.iktdev.mediaprocessing.shared.common.socket.SocketImplementation
|
import no.iktdev.mediaprocessing.shared.common.socket.SocketImplementation
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
|
import org.springframework.boot.web.client.RestTemplateBuilder
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
@ -15,6 +16,8 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry
|
|||||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer
|
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||||
|
import org.springframework.web.util.DefaultUriBuilderFactory
|
||||||
|
import org.springframework.web.util.UriTemplateHandler
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -53,6 +56,7 @@ class ApiCommunicationConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
fun coordinatorTemplate(): RestTemplate {
|
fun coordinatorTemplate(): RestTemplate {
|
||||||
val restTemplate = RestTemplate()
|
val restTemplate = RestTemplate()
|
||||||
|
restTemplate.uriTemplateHandler = DefaultUriBuilderFactory(UIEnv.coordinatorUrl)
|
||||||
return restTemplate
|
return restTemplate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ class UIApplication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var eventsDatabase: EventsDatabase
|
lateinit var eventsDatabase: EventsDatabase
|
||||||
|
|
||||||
lateinit var taskManager: TasksManager
|
lateinit var taskManager: TasksManager
|
||||||
|
|
||||||
@ -47,7 +47,6 @@ fun getContext(): ApplicationContext? {
|
|||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
val fileRegister: ObservableMap<String, ExplorerItem> = observableMapOf()
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ class ExplorerCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getHomeCursor(): ExplorerCursor? {
|
fun getHomeCursor(): ExplorerCursor? {
|
||||||
return getCursor(SharedConfig.incomingContent.absolutePath)
|
return getCursor(SharedConfig.inputRoot.absolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,60 +0,0 @@
|
|||||||
package no.iktdev.mediaprocessing.ui.service
|
|
||||||
|
|
||||||
import dev.vishna.watchservice.KWatchEvent
|
|
||||||
import dev.vishna.watchservice.asWatchChannel
|
|
||||||
import kotlinx.coroutines.channels.consumeEach
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import no.iktdev.mediaprocessing.shared.common.SharedConfig
|
|
||||||
import no.iktdev.mediaprocessing.ui.explorer.ExplorerCore
|
|
||||||
import no.iktdev.mediaprocessing.ui.fileRegister
|
|
||||||
import no.iktdev.mediaprocessing.ui.ioCoroutine
|
|
||||||
import org.springframework.stereotype.Service
|
|
||||||
import java.io.File
|
|
||||||
import java.math.BigInteger
|
|
||||||
import java.security.MessageDigest
|
|
||||||
|
|
||||||
@Service
|
|
||||||
class FileRegisterService {
|
|
||||||
val watcherChannel = SharedConfig.incomingContent.asWatchChannel()
|
|
||||||
val core = ExplorerCore()
|
|
||||||
|
|
||||||
fun fid(name: String): String {
|
|
||||||
val md = MessageDigest.getInstance("MD5")
|
|
||||||
return BigInteger(1, md.digest(name.toByteArray())).toString(16).padStart(32, '0')
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addFileToIndex(it: KWatchEvent) {
|
|
||||||
core.fromFile(it.file)?.let { info ->
|
|
||||||
val fid = fid(it.file.name)
|
|
||||||
fileRegister.put(fid, info)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private fun indexItemsInFolder(it: File) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun indexItems() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
ioCoroutine.launch {
|
|
||||||
watcherChannel.consumeEach {
|
|
||||||
when (it.kind) {
|
|
||||||
KWatchEvent.Kind.Created, KWatchEvent.Kind.Modified, KWatchEvent.Kind.Initialized -> {
|
|
||||||
if (it.file.isDirectory) {
|
|
||||||
indexItemsInFolder(it.file)
|
|
||||||
} else {
|
|
||||||
addFileToIndex(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KWatchEvent.Kind.Deleted -> {
|
|
||||||
val fid = fid(it.file.name)
|
|
||||||
fileRegister.remove(fid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package no.iktdev.mediaprocessing.ui.socket
|
||||||
|
|
||||||
|
import no.iktdev.eventi.database.withTransaction
|
||||||
|
import no.iktdev.mediaprocessing.shared.common.contract.dto.EventRequest
|
||||||
|
import no.iktdev.mediaprocessing.shared.common.database.tables.files
|
||||||
|
import no.iktdev.mediaprocessing.shared.common.database.tables.filesProcessed
|
||||||
|
import no.iktdev.mediaprocessing.ui.UIEnv
|
||||||
|
import no.iktdev.mediaprocessing.ui.eventsDatabase
|
||||||
|
import org.jetbrains.exposed.sql.select
|
||||||
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
import org.springframework.messaging.handler.annotation.MessageMapping
|
||||||
|
import org.springframework.messaging.handler.annotation.Payload
|
||||||
|
import org.springframework.messaging.simp.SimpMessagingTemplate
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled
|
||||||
|
import org.springframework.stereotype.Controller
|
||||||
|
import org.springframework.web.client.RestTemplate
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@EnableScheduling
|
||||||
|
class UnprocessedFilesTopic(
|
||||||
|
@Autowired private val template: SimpMessagingTemplate?,
|
||||||
|
@Autowired private val coordinatorTemplate: RestTemplate,
|
||||||
|
) {
|
||||||
|
fun pullUnprocessedFiles(): List<FileInfo> = withTransaction(eventsDatabase.database) {
|
||||||
|
files.select {
|
||||||
|
files.checksum notInSubQuery filesProcessed.slice(filesProcessed.checksum).selectAll()
|
||||||
|
}.mapNotNull {
|
||||||
|
FileInfo(
|
||||||
|
it[files.baseName],
|
||||||
|
it[files.fileName],
|
||||||
|
it[files.checksum]
|
||||||
|
)
|
||||||
|
}.filter { File(it.fileName).exists() }
|
||||||
|
} ?: emptyList()
|
||||||
|
|
||||||
|
|
||||||
|
@MessageMapping("/files")
|
||||||
|
fun getUnprocessedFiles() {
|
||||||
|
refreshUnprocessedFiles()
|
||||||
|
}
|
||||||
|
@MessageMapping("/request/process")
|
||||||
|
fun requestProcess(@Payload data: EventRequest) {
|
||||||
|
val req = coordinatorTemplate.postForEntity("/request/all", data, String::class.java)
|
||||||
|
log.info { "RequestProcess report:\n\tStatus: ${req.statusCode}\n\tMessage: ${req.body}" }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(fixedDelay = 5_000)
|
||||||
|
fun refreshUnprocessedFiles() {
|
||||||
|
val unprocessedFiles = pullUnprocessedFiles()
|
||||||
|
template?.convertAndSend("/topic/files/unprocessed", unprocessedFiles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class FileInfo(
|
||||||
|
val name: String,
|
||||||
|
val fileName: String,
|
||||||
|
val checksum: String
|
||||||
|
)
|
||||||
@ -1,6 +1,9 @@
|
|||||||
package no.iktdev.mediaprocessing.shared.common.contract.dto
|
package no.iktdev.mediaprocessing.shared.common.contract.dto
|
||||||
|
|
||||||
|
import no.iktdev.mediaprocessing.shared.common.contract.ProcessType
|
||||||
|
|
||||||
data class EventRequest(
|
data class EventRequest(
|
||||||
val file: String, // FullPath
|
val file: String, // FullPath
|
||||||
override val source: String
|
override val source: String,
|
||||||
|
val mode: ProcessType = ProcessType.MANUAL
|
||||||
): Requester()
|
): Requester()
|
||||||
Loading…
Reference in New Issue
Block a user