diff --git a/pom.xml b/pom.xml
index 3f86661..143bc1d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,11 @@
jna-platform
5.13.0
+
+ kotlin-reflect
+ org.jetbrains.kotlin
+ 1.9.10
+
diff --git a/vripper-core/pom.xml b/vripper-core/pom.xml
index 8667de6..f48d042 100644
--- a/vripper-core/pom.xml
+++ b/vripper-core/pom.xml
@@ -26,6 +26,10 @@
org.jetbrains.kotlinx
kotlinx-coroutines-core-jvm
+
+ kotlin-reflect
+ org.jetbrains.kotlin
+
org.jetbrains.exposed
exposed-jdbc
diff --git a/vripper-core/src/main/kotlin/me/mnlr/vripper/entities/ImageDownloadState.kt b/vripper-core/src/main/kotlin/me/mnlr/vripper/entities/ImageDownloadState.kt
index 4493046..6579fa6 100644
--- a/vripper-core/src/main/kotlin/me/mnlr/vripper/entities/ImageDownloadState.kt
+++ b/vripper-core/src/main/kotlin/me/mnlr/vripper/entities/ImageDownloadState.kt
@@ -1,12 +1,12 @@
package me.mnlr.vripper.entities
import me.mnlr.vripper.entities.domain.Status
-import me.mnlr.vripper.host.Host
data class ImageDownloadState(
var id: Long? = null,
val postId: String,
val url: String,
+ val thumbUrl: String,
val host: String,
val index: Int,
val postIdRef: Long,
diff --git a/vripper-core/src/main/kotlin/me/mnlr/vripper/repositories/impl/ImageRepositoryImpl.kt b/vripper-core/src/main/kotlin/me/mnlr/vripper/repositories/impl/ImageRepositoryImpl.kt
index a411a18..c877c33 100644
--- a/vripper-core/src/main/kotlin/me/mnlr/vripper/repositories/impl/ImageRepositoryImpl.kt
+++ b/vripper-core/src/main/kotlin/me/mnlr/vripper/repositories/impl/ImageRepositoryImpl.kt
@@ -2,7 +2,6 @@ package me.mnlr.vripper.repositories.impl
import me.mnlr.vripper.entities.ImageDownloadState
import me.mnlr.vripper.entities.domain.Status
-import me.mnlr.vripper.event.Event
import me.mnlr.vripper.repositories.ImageRepository
import me.mnlr.vripper.tables.ImageTable
import org.jetbrains.exposed.sql.*
@@ -19,6 +18,7 @@ class ImageRepositoryImpl : ImageRepository {
it[status] = imageDownloadState.status.name
it[total] = imageDownloadState.total
it[url] = imageDownloadState.url
+ it[thumbUrl] = imageDownloadState.thumbUrl
it[postIdRef] = imageDownloadState.postIdRef
}.value
return imageDownloadState.copy(id = id)
@@ -33,6 +33,7 @@ class ImageRepositoryImpl : ImageRepository {
this[ImageTable.status] = it.status.name
this[ImageTable.total] = it.total
this[ImageTable.url] = it.url
+ this[ImageTable.thumbUrl] = it.thumbUrl
this[ImageTable.postIdRef] = it.postIdRef
}
}
@@ -96,12 +97,24 @@ class ImageRepositoryImpl : ImageRepository {
val id = resultRow[ImageTable.id].value
val postId = resultRow[ImageTable.postId]
val url = resultRow[ImageTable.url]
+ val thumbUrl = resultRow[ImageTable.thumbUrl]
val host = resultRow[ImageTable.host]
val index = resultRow[ImageTable.index]
val current = resultRow[ImageTable.current]
val total = resultRow[ImageTable.total]
val status = Status.valueOf(resultRow[ImageTable.status])
val postIdRef = resultRow[ImageTable.postIdRef]
- return ImageDownloadState(id, postId, url, host, index, postIdRef, total, current, status)
+ return ImageDownloadState(
+ id,
+ postId,
+ url,
+ thumbUrl,
+ host,
+ index,
+ postIdRef,
+ total,
+ current,
+ status
+ )
}
}
diff --git a/vripper-core/src/main/kotlin/me/mnlr/vripper/services/DataTransaction.kt b/vripper-core/src/main/kotlin/me/mnlr/vripper/services/DataTransaction.kt
index 84bf05d..a53577c 100644
--- a/vripper-core/src/main/kotlin/me/mnlr/vripper/services/DataTransaction.kt
+++ b/vripper-core/src/main/kotlin/me/mnlr/vripper/services/DataTransaction.kt
@@ -12,7 +12,6 @@ import me.mnlr.vripper.repositories.ImageRepository
import me.mnlr.vripper.repositories.MetadataRepository
import me.mnlr.vripper.repositories.PostDownloadStateRepository
import me.mnlr.vripper.repositories.ThreadRepository
-import me.mnlr.vripper.tables.ImageTable
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*
import kotlin.io.path.pathString
@@ -27,9 +26,7 @@ class DataTransaction(
) {
private fun save(postDownloadState: PostDownloadState): PostDownloadState {
- val createdPost = transaction { postDownloadStateRepository.save(postDownloadState) }
- eventBus.publishEvent(Event(Event.Kind.POST_CREATE, createdPost))
- return createdPost
+ return transaction { postDownloadStateRepository.save(postDownloadState) }
}
fun update(postDownloadState: PostDownloadState) {
@@ -57,7 +54,7 @@ class DataTransaction(
}
fun newPost(postItem: PostItem): PostDownloadState {
- return transaction {
+ val (post, images) = transaction {
val postDownloadState = save(
PostDownloadState(
postTitle = postItem.title,
@@ -82,6 +79,7 @@ class DataTransaction(
ImageDownloadState(
postId = postItem.postId,
url = imageItem.mainLink,
+ thumbUrl = imageItem.thumbLink,
host = imageItem.host.hostId,
index = index,
postIdRef = postDownloadState.id!!
@@ -89,15 +87,17 @@ class DataTransaction(
}
save(images)
sortPostsByRank()
- postDownloadState
+ Pair(postDownloadState, images)
}
+ eventBus.publishEvent(Event(Event.Kind.POST_CREATE, post))
+ images.forEach {
+ eventBus.publishEvent(Event(Event.Kind.IMAGE_CREATE, it))
+ }
+ return post
}
private fun save(images: List) {
transaction { imageRepository.save(images) }
- images.forEach {
- eventBus.publishEvent(Event(Event.Kind.IMAGE_CREATE, it))
- }
}
fun finishPost(postDownloadState: PostDownloadState) {
diff --git a/vripper-core/src/main/kotlin/me/mnlr/vripper/tables/ImageTable.kt b/vripper-core/src/main/kotlin/me/mnlr/vripper/tables/ImageTable.kt
index adee819..6994259 100644
--- a/vripper-core/src/main/kotlin/me/mnlr/vripper/tables/ImageTable.kt
+++ b/vripper-core/src/main/kotlin/me/mnlr/vripper/tables/ImageTable.kt
@@ -10,5 +10,6 @@ object ImageTable : LongIdTable(name = "IMAGE", columnName = "ROWID") {
val status = varchar("STATUS", 255)
val total = long("TOTAL")
val url = varchar("URL", 3000)
+ val thumbUrl = varchar("THUMB_URL", 3000)
val postIdRef = long("POST_ID_REF").references(PostTable.id, fkName = "IMAGE_POST_ID_REF_POST_ID_FK")
}
\ No newline at end of file
diff --git a/vripper-core/src/main/kotlin/me/mnlr/vripper/tasks/ThreadLookupRunnable.kt b/vripper-core/src/main/kotlin/me/mnlr/vripper/tasks/ThreadLookupRunnable.kt
index f7a2744..f105a17 100644
--- a/vripper-core/src/main/kotlin/me/mnlr/vripper/tasks/ThreadLookupRunnable.kt
+++ b/vripper-core/src/main/kotlin/me/mnlr/vripper/tasks/ThreadLookupRunnable.kt
@@ -42,13 +42,13 @@ class ThreadLookupRunnable(private val threadId: String, private val settings: S
override fun run() {
try {
eventRepository.update(logEvent.copy(status = PROCESSING))
- val threadLookupResult = threadCacheService[threadId]
- if (threadLookupResult.postItemList.isEmpty()) {
- val message = "Nothing found for $link"
- eventRepository.update(logEvent.copy(status = ERROR, message = message))
- return
- }
if (dataTransaction.findThreadByThreadId(threadId).isEmpty) {
+ val threadLookupResult = threadCacheService[threadId]
+ if (threadLookupResult.postItemList.isEmpty()) {
+ val message = "Nothing found for $link"
+ eventRepository.update(logEvent.copy(status = ERROR, message = message))
+ return
+ }
dataTransaction.save(
Thread(
title = threadLookupResult.title,
diff --git a/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/controller/PostController.kt b/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/controller/PostController.kt
index 5ad7071..92d1224 100644
--- a/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/controller/PostController.kt
+++ b/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/controller/PostController.kt
@@ -1,6 +1,7 @@
package me.mnlr.vripper.gui.controller
import me.mnlr.vripper.AppEndpointService
+import me.mnlr.vripper.entities.ImageDownloadState
import me.mnlr.vripper.entities.PostDownloadState
import me.mnlr.vripper.gui.model.PostModel
import me.mnlr.vripper.services.DataTransaction
@@ -59,7 +60,8 @@ class PostController : Controller() {
it.addedOn.format(dateTimeFormatter),
it.rank + 1,
it.downloadDirectory,
- "${it.done}/${it.total}"
+ "${it.done}/${it.total}",
+ dataTransaction.findImagesByPostId(it.postId).map(ImageDownloadState::thumbUrl).take(4)
)
}
}
\ No newline at end of file
diff --git a/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/model/PostModel.kt b/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/model/PostModel.kt
index fd3309a..983b228 100644
--- a/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/model/PostModel.kt
+++ b/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/model/PostModel.kt
@@ -17,7 +17,8 @@ class PostModel(
addedOn: String,
order: Int,
path: String,
- progressCount: String
+ progressCount: String,
+ val previewList: List
) {
val postIdProperty = SimpleStringProperty(postId)
var postId: String by postIdProperty
diff --git a/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/view/tables/PostsTableView.kt b/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/view/tables/PostsTableView.kt
index 02f0f1f..d699c5e 100644
--- a/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/view/tables/PostsTableView.kt
+++ b/vripper-gui/src/main/kotlin/me/mnlr/vripper/gui/view/tables/PostsTableView.kt
@@ -7,12 +7,16 @@ import javafx.scene.control.*
import javafx.scene.control.cell.TextFieldTableCell
import javafx.scene.image.ImageView
import javafx.scene.input.MouseButton
+import javafx.scene.layout.HBox
import javafx.stage.Stage
import javafx.stage.StageStyle
import javafx.util.Callback
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
+import kotlinx.coroutines.*
+import kotlinx.coroutines.flow.filter
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.javafx.JavaFx
+import kotlinx.coroutines.javafx.asFlow
import me.mnlr.vripper.entities.PostDownloadState
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
@@ -34,6 +38,7 @@ class PostsTableView : View() {
lateinit var tableView: TableView
private var items: ObservableList = FXCollections.observableArrayList()
private var previewStage: Stage? = null
+ private var previewLoadJob: Job? = null
init {
titleProperty.bind(items.sizeProperty.map {
@@ -44,21 +49,15 @@ class PostsTableView : View() {
}
})
- eventBus
- .flux()
- .filter { it!!.kind == Event.Kind.POST_CREATE }
- .map { postController.mapper(it.data as PostDownloadState) }
- .publishOn(FxScheduler)
+ eventBus.flux().filter { it!!.kind == Event.Kind.POST_CREATE }
+ .map { postController.mapper(it.data as PostDownloadState) }.publishOn(FxScheduler)
.doOnNext {
items.add(it)
this.tableView.refresh()
}.subscribe()
- eventBus
- .flux()
- .filter { it!!.kind == Event.Kind.POST_UPDATE }
- .map { postController.mapper(it.data as PostDownloadState) }
- .publishOn(FxScheduler)
+ eventBus.flux().filter { it!!.kind == Event.Kind.POST_UPDATE }
+ .map { postController.mapper(it.data as PostDownloadState) }.publishOn(FxScheduler)
.doOnNext {
items.find { postModel -> postModel.postId == it.postId }?.apply {
progress = it.progress
@@ -68,13 +67,9 @@ class PostsTableView : View() {
order = it.order
progressCount = it.progressCount
}
- }
- .subscribe()
+ }.subscribe()
- eventBus
- .flux()
- .filter { it!!.kind == Event.Kind.POST_REMOVE }
- .publishOn(FxScheduler)
+ eventBus.flux().filter { it!!.kind == Event.Kind.POST_REMOVE }.publishOn(FxScheduler)
.doOnNext {
items.removeIf { p -> p.postId == it.data as String }
}.subscribe()
@@ -168,9 +163,8 @@ class PostsTableView : View() {
locationItem,
urlItem
)
- tableRow.contextMenuProperty()
- .bind(
- tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu })
+ tableRow.contextMenuProperty().bind(tableRow.emptyProperty()
+ .map { empty -> if (empty) null else contextMenu })
tableRow
}
column("Title", PostModel::titleProperty) {
@@ -178,30 +172,45 @@ class PostsTableView : View() {
cellFactory = Callback {
val cell = TextFieldTableCell()
- cell.onMouseEntered = EventHandler {
+ cell.onMouseEntered = EventHandler { mouseEvent ->
previewStage?.close()
- if(cell.text != null && cell.text.isNotBlank()) {
- previewStage = find(mapOf(Preview::images to listOf(
-
- ))).openWindow(stageStyle = StageStyle.UNDECORATED, owner = null)?.apply {
- isAlwaysOnTop = true
- x = it.screenX + 10
- y = it.screenY
+ previewLoadJob?.cancel()
+ if (cell.text != null && cell.text.isNotBlank()) {
+ previewLoadJob = coroutineScope.launch(Dispatchers.Default) {
+ yield()
+ val map = cell.tableRow.item.previewList.map {
+ previewLoading(it).await()
+ }
+ yield()
+ withContext(Dispatchers.JavaFx) {
+ previewStage = find(
+ mapOf(
+ Preview::images to map
+ )
+ ).openWindow(stageStyle = StageStyle.UNDECORATED, owner = null)
+ ?.apply {
+ isAlwaysOnTop = true
+ x = mouseEvent.screenX + 20
+ y = mouseEvent.screenY + 10
+ }
+ }
}
}
}
cell.onMouseMoved = EventHandler {
previewStage?.apply {
- x = it.screenX + 10
- y = it.screenY
+ x = it.screenX + 20
+ y = it.screenY + 10
}
}
cell.onMouseExited = EventHandler {
previewStage?.close()
+ previewLoadJob?.cancel()
+ previewStage = null
+ previewLoadJob = null
}
cell
}
-
}
column("Progress", PostModel::progressProperty) {
cellFactory = Callback {
@@ -255,6 +264,24 @@ class PostsTableView : View() {
}
}
+ suspend fun previewLoading(url: String): Deferred {
+ return coroutineScope.async(Dispatchers.IO) {
+ val imageView = ImageView(url).apply {
+ isPreserveRatio = true
+ fitWidth = 200.0
+ }
+
+ val flow = imageView.image.progressProperty().asFlow()
+
+ val lastOrNull =
+ flow.filter { it == 1.0 }.map {
+ imageView
+ }.first()
+
+ lastOrNull
+ }
+ }
+
fun deleteSelected() {
val postIdList = tableView.selectionModel.selectedItems.map { it.postId }
confirm(
@@ -286,14 +313,14 @@ class PostsTableView : View() {
class Preview : Fragment("Preview") {
- val images: List by param()
+ val images: List by param()
+ private val hBox = HBox()
- override val root = hbox {
+ init {
images.forEach {
- imageview(it, lazyload = false) {
- fitWidth = 250.0
- isPreserveRatio = true
- }
+ hBox.add(it)
}
}
+
+ override val root = hBox
}
\ No newline at end of file