This commit is contained in:
death-claw
2023-10-06 09:31:02 +01:00
parent c08c430160
commit d9e8e08adb
15 changed files with 148 additions and 77 deletions
+71 -2
View File
@@ -15,7 +15,6 @@
<version>4.4.0</version>
<properties>
<java.version>17</java.version>
<kotlin.version>1.8.21</kotlin.version>
<maven.deploy.skip>false</maven.deploy.skip>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
@@ -24,11 +23,31 @@
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
<version>1.4.11</version>
</dependency>
<dependency>
<artifactId>kotlin-stdlib</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>1.9.10</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.exposed</groupId>
<artifactId>exposed-jdbc</artifactId>
<version>0.41.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.exposed</groupId>
<artifactId>exposed-java-time</artifactId>
<version>0.41.1</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
@@ -41,9 +60,59 @@
</dependency>
<dependency>
<groupId>io.insert-koin</groupId>
<artifactId>koin-core</artifactId>
<artifactId>koin-core-jvm</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
<version>2.15.2</version>
</dependency>
<dependency>
<artifactId>h2</artifactId>
<groupId>com.h2database</groupId>
<version>2.2.224</version>
</dependency>
<dependency>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<version>4.5.14</version>
</dependency>
<dependency>
<artifactId>htmlcleaner</artifactId>
<groupId>net.sourceforge.htmlcleaner</groupId>
<version>2.26</version>
</dependency>
<dependency>
<artifactId>failsafe</artifactId>
<groupId>net.jodah</groupId>
<version>2.4.4</version>
</dependency>
<dependency>
<artifactId>caffeine</artifactId>
<groupId>com.github.ben-manes.caffeine</groupId>
<version>3.1.8</version>
</dependency>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.13.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
-29
View File
@@ -17,92 +17,70 @@
<dependency>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
<version>1.4.11</version>
</dependency>
<dependency>
<artifactId>kotlin-reflect</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>1.8.22</version>
</dependency>
<dependency>
<artifactId>kotlin-stdlib</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.exposed</groupId>
<artifactId>exposed-jdbc</artifactId>
<version>0.41.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.exposed</groupId>
<artifactId>exposed-java-time</artifactId>
<version>0.41.1</version>
</dependency>
<dependency>
<groupId>io.insert-koin</groupId>
<artifactId>koin-core-jvm</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<artifactId>jackson-module-kotlin</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
<version>2.15.2</version>
</dependency>
<dependency>
<artifactId>h2</artifactId>
<groupId>com.h2database</groupId>
<version>2.2.224</version>
</dependency>
<dependency>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<version>4.5.14</version>
</dependency>
<dependency>
<artifactId>htmlcleaner</artifactId>
<groupId>net.sourceforge.htmlcleaner</groupId>
<version>2.26</version>
</dependency>
<dependency>
<artifactId>reactor-core</artifactId>
<groupId>io.projectreactor</groupId>
<version>3.5.10</version>
</dependency>
<dependency>
<artifactId>failsafe</artifactId>
<groupId>net.jodah</groupId>
<version>2.4.4</version>
</dependency>
<dependency>
<artifactId>caffeine</artifactId>
<groupId>com.github.ben-manes.caffeine</groupId>
<version>3.1.8</version>
</dependency>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.13.0</version>
</dependency>
</dependencies>
@@ -128,13 +106,6 @@
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<artifactId>kotlin-maven-allopen</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
@@ -18,7 +18,7 @@ val coreModule = module {
SettingsService(get())
}
single<ImageRepository> {
ImageRepositoryImpl(get())
ImageRepositoryImpl()
}
single<PostDownloadStateRepository> {
PostDownloadStateRepositoryImpl()
@@ -245,9 +245,10 @@ class DownloadService(
private fun afterJobFinish(imageDownloadRunnable: ImageDownloadRunnable) {
lock.withLock {
running[imageDownloadRunnable.context.image.host]!!.remove(imageDownloadRunnable)
if (!isPending(imageDownloadRunnable.context.image.postId) && !isRunning(
imageDownloadRunnable.context.image.postId
val image = imageDownloadRunnable.context.image
running[image.host]!!.remove(imageDownloadRunnable)
if (!isPending(image.postId) && !isRunning(
image.postId
)
) {
dataTransaction.finishPost(imageDownloadRunnable.context.post)
@@ -2,6 +2,6 @@ package me.mnlr.vripper.event
data class Event<T>(val kind: Kind, val data: T?) {
enum class Kind {
POST_CREATE, POST_UPDATE, POST_REMOVE, IMAGE_UPDATE, METADATA_UPDATE, THREAD_CREATE, THREAD_REMOVE, LOG_EVENT_UPDATE, LOG_EVENT_REMOVE, VG_USER, DOWNLOAD_STATUS, SETTINGS_UPDATE, THREAD_CLEAR
POST_CREATE, POST_UPDATE, POST_REMOVE, IMAGE_CREATE, IMAGE_UPDATE, METADATA_UPDATE, THREAD_CREATE, THREAD_REMOVE, LOG_EVENT_UPDATE, LOG_EVENT_REMOVE, VG_USER, DOWNLOAD_STATUS, SETTINGS_UPDATE, THREAD_CLEAR
}
}
@@ -6,6 +6,6 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
object EventBusScheduler {
private val executor: ExecutorService = Executors.newSingleThreadExecutor()
private val executor: ExecutorService = Executors.newCachedThreadPool()
val scheduler: Scheduler = Schedulers.fromExecutor(executor)
}
@@ -3,17 +3,15 @@ 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.event.EventBus
import me.mnlr.vripper.repositories.ImageRepository
import me.mnlr.vripper.tables.ImageTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import java.util.*
class ImageRepositoryImpl(private val eventBus: EventBus) : ImageRepository {
class ImageRepositoryImpl : ImageRepository {
override fun save(imageDownloadState: ImageDownloadState): ImageDownloadState {
val insertStatement = ImageTable.insert {
val id = ImageTable.insertAndGetId {
it[current] = imageDownloadState.current
it[host] = imageDownloadState.host
it[index] = imageDownloadState.index
@@ -22,11 +20,8 @@ class ImageRepositoryImpl(private val eventBus: EventBus) : ImageRepository {
it[total] = imageDownloadState.total
it[url] = imageDownloadState.url
it[postIdRef] = imageDownloadState.postIdRef
}
eventBus.publishEvent(Event(Event.Kind.IMAGE_UPDATE, insertStatement[ImageTable.id].value))
return imageDownloadState.copy(
id = insertStatement[ImageTable.id].value
)
}.value
return imageDownloadState.copy(id = id)
}
override fun save(imageDownloadStateList: List<ImageDownloadState>) {
@@ -43,7 +38,7 @@ class ImageRepositoryImpl(private val eventBus: EventBus) : ImageRepository {
}
override fun deleteAllByPostId(postId: String) {
ImageTable.deleteWhere {ImageTable.postId eq postId}
ImageTable.deleteWhere { ImageTable.postId eq postId }
}
override fun findByPostId(postId: String): List<ImageDownloadState> {
@@ -67,7 +62,7 @@ class ImageRepositoryImpl(private val eventBus: EventBus) : ImageRepository {
}
override fun stopByPostIdAndIsNotCompleted(postId: String): Int {
return ImageTable.update({(ImageTable.postId eq postId) and (ImageTable.status neq Status.FINISHED.name)}) {
return ImageTable.update({ (ImageTable.postId eq postId) and (ImageTable.status neq Status.FINISHED.name) }) {
it[status] = Status.STOPPED.name
}
}
@@ -90,12 +85,11 @@ class ImageRepositoryImpl(private val eventBus: EventBus) : ImageRepository {
}
override fun update(imageDownloadState: ImageDownloadState) {
ImageTable.update({ImageTable.id eq imageDownloadState.id}) {
ImageTable.update({ ImageTable.id eq imageDownloadState.id }) {
it[status] = imageDownloadState.status.name
it[current] = imageDownloadState.current
it[total] = imageDownloadState.total
}
eventBus.publishEvent(Event(Event.Kind.IMAGE_UPDATE, imageDownloadState.id))
}
private fun transform(resultRow: ResultRow): ImageDownloadState {
@@ -67,7 +67,7 @@ class PostDownloadStateRepositoryImpl :
}
override fun existByPostId(postId: String): Boolean {
return PostTable.slice(PostTable.id).selectAll().count() > 0
return PostTable.slice(PostTable.id).select { PostTable.postId eq postId }.count() > 0
}
override fun setDownloadingToStopped(): Int {
@@ -12,6 +12,7 @@ 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
@@ -48,6 +49,7 @@ class DataTransaction(
fun update(imageDownloadState: ImageDownloadState) {
transaction { imageRepository.update(imageDownloadState) }
eventBus.publishEvent(Event(Event.Kind.IMAGE_UPDATE, imageDownloadState))
}
fun exists(postId: String): Boolean {
@@ -93,6 +95,9 @@ class DataTransaction(
private fun save(images: List<ImageDownloadState>) {
transaction { imageRepository.save(images) }
images.forEach {
eventBus.publishEvent(Event(Event.Kind.IMAGE_CREATE, it))
}
}
fun finishPost(postDownloadState: PostDownloadState) {
-14
View File
@@ -16,20 +16,13 @@
<javafx.version>20.0.1</javafx.version>
</properties>
<dependencies>
<dependency>
<artifactId>kotlin-reflect</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>1.8.22</version>
</dependency>
<dependency>
<artifactId>kotlin-stdlib</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
@@ -138,13 +131,6 @@
<arg>-Xjsr305=strict</arg>
</args>
</configuration>
<dependencies>
<dependency>
<artifactId>kotlin-maven-allopen</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
@@ -38,6 +38,8 @@ class VripperGuiApplication : App(
with(stage) {
width = 1200.0
height = 600.0
minWidth = 600.0
minHeight = 400.0
icons.addAll(
listOf(
Image("icons/16x16.png"),
@@ -17,6 +17,7 @@ class ClipboardService(
private val eventBusDisposable: Disposable
private var current: String? = null
private var coroutineScope = CoroutineScope(Dispatchers.JavaFx)
private var pollJob: Job? = null
init {
eventBusDisposable = eventBus
@@ -26,9 +27,9 @@ class ClipboardService(
}
fun init() {
coroutineScope.cancel()
pollJob?.cancel()
if(settingsService.settings.clipboardSettings.enable) {
coroutineScope.launch {
pollJob = coroutineScope.launch {
while (isActive) {
poll()
delay(settingsService.settings.clipboardSettings.pollingRate.toLong())
@@ -14,11 +14,7 @@ class ImageController : Controller() {
return dataTransaction.findImagesByPostId(postId).map(::mapper)
}
fun findImageById(id: Long): Optional<ImageModel> {
return dataTransaction.findImageById(id).map(::mapper)
}
private fun mapper(it: ImageDownloadState): ImageModel {
fun mapper(it: ImageDownloadState): ImageModel {
return ImageModel(
it.id!!,
it.index + 1,
@@ -7,6 +7,7 @@ import javafx.scene.control.*
import javafx.scene.image.ImageView
import javafx.scene.input.MouseButton
import javafx.util.Callback
import me.mnlr.vripper.entities.ImageDownloadState
import me.mnlr.vripper.event.Event
import me.mnlr.vripper.event.EventBus
import me.mnlr.vripper.gui.controller.ImageController
@@ -36,11 +37,9 @@ class ImagesTableView : Fragment("Photos") {
val disposable = eventBus
.flux()
.filter { it!!.kind == Event.Kind.IMAGE_UPDATE }
.map { imageController.findImageById(it!!.data as Long) }
.filter { it.isPresent }
.map { it.get() }
.filter { it.postId == postId }
.filter { it.kind == Event.Kind.IMAGE_UPDATE }
.filter { (it.data as ImageDownloadState).postId == postId }
.map { imageController.mapper(it.data as ImageDownloadState) }
.publishOn(FxScheduler)
.doOnNext { image ->
val find = items
@@ -2,9 +2,13 @@ package me.mnlr.vripper.gui.view.tables
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.event.EventHandler
import javafx.scene.control.*
import javafx.scene.control.cell.TextFieldTableCell
import javafx.scene.image.ImageView
import javafx.scene.input.MouseButton
import javafx.stage.Stage
import javafx.stage.StageStyle
import javafx.util.Callback
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -29,6 +33,7 @@ class PostsTableView : View() {
lateinit var tableView: TableView<PostModel>
private var items: ObservableList<PostModel> = FXCollections.observableArrayList()
private var previewStage: Stage? = null
init {
titleProperty.bind(items.sizeProperty.map {
@@ -170,6 +175,33 @@ class PostsTableView : View() {
}
column("Title", PostModel::titleProperty) {
prefWidth = 300.0
cellFactory = Callback {
val cell = TextFieldTableCell<PostModel, String>()
cell.onMouseEntered = EventHandler {
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
}
}
}
cell.onMouseMoved = EventHandler {
previewStage?.apply {
x = it.screenX + 10
y = it.screenY
}
}
cell.onMouseExited = EventHandler {
previewStage?.close()
}
cell
}
}
column("Progress", PostModel::progressProperty) {
cellFactory = Callback {
@@ -249,4 +281,19 @@ class PostsTableView : View() {
private fun openPhotos(postId: String) {
find<ImagesTableView>(mapOf(ImagesTableView::postId to postId)).openModal()
}
}
class Preview : Fragment("Preview") {
val images: List<String> by param()
override val root = hbox {
images.forEach {
imageview(it, lazyload = false) {
fitWidth = 250.0
isPreserveRatio = true
}
}
}
}