mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
v5 wip
This commit is contained in:
@@ -113,6 +113,11 @@
|
||||
<artifactId>jna-platform</artifactId>
|
||||
<version>5.13.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>1.9.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.exposed</groupId>
|
||||
<artifactId>exposed-jdbc</artifactId>
|
||||
|
||||
@@ -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,
|
||||
|
||||
+15
-2
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ImageDownloadState>) {
|
||||
transaction { imageRepository.save(images) }
|
||||
images.forEach {
|
||||
eventBus.publishEvent(Event(Event.Kind.IMAGE_CREATE, it))
|
||||
}
|
||||
}
|
||||
|
||||
fun finishPost(postDownloadState: PostDownloadState) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ class PostModel(
|
||||
addedOn: String,
|
||||
order: Int,
|
||||
path: String,
|
||||
progressCount: String
|
||||
progressCount: String,
|
||||
val previewList: List<String>
|
||||
) {
|
||||
val postIdProperty = SimpleStringProperty(postId)
|
||||
var postId: String by postIdProperty
|
||||
|
||||
@@ -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<PostModel>
|
||||
private var items: ObservableList<PostModel> = 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<PostModel, String>()
|
||||
cell.onMouseEntered = EventHandler {
|
||||
cell.onMouseEntered = EventHandler { mouseEvent ->
|
||||
previewStage?.close()
|
||||
if(cell.text != null && cell.text.isNotBlank()) {
|
||||
previewStage = find<Preview>(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<Preview>(
|
||||
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<ImageView?> {
|
||||
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<String> by param()
|
||||
val images: List<ImageView> 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
|
||||
}
|
||||
Reference in New Issue
Block a user