mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
899e6d2893 | ||
|
|
4c96e79802 | ||
|
|
4a001efa9f | ||
|
|
7035b1cce0 | ||
|
|
b9862a5042 | ||
|
|
8bcdb80149 | ||
|
|
e44220321e | ||
|
|
f2c9806665 | ||
|
|
fd586a522c | ||
|
|
6be744a7a7 | ||
|
|
6228551836 |
@@ -8,12 +8,12 @@ jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
os: [ ubuntu-latest, windows-latest, macos-13, macos-latest ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up JDK 21
|
||||
- name: Set up jdk21
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '21'
|
||||
@@ -21,37 +21,29 @@ jobs:
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build parent project
|
||||
run: mvn -N -q install --file pom.xml
|
||||
|
||||
- name: Build Core Jar
|
||||
run: mvn -B -q install --file vripper-core/pom.xml
|
||||
|
||||
- name: Build GUI Jar
|
||||
run: mvn -B -q install --file vripper-gui/pom.xml
|
||||
|
||||
- name: Rename GUI Jar
|
||||
run: mv vripper-gui/target/vripper-gui-${{ github.event.release.tag_name }}-jar-with-dependencies.jar vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar
|
||||
- name: Build gui jar
|
||||
run: |
|
||||
mvn -N -q install --file pom.xml
|
||||
mvn -B -q install --file vripper-core/pom.xml
|
||||
mvn -B -q install --file vripper-gui/pom.xml
|
||||
mv vripper-gui/target/vripper-gui-${{ github.event.release.tag_name }}-jar-with-dependencies.jar vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Release GUI Jar
|
||||
name: Release gui Jar
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
# Start building WEB jar in ubuntu only
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Build WEB Jar
|
||||
name: Build web Jar
|
||||
run: |
|
||||
mvn -B -q install --file vripper-web-ui/pom.xml
|
||||
mvn -B -q install --file vripper-web/pom.xml
|
||||
mv vripper-web/target/vripper-web-${{ github.event.release.tag_name }}.jar vripper-web/target/vripper-noarch-web-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Rename WEB Jar
|
||||
run: mv vripper-web/target/vripper-web-${{ github.event.release.tag_name }}.jar vripper-web/target/vripper-noarch-web-${{ github.event.release.tag_name }}.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Release WEB Jar
|
||||
name: Release web Jar
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: vripper-web/target/vripper-noarch-web-${{ github.event.release.tag_name }}.jar
|
||||
@@ -62,7 +54,7 @@ jobs:
|
||||
cp vripper-gui/target/vripper-noarch-gui-${{ github.event.release.tag_name }}.jar jpackage/jar/vripper-gui.jar
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Package Linux
|
||||
name: Package for Linux
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.png
|
||||
@@ -72,7 +64,7 @@ jobs:
|
||||
mv dist/vripper_${{ github.event.release.tag_name }}-1_amd64.deb dist/vripper-linux-${{ github.event.release.tag_name }}_amd64.deb
|
||||
|
||||
- if: matrix.os == 'windows-latest'
|
||||
name: Package Windows
|
||||
name: Package for Windows
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.ico
|
||||
@@ -83,14 +75,24 @@ jobs:
|
||||
ren VRipper-${{ github.event.release.tag_name }}.exe vripper-windows-installer-${{ github.event.release.tag_name }}.exe
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Package macOS
|
||||
name: Package for macOS(arm64)
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.icns
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-macos.cfg" --type pkg
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-macos.cfg" --type dmg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.pkg dist/vripper-macos-${{ github.event.release.tag_name }}.pkg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.dmg dist/vripper-macos-${{ github.event.release.tag_name }}.dmg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.pkg dist/vripper-macos-${{ github.event.release.tag_name }}.arm64.pkg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.dmg dist/vripper-macos-${{ github.event.release.tag_name }}.arm64.dmg
|
||||
|
||||
- if: matrix.os == 'macos-13'
|
||||
name: Package for macOS(x86_64)
|
||||
run: |
|
||||
cd jpackage
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-app-image.cfg" --icon icon.icns
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-macos.cfg" --type pkg
|
||||
jpackage --app-version ${{ github.event.release.tag_name }} "@jpackage.cfg" "@jpackage-macos.cfg" --type dmg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.pkg dist/vripper-macos-${{ github.event.release.tag_name }}.x86_64.pkg
|
||||
mv dist/VRipper-${{ github.event.release.tag_name }}.dmg dist/vripper-macos-${{ github.event.release.tag_name }}.x86_64.dmg
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Zip Ubuntu portable
|
||||
@@ -111,13 +113,22 @@ jobs:
|
||||
filename: 'vripper-windows-portable-${{ github.event.release.tag_name }}.zip'
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Zip MacOS portable
|
||||
name: Zip macOS(arm64) portable
|
||||
uses: thedoctor0/zip-release@0.7.1
|
||||
with:
|
||||
type: 'zip'
|
||||
directory: 'jpackage/dist'
|
||||
path: 'VRipper.app'
|
||||
filename: 'vripper-macos-portable-${{ github.event.release.tag_name }}.zip'
|
||||
filename: 'vripper-macos-portable-${{ github.event.release.tag_name }}.arm64.zip'
|
||||
|
||||
- if: matrix.os == 'macos-13'
|
||||
name: Zip macOS(x86_64) portable
|
||||
uses: thedoctor0/zip-release@0.7.1
|
||||
with:
|
||||
type: 'zip'
|
||||
directory: 'jpackage/dist'
|
||||
path: 'VRipper.app'
|
||||
filename: 'vripper-macos-portable-${{ github.event.release.tag_name }}.x86_64.zip'
|
||||
|
||||
- if: matrix.os == 'ubuntu-latest'
|
||||
name: Release packages for Linux
|
||||
@@ -138,10 +149,19 @@ jobs:
|
||||
jpackage/dist/vripper-windows-portable-${{ github.event.release.tag_name }}.zip
|
||||
|
||||
- if: matrix.os == 'macos-latest'
|
||||
name: Release packages for macOS
|
||||
name: Release packages for macOS(arm64)
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.pkg
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.dmg
|
||||
jpackage/dist/vripper-macos-portable-${{ github.event.release.tag_name }}.zip
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.arm64.pkg
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.arm64.dmg
|
||||
jpackage/dist/vripper-macos-portable-${{ github.event.release.tag_name }}.arm64.zip
|
||||
|
||||
- if: matrix.os == 'macos-13'
|
||||
name: Release packages for macOS(x86_64)
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.x86_64.pkg
|
||||
jpackage/dist/vripper-macos-${{ github.event.release.tag_name }}.x86_64.dmg
|
||||
jpackage/dist/vripper-macos-portable-${{ github.event.release.tag_name }}.x86_64.zip
|
||||
|
||||
@@ -9,14 +9,20 @@ To support this project, you can make a donation to its current maintainer
|
||||
|
||||
[](https://buymeacoffee.com/devclaw)
|
||||
|
||||
Or with Cryptocurrency
|
||||
|
||||
ETH: 0xDdac82B16dC5E3D742fc915ffF583D8548A301cA
|
||||
|
||||
BTC: bc1qcqudnkrndwyadsjwrxww42svkf8trnzx3c8vlr
|
||||
|
||||
## Requirements
|
||||
Direct access to `vipergirls.to` domain.
|
||||
|
||||
## Installing VRipper
|
||||
|
||||
<img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/windows_logo.svg" width="100%" height="75"> Windows | <img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/mac_logo.svg" width="100%" height="75"> macOS | <img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/linux_logo.svg" width="100%" height="75"> Linux | <img src="https://images.vexels.com/media/users/3/166401/isolated/preview/b82aa7ac3f736dd78570dd3fa3fa9e24-java-programming-language-icon-by-vexels.png" width="100%" height="75"> Java
|
||||
:---:|:---:|:---:|:---:
|
||||
[Installer (EXE)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-windows-installer-6.3.0.exe) <br /> [Installer (MSI)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-windows-installer-6.3.0.msi) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-windows-portable-6.3.0.zip) | [Installer (DMG)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-macos-6.3.0.dmg) <br /> [Installer (PKG)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-macos-6.3.0.pkg) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-macos-portable-6.3.0.zip) | [Linux (amd64) (DEB)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-linux-6.3.0_amd64.deb) <br /> [Linux (x86_64) (RPM)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-linux-6.3.0.x86_64.rpm) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-linux-portable-6.3.0.zip) | [Java GUI (noarch)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-noarch-gui-6.3.0.jar) <br /> [Java Web (noarch)](https://github.com/death-claw/vripper-project/releases/download/6.3.0/vripper-noarch-web-6.3.0.jar)
|
||||
<img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/windows_logo.svg" width="100%" height="75"> Windows | <img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/mac_logo.svg" width="100%" height="75"> macOS (Intel) | <img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/mac_logo.svg" width="100%" height="75"> macOS (Apple silicon) | <img src="https://github.com/stashapp/stash/raw/develop/docs/readme_assets/linux_logo.svg" width="100%" height="75"> Linux | <img src="https://images.vexels.com/media/users/3/166401/isolated/preview/b82aa7ac3f736dd78570dd3fa3fa9e24-java-programming-language-icon-by-vexels.png" width="100%" height="75"> Java
|
||||
:---:|:---:|:---:|:---:|:---:
|
||||
[Installer (EXE)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-windows-installer-6.5.2.exe) <br /> [Installer (MSI)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-windows-installer-6.5.2.msi) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-windows-portable-6.5.2.zip) | [Installer (DMG)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-macos-6.5.2.x86_64.dmg) <br /> [Installer (PKG)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-macos-6.5.2.x86_64.pkg) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-macos-portable-6.5.2.x86_64.zip) | [Installer (DMG)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-macos-6.5.2.arm64.dmg) <br /> [Installer (PKG)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-macos-6.5.2.arm64.pkg) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-macos-portable-6.5.2.arm64.zip) | [Linux (amd64) (DEB)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-linux-6.5.2_amd64.deb) <br /> [Linux (x86_64) (RPM)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-linux-6.5.2.x86_64.rpm) <br /> [Portable (ZIP)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-linux-portable-6.5.2.zip) | [Java GUI (noarch)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-noarch-gui-6.5.2.jar) <br /> [Java Web (noarch)](https://github.com/death-claw/vripper-project/releases/download/6.5.2/vripper-noarch-web-6.5.2.jar)
|
||||
|
||||
Source code and previous versions are available on the [Releases page](https://github.com/death-claw/vripper-project/releases).
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<revision>6.3.0</revision>
|
||||
<revision>6.5.2</revision>
|
||||
<kotlin.version>2.0.21</kotlin.version>
|
||||
<slf4j.version>2.0.16</slf4j.version>
|
||||
<logback.version>1.5.12</logback.version>
|
||||
@@ -31,13 +31,13 @@
|
||||
<kotlinx-serialization-json.version>1.7.3</kotlinx-serialization-json.version>
|
||||
<httpclient5.version>5.4</httpclient5.version>
|
||||
<httpcore5.version>5.3</httpcore5.version>
|
||||
<commons-codec.version>1.17.1</commons-codec.version>
|
||||
<liquibase-core.version>4.29.2</liquibase-core.version>
|
||||
<liquibase-slf4j.version>5.0.0</liquibase-slf4j.version>
|
||||
<grpc.kotlin.version>1.4.1</grpc.kotlin.version>
|
||||
<java.grpc.version>1.68.1</java.grpc.version>
|
||||
<protobuf.version>3.25.5</protobuf.version>
|
||||
<sqlite-jdbc.version>3.47.0.0</sqlite-jdbc.version>
|
||||
<bucket4j_jdk17-core.version>8.14.0</bucket4j_jdk17-core.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -186,11 +186,6 @@
|
||||
<groupId>org.apache.httpcomponents.core5</groupId>
|
||||
<version>${httpcore5.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<groupId>org.liquibase</groupId>
|
||||
@@ -221,6 +216,11 @@
|
||||
<artifactId>protobuf-kotlin</artifactId>
|
||||
<version>${protobuf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bucket4j</groupId>
|
||||
<artifactId>bucket4j_jdk17-core</artifactId>
|
||||
<version>${bucket4j_jdk17-core.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
|
||||
@@ -75,10 +75,6 @@
|
||||
<artifactId>caffeine</artifactId>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<groupId>commons-codec</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna-platform</artifactId>
|
||||
@@ -108,6 +104,10 @@
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-kotlin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bucket4j</groupId>
|
||||
<artifactId>bucket4j_jdk17-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -136,14 +136,14 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
<jvmTarget>21</jvmTarget>
|
||||
<compilerPlugins>
|
||||
<plugin>kotlinx-serialization</plugin>
|
||||
</compilerPlugins>
|
||||
|
||||
@@ -8,7 +8,6 @@ import me.vripper.data.repositories.impl.ImageRepositoryImpl
|
||||
import me.vripper.data.repositories.impl.MetadataRepositoryImpl
|
||||
import me.vripper.data.repositories.impl.PostRepositoryImpl
|
||||
import me.vripper.data.repositories.impl.ThreadRepositoryImpl
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.host.*
|
||||
import me.vripper.services.*
|
||||
@@ -45,16 +44,16 @@ val coreModule = module {
|
||||
RetryPolicyService(get(), get())
|
||||
}
|
||||
single<HTTPService> {
|
||||
HTTPService(get(), get())
|
||||
HTTPService(get())
|
||||
}
|
||||
single<VGAuthService> {
|
||||
VGAuthService(get(), get(), get())
|
||||
VGAuthService(get(), get())
|
||||
}
|
||||
single<ThreadCacheService> {
|
||||
ThreadCacheService(get())
|
||||
ThreadCacheService(get(), get())
|
||||
}
|
||||
single<DownloadService> {
|
||||
DownloadService(get(), get(), get(), get(), get())
|
||||
DownloadService(get(), get(), get(), get())
|
||||
}
|
||||
single<DownloadSpeedService> {
|
||||
DownloadSpeedService(get())
|
||||
@@ -69,7 +68,7 @@ val coreModule = module {
|
||||
} bind IAppEndpointService::class
|
||||
|
||||
single<MetadataService> {
|
||||
MetadataService(get(), get(), get(), get())
|
||||
MetadataService(get(), get())
|
||||
}
|
||||
single {
|
||||
AcidimgHost(get(), get(), get())
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package me.vripper.download
|
||||
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.entities.ImageEntity
|
||||
import me.vripper.model.Settings
|
||||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
|
||||
internal class ImageDownloadContext(val imageEntity: ImageEntity, val settings: Settings) : KoinComponent {
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val jobs = mutableListOf<Job>()
|
||||
val httpContext: HttpClientContext =
|
||||
HttpClientContext.create().apply { cookieStore = BasicCookieStore() }
|
||||
val requests = mutableListOf<HttpUriRequestBase>()
|
||||
val postId = imageEntity.postIdRef
|
||||
|
||||
fun cancelCoroutines() {
|
||||
runBlocking {
|
||||
coroutineScope.cancel()
|
||||
jobs.forEach { job -> job.cancelAndJoin() }
|
||||
}
|
||||
}
|
||||
|
||||
fun launchCoroutine(block: suspend CoroutineScope.() -> Unit): Job {
|
||||
return coroutineScope.launch(block = block).also { job -> jobs.add(job) }
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package me.vripper.download
|
||||
|
||||
import dev.failsafe.function.CheckedRunnable
|
||||
import me.vripper.entities.ImageEntity
|
||||
import me.vripper.entities.Status
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.host.DownloadedImage
|
||||
import me.vripper.host.Host
|
||||
import me.vripper.host.ImageMimeType
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.PathUtils.getExtension
|
||||
import me.vripper.utilities.PathUtils.getFileNameWithoutExtension
|
||||
import me.vripper.utilities.PathUtils.sanitize
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.util.*
|
||||
import kotlin.Throws
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
internal class ImageDownloadRunnable(
|
||||
val imageEntity: ImageEntity, val postRank: Int, private val settings: Settings
|
||||
) : KoinComponent, CheckedRunnable {
|
||||
private val log by LoggerDelegate()
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val hosts: List<Host> = getKoin().getAll()
|
||||
var completed = false
|
||||
var stopped = false
|
||||
|
||||
private lateinit var context: ImageDownloadContext
|
||||
|
||||
fun download() {
|
||||
try {
|
||||
imageEntity.status = Status.DOWNLOADING
|
||||
imageEntity.downloaded = 0
|
||||
dataTransaction.updateImage(imageEntity)
|
||||
synchronized(imageEntity.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId)
|
||||
if (post.status != Status.DOWNLOADING) {
|
||||
post.status = Status.DOWNLOADING
|
||||
dataTransaction.updatePost(post)
|
||||
}
|
||||
}
|
||||
log.debug("Getting image url and name from ${imageEntity.url} using ${imageEntity.host}")
|
||||
val host = hosts.first { it.isSupported(imageEntity.url) }
|
||||
val downloadedImage = host.downloadInternal(imageEntity.url, context)
|
||||
log.debug("Resolved name for ${imageEntity.url}: ${downloadedImage.name}")
|
||||
log.debug("Downloaded image {} to {}", imageEntity.url, downloadedImage.path)
|
||||
synchronized(imageEntity.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId)
|
||||
val downloadDirectory = Path(post.downloadDirectory, post.folderName).pathString
|
||||
checkImageTypeAndRename(
|
||||
downloadDirectory, downloadedImage, imageEntity.index
|
||||
)
|
||||
if (imageEntity.downloaded == imageEntity.size && imageEntity.size > 0) {
|
||||
imageEntity.status = Status.FINISHED
|
||||
post.done += 1
|
||||
post.downloaded += imageEntity.size
|
||||
dataTransaction.updatePost(post)
|
||||
} else {
|
||||
imageEntity.status = Status.ERROR
|
||||
}
|
||||
dataTransaction.updateImage(imageEntity)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (stopped) {
|
||||
return
|
||||
}
|
||||
imageEntity.status = Status.ERROR
|
||||
dataTransaction.updateImage(imageEntity)
|
||||
throw DownloadException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(HostException::class)
|
||||
private fun checkImageTypeAndRename(
|
||||
downloadDirectory: String, downloadedImage: DownloadedImage, index: Int
|
||||
) {
|
||||
val existingExtension = getExtension(downloadedImage.name).lowercase()
|
||||
val fileNameWithoutExtension = getFileNameWithoutExtension(downloadedImage.name)
|
||||
val extension = when (downloadedImage.type) {
|
||||
ImageMimeType.IMAGE_BMP -> "BMP"
|
||||
ImageMimeType.IMAGE_GIF -> "GIF"
|
||||
ImageMimeType.IMAGE_JPEG -> "JPG"
|
||||
ImageMimeType.IMAGE_PNG -> "PNG"
|
||||
ImageMimeType.IMAGE_WEBP -> "WEBP"
|
||||
}
|
||||
val filename =
|
||||
if (existingExtension.isBlank()) "${sanitize(downloadedImage.name)}.$extension" else "${
|
||||
sanitize(
|
||||
fileNameWithoutExtension
|
||||
)
|
||||
}.$extension"
|
||||
try {
|
||||
val downloadDestinationFolder = Path.of(downloadDirectory)
|
||||
Files.createDirectories(downloadDestinationFolder)
|
||||
val finalFilename = "${
|
||||
if (settings.downloadSettings.forceOrder) String.format(
|
||||
"%03d_", index + 1
|
||||
) else ""
|
||||
}$filename"
|
||||
imageEntity.filename = finalFilename
|
||||
val imageDownloadPath = downloadDestinationFolder.resolve(finalFilename)
|
||||
Files.copy(downloadedImage.path, imageDownloadPath, StandardCopyOption.REPLACE_EXISTING)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Failed to rename the image", e)
|
||||
} finally {
|
||||
try {
|
||||
Files.delete(downloadedImage.path)
|
||||
} catch (_: IOException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
context = ImageDownloadContext(imageEntity, settings)
|
||||
try {
|
||||
if (stopped) {
|
||||
return
|
||||
}
|
||||
download()
|
||||
} finally {
|
||||
completed = true
|
||||
context.cancelCoroutines()
|
||||
}
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
stopped = true
|
||||
context.requests.forEach { it.abort() }
|
||||
context.cancelCoroutines()
|
||||
dataTransaction.updateImage(context.imageEntity)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || javaClass != other.javaClass) return false
|
||||
val that = other as ImageDownloadRunnable
|
||||
return imageEntity.id == that.imageEntity.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(imageEntity.id)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
@@ -46,7 +48,7 @@ internal class AcidimgHost(
|
||||
)
|
||||
)
|
||||
}.also { context.requests.add(it) }
|
||||
log.debug(String.format("Requesting %s", httpPost))
|
||||
log.debug(String.format("Requesting %s", httpPost.uri))
|
||||
val doc = try {
|
||||
httpService.client.execute(
|
||||
httpPost, context.httpContext
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -4,10 +4,10 @@ import kotlinx.coroutines.cancelAndJoin
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
@@ -22,7 +22,6 @@ import org.w3c.dom.Document
|
||||
import java.io.BufferedOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.Throws
|
||||
|
||||
internal abstract class Host(
|
||||
val hostName: String,
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.HtmlProcessorException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package me.vripper.host
|
||||
|
||||
import me.vripper.download.ImageDownloadContext
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.exception.XpathException
|
||||
import me.vripper.services.*
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.DownloadService.ImageDownloadContext
|
||||
import me.vripper.services.DownloadSpeedService
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.w3c.dom.Document
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
package me.vripper.listeners
|
||||
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.MetadataService
|
||||
import me.vripper.services.*
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
open class OnStartupListener : KoinComponent {
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val metadataService: MetadataService by inject()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
private val downloadSpeedService: DownloadSpeedService by inject()
|
||||
private val httpService: HTTPService by inject()
|
||||
private val retryPolicyService: RetryPolicyService by inject()
|
||||
private val threadCacheService: ThreadCacheService by inject()
|
||||
private val downloadService: DownloadService by inject()
|
||||
|
||||
open fun run() {
|
||||
dataTransaction.setDownloadingToStopped()
|
||||
dataTransaction.stopImagesByPostIdAndIsNotCompleted()
|
||||
vgAuthService.init()
|
||||
httpService.init()
|
||||
retryPolicyService.init()
|
||||
threadCacheService.init()
|
||||
settingsService.init()
|
||||
metadataService.init()
|
||||
downloadSpeedService.init()
|
||||
downloadService.init()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ data class ViperSettings(
|
||||
val password: String = "",
|
||||
val thanks: Boolean = false,
|
||||
val host: String = "https://vipergirls.to",
|
||||
val requestLimit: Long = 2,
|
||||
val fetchMetadata: Boolean = false,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -3,7 +3,6 @@ package me.vripper.services
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.time.sample
|
||||
import kotlinx.serialization.json.Json
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.entities.*
|
||||
import me.vripper.event.*
|
||||
import me.vripper.exception.PostParseException
|
||||
@@ -14,7 +13,7 @@ import me.vripper.utilities.ApplicationProperties
|
||||
import me.vripper.utilities.ApplicationProperties.VRIPPER_DIR
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.PathUtils
|
||||
import me.vripper.utilities.executorService
|
||||
import me.vripper.utilities.taskRunner
|
||||
import org.h2.jdbc.JdbcSQLNonTransientConnectionException
|
||||
import java.sql.DriverManager
|
||||
import java.time.Duration
|
||||
@@ -42,10 +41,10 @@ internal class AppEndpointService(
|
||||
if (postLinks.isBlank()) {
|
||||
return
|
||||
}
|
||||
val urlList = postLinks.split(Pattern.compile("\\r?\\n")).dropLastWhile { it.isEmpty() }.map { it.trim() }
|
||||
val urlList = postLinks.split(Pattern.compile("\\r?\\n")).dropLastWhile { it.isBlank() }.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
for (link in urlList) {
|
||||
log.debug("Starting to process thread: $link")
|
||||
log.debug("Scanning: $link")
|
||||
if (!link.startsWith(settingsService.settings.viperSettings.host)) {
|
||||
continue
|
||||
}
|
||||
@@ -58,13 +57,13 @@ internal class AppEndpointService(
|
||||
threadId = m.group(1).toLong()
|
||||
postId = m.group(4)?.toLong()
|
||||
if (postId == null) {
|
||||
executorService.submit(
|
||||
taskRunner.submit(
|
||||
ThreadLookupTask(
|
||||
threadId, settingsService.settings
|
||||
)
|
||||
)
|
||||
} else {
|
||||
executorService.submit(
|
||||
taskRunner.submit(
|
||||
AddPostTask(
|
||||
listOf(ThreadPostId(threadId, postId))
|
||||
)
|
||||
@@ -86,7 +85,7 @@ internal class AppEndpointService(
|
||||
}
|
||||
|
||||
override suspend fun download(posts: List<ThreadPostId>) {
|
||||
executorService.submit(AddPostTask(posts))
|
||||
taskRunner.submit(AddPostTask(posts))
|
||||
}
|
||||
|
||||
override suspend fun stopAll(postIdList: List<Long>) {
|
||||
@@ -119,6 +118,9 @@ internal class AppEndpointService(
|
||||
)
|
||||
}
|
||||
val threadLookupResult = threadCacheService[thread.threadId]
|
||||
if (threadLookupResult.error.isNotBlank()) {
|
||||
throw PostParseException("Error occurred for threadId = $threadId, ${threadLookupResult.error}")
|
||||
}
|
||||
threadLookupResult.postItemList.map { postItem ->
|
||||
PostSelection(
|
||||
postItem.threadId,
|
||||
@@ -132,23 +134,13 @@ internal class AppEndpointService(
|
||||
postItem.forum,
|
||||
postItem.imageItemList.map { it.thumbLink })
|
||||
}.ifEmpty {
|
||||
log.error(
|
||||
String.format(
|
||||
"Failed to get links for threadId = %s", threadId
|
||||
)
|
||||
)
|
||||
throw PostParseException(
|
||||
String.format(
|
||||
"Failed to get links for threadId = %s", threadId
|
||||
)
|
||||
"Nothing found for threadId = $threadId"
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
throw PostParseException(
|
||||
String.format(
|
||||
"Failed to get links for threadId = %s, %s", threadId, e.message
|
||||
)
|
||||
)
|
||||
log.error(e.message)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,7 +174,7 @@ internal class AppEndpointService(
|
||||
}
|
||||
|
||||
override suspend fun rename(postId: Long, newName: String) {
|
||||
executorService.submit {
|
||||
taskRunner.submit {
|
||||
synchronized(postId.toString().intern()) {
|
||||
if (dataTransaction.exists(postId)) {
|
||||
dataTransaction.findPostByPostId(postId).let { post ->
|
||||
|
||||
+176
-16
@@ -1,8 +1,9 @@
|
||||
package me.vripper.download
|
||||
package me.vripper.services
|
||||
|
||||
import dev.failsafe.Failsafe
|
||||
import dev.failsafe.RetryPolicy
|
||||
import kotlinx.coroutines.Runnable
|
||||
import dev.failsafe.function.CheckedRunnable
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.entities.ImageEntity
|
||||
import me.vripper.entities.PostEntity
|
||||
import me.vripper.entities.Status
|
||||
@@ -10,24 +11,39 @@ import me.vripper.event.ErrorCountEvent
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.QueueStateEvent
|
||||
import me.vripper.event.StoppedEvent
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.HostException
|
||||
import me.vripper.host.DownloadedImage
|
||||
import me.vripper.host.Host
|
||||
import me.vripper.host.ImageMimeType
|
||||
import me.vripper.model.ErrorCount
|
||||
import me.vripper.model.QueueState
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.RetryPolicyService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.VGAuthService
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.executorService
|
||||
import me.vripper.utilities.PathUtils.getExtension
|
||||
import me.vripper.utilities.PathUtils.getFileNameWithoutExtension
|
||||
import me.vripper.utilities.PathUtils.sanitize
|
||||
import me.vripper.utilities.downloadRunner
|
||||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
internal class DownloadService(
|
||||
private val settingsService: SettingsService,
|
||||
private val dataTransaction: DataTransaction,
|
||||
private val retryPolicyService: RetryPolicyService,
|
||||
private val vgAuthService: VGAuthService,
|
||||
private val eventBus: EventBus
|
||||
) {
|
||||
private val maxPoolSize: Int = 24
|
||||
@@ -37,7 +53,155 @@ internal class DownloadService(
|
||||
private val lock = ReentrantLock()
|
||||
private val condition = lock.newCondition()
|
||||
|
||||
init {
|
||||
internal class ImageDownloadContext(val imageEntity: ImageEntity, val settings: Settings) : KoinComponent {
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val jobs = mutableListOf<Job>()
|
||||
val httpContext: HttpClientContext =
|
||||
HttpClientContext.create().apply { cookieStore = BasicCookieStore() }
|
||||
val requests = mutableListOf<HttpUriRequestBase>()
|
||||
val postId = imageEntity.postIdRef
|
||||
|
||||
fun cancelCoroutines() {
|
||||
runBlocking {
|
||||
coroutineScope.cancel()
|
||||
jobs.forEach { job -> job.cancelAndJoin() }
|
||||
}
|
||||
}
|
||||
|
||||
fun launchCoroutine(block: suspend CoroutineScope.() -> Unit): Job {
|
||||
return coroutineScope.launch(block = block).also { job -> jobs.add(job) }
|
||||
}
|
||||
}
|
||||
|
||||
internal class ImageDownloadRunnable(
|
||||
val imageEntity: ImageEntity, val postRank: Int, private val settings: Settings
|
||||
) : KoinComponent, CheckedRunnable {
|
||||
private val log by LoggerDelegate()
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
private val vgauthService: VGAuthService by inject()
|
||||
private val hosts: List<Host> = getKoin().getAll()
|
||||
var completed = false
|
||||
var stopped = false
|
||||
|
||||
private lateinit var context: ImageDownloadContext
|
||||
|
||||
fun download() {
|
||||
try {
|
||||
imageEntity.status = Status.DOWNLOADING
|
||||
imageEntity.downloaded = 0
|
||||
dataTransaction.updateImage(imageEntity)
|
||||
synchronized(imageEntity.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId)
|
||||
if (post.status != Status.DOWNLOADING) {
|
||||
post.status = Status.DOWNLOADING
|
||||
dataTransaction.updatePost(post)
|
||||
vgauthService.leaveThanks(post)
|
||||
}
|
||||
}
|
||||
log.debug("Getting image url and name from ${imageEntity.url} using ${imageEntity.host}")
|
||||
val host = hosts.first { it.isSupported(imageEntity.url) }
|
||||
val downloadedImage = host.downloadInternal(imageEntity.url, context)
|
||||
log.debug("Resolved name for ${imageEntity.url}: ${downloadedImage.name}")
|
||||
log.debug("Downloaded image {} to {}", imageEntity.url, downloadedImage.path)
|
||||
synchronized(imageEntity.postId.toString().intern()) {
|
||||
val post = dataTransaction.findPostById(context.postId)
|
||||
val downloadDirectory = Path(post.downloadDirectory, post.folderName).pathString
|
||||
checkImageTypeAndRename(
|
||||
downloadDirectory, downloadedImage, imageEntity.index
|
||||
)
|
||||
if (imageEntity.downloaded == imageEntity.size && imageEntity.size > 0) {
|
||||
imageEntity.status = Status.FINISHED
|
||||
post.done += 1
|
||||
post.downloaded += imageEntity.size
|
||||
dataTransaction.updatePost(post)
|
||||
} else {
|
||||
imageEntity.status = Status.ERROR
|
||||
}
|
||||
dataTransaction.updateImage(imageEntity)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (stopped) {
|
||||
return
|
||||
}
|
||||
imageEntity.status = Status.ERROR
|
||||
dataTransaction.updateImage(imageEntity)
|
||||
throw DownloadException(e)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(HostException::class)
|
||||
private fun checkImageTypeAndRename(
|
||||
downloadDirectory: String, downloadedImage: DownloadedImage, index: Int
|
||||
) {
|
||||
val existingExtension = getExtension(downloadedImage.name).lowercase()
|
||||
val fileNameWithoutExtension = getFileNameWithoutExtension(downloadedImage.name)
|
||||
val extension = when (downloadedImage.type) {
|
||||
ImageMimeType.IMAGE_BMP -> "BMP"
|
||||
ImageMimeType.IMAGE_GIF -> "GIF"
|
||||
ImageMimeType.IMAGE_JPEG -> "JPG"
|
||||
ImageMimeType.IMAGE_PNG -> "PNG"
|
||||
ImageMimeType.IMAGE_WEBP -> "WEBP"
|
||||
}
|
||||
val filename =
|
||||
if (existingExtension.isBlank()) "${sanitize(downloadedImage.name)}.$extension" else "${
|
||||
sanitize(
|
||||
fileNameWithoutExtension
|
||||
)
|
||||
}.$extension"
|
||||
try {
|
||||
val downloadDestinationFolder = Path.of(downloadDirectory)
|
||||
Files.createDirectories(downloadDestinationFolder)
|
||||
val finalFilename = "${
|
||||
if (settings.downloadSettings.forceOrder) String.format(
|
||||
"%03d_", index + 1
|
||||
) else ""
|
||||
}$filename"
|
||||
imageEntity.filename = finalFilename
|
||||
val imageDownloadPath = downloadDestinationFolder.resolve(finalFilename)
|
||||
Files.copy(downloadedImage.path, imageDownloadPath, StandardCopyOption.REPLACE_EXISTING)
|
||||
} catch (e: Exception) {
|
||||
throw HostException("Failed to rename the image", e)
|
||||
} finally {
|
||||
try {
|
||||
Files.delete(downloadedImage.path)
|
||||
} catch (_: IOException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
context = ImageDownloadContext(imageEntity, settings)
|
||||
try {
|
||||
if (stopped) {
|
||||
return
|
||||
}
|
||||
download()
|
||||
} finally {
|
||||
completed = true
|
||||
context.cancelCoroutines()
|
||||
}
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
stopped = true
|
||||
context.requests.forEach { it.abort() }
|
||||
context.cancelCoroutines()
|
||||
dataTransaction.updateImage(context.imageEntity)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || javaClass != other.javaClass) return false
|
||||
val that = other as ImageDownloadRunnable
|
||||
return imageEntity.id == that.imageEntity.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(imageEntity.id)
|
||||
}
|
||||
}
|
||||
|
||||
fun init() {
|
||||
Thread.ofVirtual().name("Download Loop").unstarted(Runnable {
|
||||
val accepted: MutableList<ImageDownloadRunnable> = mutableListOf()
|
||||
val candidates: MutableList<ImageDownloadRunnable> = mutableListOf()
|
||||
@@ -59,7 +223,7 @@ internal class DownloadService(
|
||||
candidates.clear()
|
||||
try {
|
||||
condition.await()
|
||||
} catch (e: InterruptedException) {
|
||||
} catch (_: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
}
|
||||
}
|
||||
@@ -120,10 +284,6 @@ internal class DownloadService(
|
||||
)
|
||||
}
|
||||
|
||||
toProcess.keys.forEach {
|
||||
vgAuthService.leaveThanks(it)
|
||||
}
|
||||
|
||||
|
||||
toProcess.entries.forEach { (post, images) ->
|
||||
images.forEach { image ->
|
||||
@@ -193,7 +353,7 @@ internal class DownloadService(
|
||||
|
||||
private fun candidateCount(): Map<Byte, Int> {
|
||||
val map: MutableMap<Byte, Int> = mutableMapOf()
|
||||
Host.getHosts().values.forEach { host: Byte ->
|
||||
Host.Companion.getHosts().values.forEach { host: Byte ->
|
||||
val imageDownloadRunnableList: List<ImageDownloadRunnable> = running.computeIfAbsent(
|
||||
host
|
||||
) { mutableListOf() }
|
||||
@@ -231,7 +391,7 @@ internal class DownloadService(
|
||||
log.debug("Scheduling a job for ${imageDownloadRunnable.imageEntity.url}")
|
||||
eventBus.publishEvent(QueueStateEvent(QueueState(runningCount(), pendingCount())))
|
||||
Failsafe.with<Any, RetryPolicy<Any>>(retryPolicyService.buildRetryPolicy("Failed to download ${imageDownloadRunnable.imageEntity.url}: "))
|
||||
.with(executorService)
|
||||
.with(downloadRunner)
|
||||
.onFailure {
|
||||
log.error(
|
||||
"Failed to download ${imageDownloadRunnable.imageEntity.url} after ${it.attemptCount} tries",
|
||||
@@ -20,7 +20,7 @@ internal class DownloadSpeedService(
|
||||
private val bytesCount = AtomicLong(0)
|
||||
private var job: Job? = null
|
||||
|
||||
init {
|
||||
fun init() {
|
||||
coroutineScope.launch {
|
||||
eventBus.events.filterIsInstance(QueueStateEvent::class).collect {
|
||||
if (it.queueState.running + it.queueState.remaining > 0) {
|
||||
|
||||
@@ -4,73 +4,65 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import me.vripper.utilities.ApplicationProperties
|
||||
import org.apache.hc.client5.http.config.ConnectionConfig
|
||||
import org.apache.hc.client5.http.config.RequestConfig
|
||||
import org.apache.hc.client5.http.cookie.StandardCookieSpec
|
||||
import org.apache.hc.client5.http.impl.DefaultRedirectStrategy
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager
|
||||
import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder
|
||||
import org.apache.hc.client5.http.io.HttpClientConnectionManager
|
||||
import org.apache.hc.core5.pool.PoolConcurrencyPolicy
|
||||
import org.apache.hc.core5.pool.PoolReusePolicy
|
||||
import org.apache.hc.core5.util.Timeout
|
||||
|
||||
internal class HTTPService(
|
||||
private val eventBus: EventBus,
|
||||
settingsService: SettingsService
|
||||
private val eventBus: EventBus
|
||||
) {
|
||||
|
||||
companion object {
|
||||
const val USER_AGENT =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0"
|
||||
}
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
private lateinit var pcm: PoolingHttpClientConnectionManager
|
||||
private lateinit var rc: RequestConfig
|
||||
private lateinit var cc: ConnectionConfig
|
||||
lateinit var client: CloseableHttpClient
|
||||
private var connectionTimeout = settingsService.settings.connectionSettings.timeout
|
||||
private var pcm: HttpClientConnectionManager = BasicHttpClientConnectionManager()
|
||||
private var rc: RequestConfig = RequestConfig.DEFAULT
|
||||
private var cc: ConnectionConfig = ConnectionConfig.DEFAULT
|
||||
private var connectionTimeout = 30
|
||||
private var connectionExpiryJob: Job? = null
|
||||
var client: CloseableHttpClient = HttpClients.createDefault()
|
||||
|
||||
init {
|
||||
buildRequestConfig()
|
||||
buildConnectionConfig()
|
||||
buildConnectionPool()
|
||||
buildClientBuilder()
|
||||
coroutineScope.launch {
|
||||
while (isActive) {
|
||||
pcm.closeExpired()
|
||||
delay(60_000)
|
||||
}
|
||||
}
|
||||
fun init() {
|
||||
coroutineScope.launch {
|
||||
eventBus
|
||||
.events
|
||||
.filterIsInstance(SettingsUpdateEvent::class)
|
||||
.collect {
|
||||
if (connectionTimeout != it.settings.connectionSettings.timeout) {
|
||||
connectionTimeout = it.settings.connectionSettings.timeout
|
||||
client.close()
|
||||
pcm.close()
|
||||
buildRequestConfig()
|
||||
buildConnectionConfig()
|
||||
buildConnectionPool()
|
||||
buildClientBuilder()
|
||||
}
|
||||
connectionTimeout = it.settings.connectionSettings.timeout
|
||||
client.close()
|
||||
pcm.close()
|
||||
buildRequestConfig()
|
||||
buildConnectionConfig()
|
||||
buildConnectionPool()
|
||||
buildClientBuilder()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildConnectionPool() {
|
||||
connectionExpiryJob?.cancel()
|
||||
pcm = PoolingHttpClientConnectionManagerBuilder.create()
|
||||
.setPoolConcurrencyPolicy(PoolConcurrencyPolicy.LAX)
|
||||
.setConnPoolPolicy(PoolReusePolicy.FIFO)
|
||||
.setDefaultConnectionConfig(cc)
|
||||
.setMaxConnTotal(Int.MAX_VALUE)
|
||||
.setMaxConnPerRoute(Int.MAX_VALUE)
|
||||
.build()
|
||||
.build().also {
|
||||
connectionExpiryJob = coroutineScope.launch {
|
||||
while (isActive) {
|
||||
it.closeExpired()
|
||||
delay(60_000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildRequestConfig() {
|
||||
@@ -91,10 +83,9 @@ internal class HTTPService(
|
||||
client = HttpClients.custom()
|
||||
.setConnectionManager(pcm)
|
||||
.setRedirectStrategy(DefaultRedirectStrategy.INSTANCE)
|
||||
.setUserAgent(USER_AGENT)
|
||||
.setUserAgent(ApplicationProperties.USER_AGENT)
|
||||
.disableAutomaticRetries()
|
||||
.setDefaultRequestConfig(rc)
|
||||
.build()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,111 +1,29 @@
|
||||
package me.vripper.services
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import me.vripper.entities.MetadataEntity
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.VripperException
|
||||
import me.vripper.tasks.Tasks
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.RequestLimit
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils
|
||||
import org.apache.hc.core5.net.URIBuilder
|
||||
import org.w3c.dom.Node
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.stream.Collectors
|
||||
import me.vripper.tasks.FetchMetadataTask
|
||||
import me.vripper.utilities.taskRunner
|
||||
|
||||
internal class MetadataService(
|
||||
private val httpService: HTTPService,
|
||||
private val settingsService: SettingsService,
|
||||
private val dataTransaction: DataTransaction,
|
||||
private val vgAuthService: VGAuthService,
|
||||
private val settingsService: SettingsService,
|
||||
) {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val dictionary: List<String> = mutableListOf("download", "link", "rapidgator", "filefactory", "filefox")
|
||||
|
||||
fun init() {
|
||||
if (!settingsService.settings.viperSettings.fetchMetadata) {
|
||||
return
|
||||
}
|
||||
dataTransaction.findAllPosts().filter { dataTransaction.findMetadataByPostId(it.postId).isEmpty }
|
||||
.map { it.postId }.forEach(::fetchMetadata)
|
||||
}
|
||||
|
||||
fun fetchMetadata(postId: Long) {
|
||||
Tasks.increment()
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
val httpGet = HttpGet(URIBuilder(settingsService.settings.viperSettings.host + "/threads/").also {
|
||||
it.setParameter(
|
||||
"p", postId.toString()
|
||||
)
|
||||
}.build())
|
||||
|
||||
val response = RequestLimit.semaphore.withPermit {
|
||||
httpService.client.execute(httpGet, vgAuthService.context) {
|
||||
if (it.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${it.code}' for $httpGet")
|
||||
}
|
||||
EntityUtils.toString(it.entity)
|
||||
}
|
||||
}
|
||||
val document = HtmlUtils.clean(response)
|
||||
val postNode: Node = XpathUtils.getAsNode(
|
||||
document,
|
||||
"//li[@id='post_$postId']/div[contains(@class, 'postdetails')]",
|
||||
|
||||
) ?: throw VripperException("Unable to find post #'$postId'")
|
||||
|
||||
val postedBy: String = XpathUtils.getAsNode(
|
||||
postNode, "./div[contains(@class, 'userinfo')]//a[contains(@class, 'username')]//font"
|
||||
)?.textContent?.trim()
|
||||
?: throw VripperException("Unable to find the poster for post #'$postId'")
|
||||
|
||||
|
||||
val node: Node = XpathUtils.getAsNode(
|
||||
document, java.lang.String.format("//div[@id='post_message_%s']", postId)
|
||||
) ?: throw VripperException("Unable to locate post content")
|
||||
val titles = findTitleInContent(node)
|
||||
val metadataEntity = MetadataEntity(postId, MetadataEntity.Data(postedBy, titles))
|
||||
dataTransaction.saveMetadata(metadataEntity)
|
||||
} finally {
|
||||
Tasks.decrement()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findTitleInContent(node: Node): List<String> {
|
||||
val altTitle: MutableList<String> = mutableListOf()
|
||||
findTitle(node, altTitle, AtomicBoolean(true))
|
||||
return altTitle.stream().distinct().collect(Collectors.toList())
|
||||
}
|
||||
|
||||
private fun findTitle(node: Node, altTitle: MutableList<String>, keepGoing: AtomicBoolean) {
|
||||
if (!keepGoing.get()) {
|
||||
if (!settingsService.settings.viperSettings.fetchMetadata) {
|
||||
return
|
||||
}
|
||||
if (node.nodeName == "a" || node.nodeName == "img") {
|
||||
keepGoing.set(false)
|
||||
return
|
||||
}
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
for (i in 0 until node.childNodes.length) {
|
||||
val item = node.childNodes.item(i)
|
||||
findTitle(item, altTitle, keepGoing)
|
||||
if (!keepGoing.get()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else if (node.nodeType == Node.TEXT_NODE) {
|
||||
val text = node.textContent.trim()
|
||||
if (text.isNotBlank() && dictionary.stream().noneMatch { e ->
|
||||
text.lowercase().contains(e.lowercase())
|
||||
}) {
|
||||
altTitle.add(text)
|
||||
}
|
||||
}
|
||||
taskRunner.submit(
|
||||
FetchMetadataTask(
|
||||
postId
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ internal class RetryPolicyService(
|
||||
private var maxAttempts: Int = settingsService.settings.connectionSettings.maxAttempts
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
init {
|
||||
fun init() {
|
||||
coroutineScope.launch {
|
||||
eventBus.events.filterIsInstance(SettingsUpdateEvent::class).collect {
|
||||
if (maxAttempts != it.settings.connectionSettings.maxAttempts) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.vripper.services
|
||||
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
@@ -9,7 +10,7 @@ import me.vripper.exception.ValidationException
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.utilities.ApplicationProperties.VRIPPER_DIR
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import me.vripper.utilities.md5Hex
|
||||
import java.io.FileWriter
|
||||
import java.nio.file.*
|
||||
import kotlin.io.path.readText
|
||||
@@ -28,16 +29,13 @@ class SettingsService(private val eventBus: EventBus) {
|
||||
}
|
||||
var settings = Settings()
|
||||
|
||||
init {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
fun init() {
|
||||
loadViperProxies()
|
||||
restore()
|
||||
eventBus.publishEvent(SettingsUpdateEvent(settings))
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
private fun loadViperProxies() {
|
||||
try {
|
||||
SettingsService::class.java.getResourceAsStream("/proxies.json")?.use {
|
||||
@@ -84,7 +82,7 @@ class SettingsService(private val eventBus: EventBus) {
|
||||
check(settings)
|
||||
val viperSettings = if (settings.viperSettings.login) {
|
||||
if (this.settings.viperSettings.password != settings.viperSettings.password) {
|
||||
settings.viperSettings.copy(password = DigestUtils.md5Hex(settings.viperSettings.password))
|
||||
settings.viperSettings.copy(password = md5Hex(settings.viperSettings.password))
|
||||
} else {
|
||||
settings.viperSettings
|
||||
}
|
||||
@@ -137,7 +135,7 @@ class SettingsService(private val eventBus: EventBus) {
|
||||
fun check(settings: Settings) {
|
||||
val path: Path = try {
|
||||
Paths.get(settings.downloadSettings.downloadPath)
|
||||
} catch (e: InvalidPathException) {
|
||||
} catch (_: InvalidPathException) {
|
||||
throw ValidationException(
|
||||
String.format(
|
||||
"%s is invalid", settings.downloadSettings.downloadPath
|
||||
@@ -188,5 +186,11 @@ class SettingsService(private val eventBus: EventBus) {
|
||||
"Invalid clipboard monitoring polling rate settings, values must be >= 500"
|
||||
)
|
||||
}
|
||||
|
||||
if (settings.viperSettings.requestLimit < 1 || settings.viperSettings.requestLimit > 5) {
|
||||
throw ValidationException(
|
||||
"Invalid request rate limit, values must be in [1,5]"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import me.vripper.vgapi.ThreadLookupAPIParser
|
||||
import java.util.concurrent.ExecutionException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
internal class ThreadCacheService(val eventBus: EventBus) {
|
||||
internal class ThreadCacheService(val eventBus: EventBus, val dataTransaction: DataTransaction) {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
@@ -28,7 +28,13 @@ internal class ThreadCacheService(val eventBus: EventBus) {
|
||||
|
||||
private val cache: LoadingCache<Long, ThreadItem> =
|
||||
Caffeine.newBuilder().expireAfterWrite(20, TimeUnit.MINUTES).build { threadId ->
|
||||
ThreadLookupAPIParser(threadId).parse()
|
||||
val threadItem = ThreadLookupAPIParser(threadId).parse()
|
||||
dataTransaction.findThreadByThreadId(threadItem.threadId).ifPresent {
|
||||
if (threadItem.postItemList.isNotEmpty()) {
|
||||
dataTransaction.update(it.copy(total = threadItem.postItemList.size))
|
||||
}
|
||||
}
|
||||
threadItem
|
||||
}
|
||||
|
||||
@Throws(ExecutionException::class)
|
||||
|
||||
@@ -13,43 +13,42 @@ import me.vripper.exception.VripperException
|
||||
import me.vripper.model.Settings
|
||||
import me.vripper.tasks.LeaveThanksTask
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.executorService
|
||||
import me.vripper.utilities.taskRunner
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore
|
||||
import org.apache.hc.client5.http.cookie.Cookie
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity
|
||||
import org.apache.hc.client5.http.impl.cookie.BasicClientCookie
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair
|
||||
|
||||
internal class VGAuthService(
|
||||
private val cm: HTTPService,
|
||||
private val settingsService: SettingsService,
|
||||
private val eventBus: EventBus
|
||||
private val eventBus: EventBus,
|
||||
) {
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val log by LoggerDelegate()
|
||||
val context: HttpClientContext = HttpClientContext.create()
|
||||
private val vgCookies: MutableList<Cookie> = mutableListOf()
|
||||
var loggedUser = ""
|
||||
|
||||
private var authenticated = false
|
||||
|
||||
init {
|
||||
context.cookieStore = BasicCookieStore()
|
||||
fun init() {
|
||||
coroutineScope.launch {
|
||||
eventBus.events.filterIsInstance(SettingsUpdateEvent::class).collect {
|
||||
authenticate(it.settings)
|
||||
}
|
||||
}
|
||||
authenticate(settingsService.settings)
|
||||
}
|
||||
|
||||
private fun authenticate(settings: Settings) {
|
||||
authenticated = false
|
||||
if (!settings.viperSettings.login) {
|
||||
log.debug("Authentication option is disabled")
|
||||
context.cookieStore.clear()
|
||||
authenticated = false
|
||||
loggedUser = ""
|
||||
synchronized(vgCookies) {
|
||||
vgCookies.clear()
|
||||
}
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
return
|
||||
}
|
||||
@@ -57,8 +56,11 @@ internal class VGAuthService(
|
||||
val password = settings.viperSettings.password
|
||||
if (username.isEmpty() || password.isEmpty()) {
|
||||
log.error("Cannot authenticate with ViperGirls credentials, username or password is empty")
|
||||
context.cookieStore.clear()
|
||||
authenticated = false
|
||||
loggedUser = ""
|
||||
synchronized(vgCookies) {
|
||||
vgCookies.clear()
|
||||
}
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
return
|
||||
}
|
||||
@@ -71,13 +73,13 @@ internal class VGAuthService(
|
||||
BasicNameValuePair("vb_login_md5password", password)
|
||||
)
|
||||
)
|
||||
it.addHeader("Referer", settings.viperSettings.host)
|
||||
it.addHeader(
|
||||
"Host", settings.viperSettings.host.replace("https://", "").replace("http://", "")
|
||||
)
|
||||
}
|
||||
|
||||
log.info("Authenticating: ${postAuth.uri}")
|
||||
try {
|
||||
val context = HttpClientContext.create().apply {
|
||||
cookieStore =
|
||||
BasicCookieStore()
|
||||
}
|
||||
cm.client.execute(postAuth, context) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw VripperException("Unexpected response code returned ${response.code}")
|
||||
@@ -85,21 +87,34 @@ internal class VGAuthService(
|
||||
val responseBody = EntityUtils.toString(response.entity)
|
||||
log.debug("Authentication with ViperGirls response body:{}", responseBody)
|
||||
}
|
||||
if (context.cookieStore.cookies.stream().map { obj: Cookie -> obj.name }
|
||||
.noneMatch { e: String -> e == "vg_userid" }) {
|
||||
|
||||
val userIdCookie = context.cookieStore.cookies.find { it.name == "vg_userid" }
|
||||
val passwordCookie = context.cookieStore.cookies.find { it.name == "vg_password" }
|
||||
|
||||
if (userIdCookie == null || passwordCookie == null) {
|
||||
log.error(
|
||||
"Failed to authenticate user with {}, missing vg_userid cookie",
|
||||
"Failed to authenticate user with {}, missing vg_userid/vg_password cookie",
|
||||
settings.viperSettings.host
|
||||
)
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
return
|
||||
}
|
||||
synchronized(vgCookies) {
|
||||
vgCookies.clear()
|
||||
vgCookies.add(BasicClientCookie(userIdCookie.name, userIdCookie.value).apply {
|
||||
domain = userIdCookie.domain
|
||||
})
|
||||
vgCookies.add(BasicClientCookie(passwordCookie.name, passwordCookie.value).apply {
|
||||
domain = passwordCookie.domain
|
||||
})
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.cookieStore.clear()
|
||||
loggedUser = ""
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
log.error(
|
||||
"Failed to authenticate user with " + settings.viperSettings.host, e
|
||||
)
|
||||
authenticated = false
|
||||
loggedUser = ""
|
||||
eventBus.publishEvent(VGUserLoginEvent(loggedUser))
|
||||
return
|
||||
}
|
||||
authenticated = true
|
||||
@@ -108,8 +123,35 @@ internal class VGAuthService(
|
||||
}
|
||||
|
||||
fun leaveThanks(postEntity: PostEntity) {
|
||||
executorService.submit(
|
||||
val context = createVgContext()
|
||||
taskRunner.submit(
|
||||
LeaveThanksTask(postEntity, authenticated, context)
|
||||
)
|
||||
}
|
||||
|
||||
fun createVgContext(): HttpClientContext {
|
||||
val context = HttpClientContext().apply { cookieStore = BasicCookieStore() }
|
||||
synchronized(vgCookies) {
|
||||
if (authenticated && vgCookies.isNotEmpty()) {
|
||||
vgCookies.forEach { c -> context.cookieStore.addCookie(c) }
|
||||
}
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
fun createClickContext(): HttpClientContext {
|
||||
val context = HttpClientContext().apply { cookieStore = BasicCookieStore() }
|
||||
synchronized(vgCookies) {
|
||||
if (authenticated && vgCookies.isNotEmpty()) {
|
||||
vgCookies.forEach { c ->
|
||||
context.cookieStore.addCookie(
|
||||
BasicClientCookie(
|
||||
c.name,
|
||||
c.value
|
||||
).apply { domain = "viper.click" })
|
||||
}
|
||||
}
|
||||
}
|
||||
return context
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
package me.vripper.tasks
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import me.vripper.download.DownloadService
|
||||
import me.vripper.model.ThreadPostId
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.MetadataService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.ThreadCacheService
|
||||
import me.vripper.services.*
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.vgapi.PostItem
|
||||
import me.vripper.vgapi.PostLookupAPIParser
|
||||
@@ -31,14 +26,14 @@ internal class AddPostTask(private val items: List<ThreadPostId>) : KoinComponen
|
||||
}
|
||||
|
||||
val link =
|
||||
"https://${settingsService.settings.viperSettings.host}/threads/$threadId?p=$postId&viewfull=1#post$postId"
|
||||
"${settingsService.settings.viperSettings.host}/threads/$threadId?p=$postId&viewfull=1#post$postId"
|
||||
|
||||
val cachedThread = threadCacheService.getIfPresent(threadId)
|
||||
val threadItem = cachedThread ?: runBlocking {
|
||||
val threadItem = cachedThread ?:
|
||||
PostLookupAPIParser(
|
||||
threadId, postId
|
||||
).parse()
|
||||
}
|
||||
|
||||
|
||||
if (threadItem == null) {
|
||||
log.error("Failed to load $link")
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package me.vripper.tasks
|
||||
|
||||
import me.vripper.entities.MetadataEntity
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.VripperException
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.VGAuthService
|
||||
import me.vripper.utilities.HtmlUtils
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.RequestLimit
|
||||
import me.vripper.utilities.XpathUtils
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils
|
||||
import org.apache.hc.core5.net.URIBuilder
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import org.w3c.dom.Node
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.stream.Collectors
|
||||
|
||||
internal class FetchMetadataTask(
|
||||
private val postId: Long,
|
||||
) : KoinComponent, Runnable {
|
||||
private val dictionary: List<String> = mutableListOf("download", "link", "rapidgator", "filefactory", "filefox")
|
||||
private val log by LoggerDelegate()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
private val httpService: HTTPService by inject()
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
if (!settingsService.settings.viperSettings.fetchMetadata) {
|
||||
log.debug("Fetching metadata is disabled")
|
||||
return
|
||||
}
|
||||
Tasks.increment()
|
||||
val httpGet = HttpGet(URIBuilder(settingsService.settings.viperSettings.host + "/threads/").also {
|
||||
it.setParameter(
|
||||
"p", postId.toString()
|
||||
)
|
||||
}.build())
|
||||
|
||||
RequestLimit.getPermit(1)
|
||||
log.debug("Requesting {}", httpGet.uri)
|
||||
val response = httpService.client.execute(httpGet, vgAuthService.createVgContext()) {
|
||||
if (it.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${it.code}' for $httpGet")
|
||||
}
|
||||
EntityUtils.toString(it.entity)
|
||||
}
|
||||
|
||||
val document = HtmlUtils.clean(response)
|
||||
val postNode: Node = XpathUtils.getAsNode(
|
||||
document,
|
||||
"//li[@id='post_$postId']/div[contains(@class, 'postdetails')]",
|
||||
|
||||
) ?: throw VripperException("Unable to find post #'$postId'")
|
||||
|
||||
val postedBy: String = XpathUtils.getAsNode(
|
||||
postNode, "./div[contains(@class, 'userinfo')]//a[contains(@class, 'username')]//font"
|
||||
)?.textContent?.trim()
|
||||
?: throw VripperException("Unable to find the poster for post #'$postId'")
|
||||
|
||||
|
||||
val node: Node = XpathUtils.getAsNode(
|
||||
document, java.lang.String.format("//div[@id='post_message_%s']", postId)
|
||||
) ?: throw VripperException("Unable to locate post content")
|
||||
val titles = findTitleInContent(node)
|
||||
val metadataEntity = MetadataEntity(postId, MetadataEntity.Data(postedBy, titles))
|
||||
dataTransaction.saveMetadata(metadataEntity)
|
||||
} finally {
|
||||
Tasks.decrement()
|
||||
}
|
||||
}
|
||||
|
||||
private fun findTitleInContent(node: Node): List<String> {
|
||||
val altTitle: MutableList<String> = mutableListOf()
|
||||
findTitle(node, altTitle, AtomicBoolean(true))
|
||||
return altTitle.stream().distinct().collect(Collectors.toList())
|
||||
}
|
||||
|
||||
private fun findTitle(node: Node, altTitle: MutableList<String>, keepGoing: AtomicBoolean) {
|
||||
if (!keepGoing.get()) {
|
||||
return
|
||||
}
|
||||
if (node.nodeName == "a" || node.nodeName == "img") {
|
||||
keepGoing.set(false)
|
||||
return
|
||||
}
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
for (i in 0 until node.childNodes.length) {
|
||||
val item = node.childNodes.item(i)
|
||||
findTitle(item, altTitle, keepGoing)
|
||||
if (!keepGoing.get()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else if (node.nodeType == Node.TEXT_NODE) {
|
||||
val text = node.textContent.trim()
|
||||
if (text.isNotBlank() && dictionary.stream().noneMatch { e ->
|
||||
text.lowercase().contains(e.lowercase())
|
||||
}) {
|
||||
altTitle.add(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package me.vripper.tasks
|
||||
|
||||
import me.vripper.entities.PostEntity
|
||||
import me.vripper.services.DataTransaction
|
||||
import me.vripper.exception.VripperException
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.RequestLimit
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost
|
||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext
|
||||
@@ -20,7 +21,6 @@ internal class LeaveThanksTask(
|
||||
private val log by LoggerDelegate()
|
||||
private val cm: HTTPService by inject()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val dataTransaction: DataTransaction by inject()
|
||||
|
||||
override fun run() {
|
||||
try {
|
||||
@@ -31,25 +31,23 @@ internal class LeaveThanksTask(
|
||||
if (!settingsService.settings.viperSettings.thanks) {
|
||||
return
|
||||
}
|
||||
|
||||
val postThanks =
|
||||
HttpPost("${settingsService.settings.viperSettings.host}/post_thanks.php").also {
|
||||
it.entity = UrlEncodedFormEntity(
|
||||
listOf(
|
||||
BasicNameValuePair("do", "post_thanks_add"),
|
||||
BasicNameValuePair("using_ajax", "1"),
|
||||
BasicNameValuePair("p", postEntity.postId.toString()),
|
||||
BasicNameValuePair("securitytoken", postEntity.token)
|
||||
)
|
||||
)
|
||||
it.addHeader("Referer", settingsService.settings.viperSettings.host)
|
||||
it.addHeader(
|
||||
"Host",
|
||||
settingsService.settings.viperSettings.host.replace("https://", "")
|
||||
.replace("http://", "")
|
||||
val postThanks = HttpPost("${settingsService.settings.viperSettings.host}/post_thanks.php").also {
|
||||
it.entity = UrlEncodedFormEntity(
|
||||
listOf(
|
||||
BasicNameValuePair("do", "post_thanks_add"),
|
||||
BasicNameValuePair("using_ajax", "1"),
|
||||
BasicNameValuePair("p", postEntity.postId.toString()),
|
||||
BasicNameValuePair("securitytoken", postEntity.token)
|
||||
)
|
||||
)
|
||||
}
|
||||
RequestLimit.getPermit(1)
|
||||
log.debug("Requesting {}", postThanks.uri)
|
||||
cm.client.execute(postThanks, context) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw VripperException("Unexpected response code '${response.code}' for $postThanks")
|
||||
}
|
||||
cm.client.execute(postThanks, context) { }
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
log.error("Failed to leave a thanks for $postEntity", e)
|
||||
} finally {
|
||||
|
||||
@@ -7,7 +7,7 @@ import me.vripper.services.DataTransaction
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.ThreadCacheService
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
import me.vripper.utilities.executorService
|
||||
import me.vripper.utilities.taskRunner
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
@@ -33,7 +33,7 @@ internal class ThreadLookupTask(private val threadId: Long, private val settings
|
||||
}
|
||||
|
||||
if (threadLookupResult.postItemList.size <= settings.downloadSettings.autoQueueThreshold) {
|
||||
executorService.submit(
|
||||
taskRunner.submit(
|
||||
AddPostTask(threadLookupResult.postItemList.map {
|
||||
ThreadPostId(
|
||||
it.threadId, it.postId
|
||||
|
||||
@@ -11,7 +11,9 @@ import java.net.http.HttpResponse
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.pathString
|
||||
import kotlin.io.path.readLines
|
||||
|
||||
object ApplicationProperties {
|
||||
val VERSION: String =
|
||||
@@ -24,6 +26,8 @@ object ApplicationProperties {
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
const val DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0"
|
||||
val USER_AGENT: String;
|
||||
|
||||
@Serializable
|
||||
internal data class ReleaseResponse(@SerialName("tag_name") val tagName: String)
|
||||
@@ -31,6 +35,12 @@ object ApplicationProperties {
|
||||
init {
|
||||
Files.createDirectories(VRIPPER_DIR)
|
||||
System.setProperty("VRIPPER_DIR", VRIPPER_DIR.toRealPath().pathString)
|
||||
val userAgentOverride = VRIPPER_DIR.resolve("user-agent")
|
||||
USER_AGENT = if (userAgentOverride.exists()) {
|
||||
userAgentOverride.readLines().firstOrNull() ?: DEFAULT_USER_AGENT
|
||||
} else {
|
||||
DEFAULT_USER_AGENT
|
||||
}
|
||||
}
|
||||
|
||||
fun latestVersion(): String {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
val taskRunner: ExecutorService = Executors.newFixedThreadPool(6)
|
||||
val downloadRunner: ExecutorService = Executors.newVirtualThreadPerTaskExecutor()
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import java.security.MessageDigest
|
||||
import javax.xml.bind.DatatypeConverter
|
||||
|
||||
fun md5Hex(data: String): String {
|
||||
val md: MessageDigest = MessageDigest.getInstance("MD5")
|
||||
md.update(data.toByteArray())
|
||||
return DatatypeConverter.printHexBinary(md.digest()).lowercase()
|
||||
}
|
||||
@@ -1,7 +1,42 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
import io.github.bucket4j.Bucket
|
||||
import io.github.bucket4j.BucketConfiguration
|
||||
import io.github.bucket4j.TokensInheritanceStrategy
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
import kotlinx.coroutines.launch
|
||||
import me.vripper.event.EventBus
|
||||
import me.vripper.event.SettingsUpdateEvent
|
||||
import me.vripper.services.SettingsService
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.time.Duration
|
||||
|
||||
internal object RequestLimit {
|
||||
val semaphore: Semaphore = Semaphore(2)
|
||||
internal object RequestLimit : KoinComponent {
|
||||
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val eventBus: EventBus by inject()
|
||||
private val bucket: Bucket = Bucket.builder().addLimit {
|
||||
it.capacity(settingsService.settings.viperSettings.requestLimit)
|
||||
.refillGreedy(settingsService.settings.viperSettings.requestLimit, Duration.ofSeconds(1))
|
||||
}.build()
|
||||
|
||||
init {
|
||||
coroutineScope.launch {
|
||||
eventBus.events.filterIsInstance(SettingsUpdateEvent::class).collectLatest { event ->
|
||||
bucket.replaceConfiguration(BucketConfiguration.builder().addLimit {
|
||||
it.capacity(event.settings.viperSettings.requestLimit)
|
||||
.refillGreedy(event.settings.viperSettings.requestLimit, Duration.ofSeconds(1))
|
||||
}.build(), TokensInheritanceStrategy.RESET)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getPermit(tokens: Long) {
|
||||
bucket.asBlocking().consume(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package me.vripper.utilities
|
||||
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
val executorService: ExecutorService = Executors.newVirtualThreadPerTaskExecutor()
|
||||
@@ -2,13 +2,10 @@ package me.vripper.vgapi
|
||||
|
||||
import dev.failsafe.Failsafe
|
||||
import dev.failsafe.function.CheckedSupplier
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.PostParseException
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.services.RetryPolicyService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.VGAuthService
|
||||
import me.vripper.tasks.Tasks
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
@@ -20,11 +17,9 @@ import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.ByteArrayInputStream
|
||||
import javax.xml.parsers.SAXParserFactory
|
||||
import kotlin.Throws
|
||||
|
||||
internal class PostLookupAPIParser(private val threadId: Long, private val postId: Long) : KoinComponent {
|
||||
private val log by LoggerDelegate()
|
||||
private val settingsService: SettingsService by inject()
|
||||
private val retryPolicyService: RetryPolicyService by inject()
|
||||
private val httpService: HTTPService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
@@ -33,13 +28,12 @@ internal class PostLookupAPIParser(private val threadId: Long, private val postI
|
||||
fun parse(): ThreadItem? {
|
||||
log.debug("Parsing post $postId")
|
||||
val httpGet =
|
||||
HttpGet(URIBuilder("${settingsService.settings.viperSettings.host}/vr.php").also {
|
||||
HttpGet(URIBuilder("https://viper.click/vr.php").also {
|
||||
it.setParameter(
|
||||
"p", postId.toString()
|
||||
)
|
||||
}.build())
|
||||
val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler()
|
||||
log.debug("Requesting {}", httpGet)
|
||||
Tasks.increment()
|
||||
return try {
|
||||
Failsafe.with(retryPolicyService.buildRetryPolicy<Any>("Failed to parse $httpGet: ")).onFailure {
|
||||
@@ -47,22 +41,22 @@ internal class PostLookupAPIParser(private val threadId: Long, private val postI
|
||||
"Failed to process thread $threadId, post $postId", it.exception
|
||||
)
|
||||
}.get(CheckedSupplier {
|
||||
runBlocking {
|
||||
RequestLimit.semaphore.withPermit {
|
||||
httpService.client.execute(
|
||||
httpGet, vgAuthService.context
|
||||
) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${response.code}' for $httpGet")
|
||||
}
|
||||
ByteArrayInputStream(EntityUtils.toByteArray(response.entity))
|
||||
}
|
||||
}.use {
|
||||
RequestLimit.getPermit(1)
|
||||
log.info("Requesting {}", httpGet.uri)
|
||||
httpService.client.execute(
|
||||
httpGet,
|
||||
vgAuthService.createClickContext()
|
||||
) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${response.code}' for $httpGet")
|
||||
}
|
||||
ByteArrayInputStream(EntityUtils.toByteArray(response.entity)).use {
|
||||
factory.newSAXParser()
|
||||
.parse(it, threadLookupAPIResponseHandler)
|
||||
threadLookupAPIResponseHandler.result
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
} catch (e: Exception) {
|
||||
throw PostParseException(e)
|
||||
|
||||
@@ -2,13 +2,10 @@ package me.vripper.vgapi
|
||||
|
||||
import dev.failsafe.Failsafe
|
||||
import dev.failsafe.function.CheckedSupplier
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.withPermit
|
||||
import me.vripper.exception.DownloadException
|
||||
import me.vripper.exception.PostParseException
|
||||
import me.vripper.services.HTTPService
|
||||
import me.vripper.services.RetryPolicyService
|
||||
import me.vripper.services.SettingsService
|
||||
import me.vripper.services.VGAuthService
|
||||
import me.vripper.tasks.Tasks
|
||||
import me.vripper.utilities.LoggerDelegate
|
||||
@@ -20,27 +17,24 @@ import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.ByteArrayInputStream
|
||||
import javax.xml.parsers.SAXParserFactory
|
||||
import kotlin.Throws
|
||||
|
||||
internal class ThreadLookupAPIParser(private val threadId: Long) : KoinComponent {
|
||||
private val log by LoggerDelegate()
|
||||
private val cm: HTTPService by inject()
|
||||
private val retryPolicyService: RetryPolicyService by inject()
|
||||
private val vgAuthService: VGAuthService by inject()
|
||||
private val settingsService: SettingsService by inject()
|
||||
|
||||
@Throws(PostParseException::class)
|
||||
fun parse(): ThreadItem {
|
||||
log.debug("Parsing thread $threadId")
|
||||
val httpGet =
|
||||
HttpGet(URIBuilder(settingsService.settings.viperSettings.host + "/vr.php").also {
|
||||
HttpGet(URIBuilder("https://viper.click/vr.php").also {
|
||||
it.setParameter(
|
||||
"t",
|
||||
threadId.toString()
|
||||
)
|
||||
}.build())
|
||||
val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler()
|
||||
log.debug("Requesting {}", httpGet)
|
||||
Tasks.increment()
|
||||
return try {
|
||||
Failsafe.with(retryPolicyService.buildRetryPolicy<Any>("Failed to parse $httpGet: ")).onFailure {
|
||||
@@ -49,17 +43,15 @@ internal class ThreadLookupAPIParser(private val threadId: Long) : KoinComponent
|
||||
it.exception
|
||||
)
|
||||
}.get(CheckedSupplier {
|
||||
runBlocking {
|
||||
RequestLimit.semaphore.withPermit {
|
||||
cm.client.execute(
|
||||
httpGet, vgAuthService.context
|
||||
) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${response.code}' for $httpGet")
|
||||
}
|
||||
ByteArrayInputStream(EntityUtils.toByteArray(response.entity))
|
||||
}
|
||||
}.use {
|
||||
RequestLimit.getPermit(1)
|
||||
log.info("Requesting {}", httpGet.uri)
|
||||
cm.client.execute(
|
||||
httpGet, vgAuthService.createClickContext()
|
||||
) { response ->
|
||||
if (response.code / 100 != 2) {
|
||||
throw DownloadException("Unexpected response code '${response.code}' for $httpGet")
|
||||
}
|
||||
ByteArrayInputStream(EntityUtils.toByteArray(response.entity)).use {
|
||||
factory.newSAXParser().parse(
|
||||
it,
|
||||
threadLookupAPIResponseHandler
|
||||
|
||||
@@ -7,6 +7,8 @@ message ViperSettings {
|
||||
string password = 3;
|
||||
bool thanks = 4;
|
||||
string host = 5;
|
||||
int64 requestLimit = 6;
|
||||
bool fetchMetadata = 7;
|
||||
}
|
||||
|
||||
message DownloadSettings {
|
||||
|
||||
@@ -19,18 +19,17 @@
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${VRIPPER_DIR}/vripper.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>7</maxHistory>
|
||||
<totalSizeCap>1GB</totalSizeCap>
|
||||
<maxHistory>5</maxHistory>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<appender name="RING" class="me.vripper.RingAppender">
|
||||
<appender name="RING" class="me.vripper.RingAppender"/>
|
||||
|
||||
</appender>
|
||||
|
||||
<logger name="Exposed" level="OFF"/>
|
||||
<logger name="me.vripper" level="info"/>
|
||||
<logger name="Exposed" level="off"/>
|
||||
<logger name="org.springframework.web.socket.config.WebSocketMessageBrokerStats" level="off"/>
|
||||
<Logger name="org.apache.hc.client5.http" level="off"/>
|
||||
<Logger name="org.apache.hc.client5.http.wire" level="off"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
|
||||
+2
-2
@@ -160,14 +160,14 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
<jvmTarget>21</jvmTarget>
|
||||
<compilerPlugins>
|
||||
<plugin>kotlinx-serialization</plugin>
|
||||
</compilerPlugins>
|
||||
|
||||
@@ -31,7 +31,7 @@ class VripperGuiApplication : App(
|
||||
private val log by LoggerDelegate()
|
||||
private var initialized = false
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
|
||||
init {
|
||||
APP_INSTANCE = this
|
||||
|
||||
@@ -24,31 +24,55 @@ class AboutFragment : Fragment("About") {
|
||||
spacing = 15.0
|
||||
imageview("icons/64x64.png")
|
||||
vbox(spacing = 5.0) {
|
||||
text("VRipper") {
|
||||
text("VRipper ${ApplicationProperties.VERSION}") {
|
||||
style {
|
||||
fontWeight = FontWeight.BOLD
|
||||
fontSize = Dimension(18.0, Dimension.LinearUnits.px)
|
||||
}
|
||||
}
|
||||
text("Version ${ApplicationProperties.VERSION}")
|
||||
text("Developed by dev-claw and VRipper working group")
|
||||
hbox(spacing = 5.0) {
|
||||
hyperlink {
|
||||
imageview("icons/github-mark.png").apply {
|
||||
isPreserveRatio = true
|
||||
fitHeight = 32.0
|
||||
if (widgetsController.currentSettings.darkMode) {
|
||||
imageview("icons/github-mark-white.png").apply {
|
||||
isPreserveRatio = true
|
||||
fitHeight = 32.0
|
||||
}
|
||||
} else {
|
||||
imageview("icons/github-mark.png").apply {
|
||||
isPreserveRatio = true
|
||||
fitHeight = 32.0
|
||||
}
|
||||
}
|
||||
action {
|
||||
openLink("https://github.com/dev-claw/vripper-project")
|
||||
}
|
||||
}
|
||||
hyperlink {
|
||||
imageview("icons/buymeacoffee-logo.png").apply {
|
||||
isPreserveRatio = true
|
||||
fitHeight = 32.0
|
||||
}
|
||||
form {
|
||||
fieldset("Donation") {
|
||||
minWidth = 400.0
|
||||
field {
|
||||
hyperlink {
|
||||
imageview("icons/buymeacoffee-logo.png").apply {
|
||||
isPreserveRatio = true
|
||||
fitHeight = 32.0
|
||||
}
|
||||
action {
|
||||
openLink("https://buymeacoffee.com/devclaw")
|
||||
}
|
||||
}
|
||||
}
|
||||
action {
|
||||
openLink("https://buymeacoffee.com/devclaw")
|
||||
field("ETH:") {
|
||||
textfield("0xDdac82B16dC5E3D742fc915ffF583D8548A301cA") {
|
||||
|
||||
isEditable = false
|
||||
}
|
||||
}
|
||||
field("BTC:") {
|
||||
textfield("bc1qcqudnkrndwyadsjwrxww42svkf8trnzx3c8vlr") {
|
||||
isEditable = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,13 @@ import javafx.geometry.Pos
|
||||
import javafx.scene.control.TextArea
|
||||
import javafx.scene.layout.Priority
|
||||
import javafx.scene.layout.VBox
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.gui.controller.PostController
|
||||
import tornadofx.*
|
||||
|
||||
class AddLinksFragment : Fragment("Add thread links") {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val textAreaProperty = SimpleStringProperty()
|
||||
private val postController: PostController by inject()
|
||||
lateinit var input: TextArea
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import tornadofx.*
|
||||
|
||||
class ConnectionSettingsFragment : Fragment("Connection Settings") {
|
||||
private val settingsController: SettingsController by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private lateinit var connectionSettings: ConnectionSettings
|
||||
val connectionSettingsModel = ConnectionSettingsModel()
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class DownloadSettingsFragment : Fragment("Download Settings") {
|
||||
|
||||
private val settingsController: SettingsController by inject()
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private lateinit var downloadSettings: DownloadSettings
|
||||
val downloadSettingsModel = DownloadSettingsModel()
|
||||
|
||||
|
||||
@@ -6,10 +6,7 @@ import javafx.scene.control.Alert
|
||||
import javafx.scene.control.TabPane
|
||||
import javafx.scene.layout.Priority
|
||||
import javafx.scene.layout.VBox
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.exception.ValidationException
|
||||
import me.vripper.gui.controller.SettingsController
|
||||
import org.kordamp.ikonli.feather.Feather
|
||||
@@ -20,7 +17,7 @@ import tornadofx.*
|
||||
class SettingsFragment : Fragment("Settings") {
|
||||
|
||||
private val settingsController: SettingsController by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val downloadSettingsFragment: DownloadSettingsFragment = find()
|
||||
private val connectionSettingsFragment: ConnectionSettingsFragment = find()
|
||||
private val viperSettingsFragment: ViperSettingsFragment = find()
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import tornadofx.*
|
||||
class SystemSettingsFragment : Fragment("System Settings") {
|
||||
private val settingsController: SettingsController by inject()
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private lateinit var systemSettings: SystemSettings
|
||||
val systemSettingsModel = SystemSettingsModel()
|
||||
|
||||
|
||||
+21
-6
@@ -2,6 +2,7 @@ package me.vripper.gui.components.fragments
|
||||
|
||||
import atlantafx.base.controls.ToggleSwitch
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.scene.control.Spinner
|
||||
import kotlinx.coroutines.*
|
||||
import me.vripper.gui.controller.SettingsController
|
||||
import me.vripper.gui.model.settings.ViperSettingsModel
|
||||
@@ -11,7 +12,7 @@ import tornadofx.*
|
||||
class ViperSettingsFragment : Fragment("Viper Settings") {
|
||||
private val settingsController: SettingsController by inject()
|
||||
private val proxies = FXCollections.observableArrayList<String>()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private lateinit var viperGirlsSettings: ViperSettings
|
||||
val viperSettingsModel = ViperSettingsModel()
|
||||
|
||||
@@ -25,16 +26,30 @@ class ViperSettingsFragment : Fragment("Viper Settings") {
|
||||
viperSettingsModel.password = viperGirlsSettings.password
|
||||
viperSettingsModel.thanks = viperGirlsSettings.thanks
|
||||
viperSettingsModel.host = viperGirlsSettings.host
|
||||
viperSettingsModel.requestLimit = viperGirlsSettings.requestLimit
|
||||
viperSettingsModel.fetchMetadata = viperGirlsSettings.fetchMetadata
|
||||
proxies.addAll(settingsController.getProxies())
|
||||
}.await()
|
||||
runLater {
|
||||
with(root) {
|
||||
form {
|
||||
fieldset {
|
||||
field("Select a proxy") {
|
||||
field("Viper domain") {
|
||||
combobox(viperSettingsModel.hostProperty, proxies)
|
||||
}
|
||||
field("Enable ViperGirls Authentication") {
|
||||
field("Rate limit (requests/s)") {
|
||||
add(Spinner<Int>(1, 5, viperGirlsSettings.requestLimit.toInt()).apply {
|
||||
viperSettingsModel.requestLimitProperty.bind(valueProperty())
|
||||
isEditable = true
|
||||
atlantafx.base.util.IntegerStringConverter.createFor(this)
|
||||
})
|
||||
}
|
||||
field("Fetch Metadata") {
|
||||
checkbox {
|
||||
bind(viperSettingsModel.fetchMetadataProperty)
|
||||
}
|
||||
}
|
||||
field("Authentication") {
|
||||
add(ToggleSwitch().apply {
|
||||
isSelected = viperGirlsSettings.login
|
||||
viperSettingsModel.loginProperty.bind(selectedProperty())
|
||||
@@ -42,13 +57,13 @@ class ViperSettingsFragment : Fragment("Viper Settings") {
|
||||
}
|
||||
fieldset {
|
||||
visibleWhen(viperSettingsModel.loginProperty)
|
||||
field("ViperGirls Username") {
|
||||
field("Username") {
|
||||
textfield(viperSettingsModel.usernameProperty)
|
||||
}
|
||||
field("ViperGirls Password") {
|
||||
field("Password") {
|
||||
passwordfield(viperSettingsModel.passwordProperty)
|
||||
}
|
||||
field("Leave like") {
|
||||
field("Leave likes") {
|
||||
checkbox {
|
||||
bind(viperSettingsModel.thanksProperty)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class ActionBarView : View() {
|
||||
private val downloadActiveProperty = SimpleBooleanProperty(true)
|
||||
private val postController: PostController by inject()
|
||||
private val postsTableView: PostsTableView by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val grpcEndpointService: IAppEndpointService by di("remoteAppEndpointService")
|
||||
private val localEndpointService: IAppEndpointService by di("localAppEndpointService")
|
||||
private val running = SimpleIntegerProperty(0)
|
||||
|
||||
@@ -37,7 +37,7 @@ class ImagesTableView : View("Photos") {
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val localAppEndpointService: IAppEndpointService by di("localAppEndpointService")
|
||||
private val remoteAppEndpointService: IAppEndpointService by di("remoteAppEndpointService")
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val items: ObservableList<ImageModel> = FXCollections.observableArrayList()
|
||||
private var preview: Preview? = null
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class LoadingView : View("VRipper") {
|
||||
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val grpcEndpointService: GrpcEndpointService by di("remoteAppEndpointService")
|
||||
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
override val root = borderpane {}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class LogTableView : View() {
|
||||
private val localAppEndpointService: IAppEndpointService by di("localAppEndpointService")
|
||||
private val remoteAppEndpointService: IAppEndpointService by di("remoteAppEndpointService")
|
||||
private val tableView: TableView<LogModel>
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val items: ObservableList<LogModel> = FXCollections.observableArrayList()
|
||||
private var maxLogEvent = 0
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import tornadofx.*
|
||||
|
||||
class MenuBarView : View() {
|
||||
private val logger by LoggerDelegate()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val downloadActiveProperty = SimpleBooleanProperty(false)
|
||||
private val postsTableView: PostsTableView by inject()
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
|
||||
@@ -18,7 +18,7 @@ import tornadofx.*
|
||||
class PostInfoView : View() {
|
||||
private val logger by LoggerDelegate()
|
||||
private val postController: PostController by inject()
|
||||
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val imagesTableView: ImagesTableView by inject()
|
||||
private val postModel: PostModel = PostModel(
|
||||
-1, "", 0.0, "", "", 0, 0, "", "", -1, "", "", "", emptyList(), emptyList(), "", 0
|
||||
|
||||
@@ -37,7 +37,7 @@ import kotlin.io.path.Path
|
||||
|
||||
class PostsTableView : View() {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val postController: PostController by inject()
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val clipboardService: ClipboardService by inject()
|
||||
|
||||
@@ -18,7 +18,7 @@ import tornadofx.*
|
||||
class StatusBarView : View("Status bar") {
|
||||
private val logger by LoggerDelegate()
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val grpcEndpointService: IAppEndpointService by di("remoteAppEndpointService")
|
||||
private val localEndpointService: IAppEndpointService by di("localAppEndpointService")
|
||||
private val remoteText = SimpleStringProperty()
|
||||
|
||||
@@ -24,7 +24,7 @@ import tornadofx.*
|
||||
|
||||
class ThreadTableView : View() {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val threadController: ThreadController by inject()
|
||||
private val widgetsController: WidgetsController by inject()
|
||||
private val mainView: MainView by inject()
|
||||
|
||||
@@ -59,14 +59,16 @@ class SettingsController : Controller() {
|
||||
viperSettingsModel.password,
|
||||
viperSettingsModel.thanks,
|
||||
viperSettingsModel.host,
|
||||
viperSettingsModel.requestLimit,
|
||||
viperSettingsModel.fetchMetadata,
|
||||
),
|
||||
systemSettings =
|
||||
SystemSettings(
|
||||
systemSettingsModel.tempPath,
|
||||
systemSettingsModel.enable,
|
||||
systemSettingsModel.pollingRate,
|
||||
systemSettingsModel.logEntries
|
||||
)
|
||||
SystemSettings(
|
||||
systemSettingsModel.tempPath,
|
||||
systemSettingsModel.enable,
|
||||
systemSettingsModel.pollingRate,
|
||||
systemSettingsModel.logEntries
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.vripper.gui.model.settings
|
||||
|
||||
import javafx.beans.property.SimpleBooleanProperty
|
||||
import javafx.beans.property.SimpleLongProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
@@ -20,4 +21,10 @@ class ViperSettingsModel {
|
||||
|
||||
val hostProperty = SimpleStringProperty()
|
||||
var host: String by hostProperty
|
||||
|
||||
val requestLimitProperty = SimpleLongProperty()
|
||||
var requestLimit: Long by requestLimitProperty
|
||||
|
||||
val fetchMetadataProperty = SimpleBooleanProperty()
|
||||
var fetchMetadata: Boolean by fetchMetadataProperty
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import tornadofx.runLater
|
||||
class ClipboardService : Controller() {
|
||||
private val logger by LoggerDelegate()
|
||||
private var current: String? = null
|
||||
private var coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private var coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private var pollJob: Job? = null
|
||||
private var subscribeJob: Job? = null
|
||||
|
||||
|
||||
@@ -176,6 +176,8 @@ class GrpcEndpointService : IAppEndpointService {
|
||||
password = settings.viperSettings.password
|
||||
thanks = settings.viperSettings.thanks
|
||||
host = settings.viperSettings.host
|
||||
requestLimit = settings.viperSettings.requestLimit
|
||||
fetchMetadata = settings.viperSettings.fetchMetadata
|
||||
build()
|
||||
}
|
||||
|
||||
@@ -241,6 +243,7 @@ class GrpcEndpointService : IAppEndpointService {
|
||||
password = settings.viperSettings.password,
|
||||
thanks = settings.viperSettings.thanks,
|
||||
host = settings.viperSettings.host,
|
||||
requestLimit = settings.viperSettings.requestLimit,
|
||||
),
|
||||
downloadSettings = DownloadSettings(
|
||||
downloadPath = settings.downloadSettings.downloadPath,
|
||||
|
||||
@@ -25,7 +25,7 @@ class Preview(owner: Stage, private val images: List<String>, private val cacheP
|
||||
|
||||
private var hBox: HBox = HBox().apply { spacing = 5.0; alignment = Pos.BOTTOM_CENTER }
|
||||
private val log by LoggerDelegate()
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob())
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
val previewPopup = Popup()
|
||||
|
||||
private val cache: LoadingCache<String, ByteArray> = Caffeine
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
+1
-1
@@ -106,7 +106,7 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
|
||||
@@ -196,6 +196,8 @@ class GrpcServerAppEndpointService : EndpointServiceGrpcKt.EndpointServiceCorout
|
||||
password = request.viperSettings.password,
|
||||
thanks = request.viperSettings.thanks,
|
||||
host = request.viperSettings.host,
|
||||
requestLimit = request.viperSettings.requestLimit,
|
||||
fetchMetadata = request.viperSettings.fetchMetadata,
|
||||
), systemSettings = SystemSettings(
|
||||
tempPath = request.systemSettings.tempPath,
|
||||
enableClipboardMonitoring = request.systemSettings.enableClipboardMonitoring,
|
||||
@@ -228,6 +230,8 @@ class GrpcServerAppEndpointService : EndpointServiceGrpcKt.EndpointServiceCorout
|
||||
password = settings.viperSettings.password
|
||||
thanks = settings.viperSettings.thanks
|
||||
host = settings.viperSettings.host
|
||||
requestLimit = settings.viperSettings.requestLimit
|
||||
fetchMetadata = settings.viperSettings.fetchMetadata
|
||||
build()
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class DataBroadcast(
|
||||
private val template: SimpMessagingTemplate
|
||||
) : KoinComponent {
|
||||
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
private val appEndpointService: IAppEndpointService by inject(named("localAppEndpointService"))
|
||||
|
||||
@OptIn(FlowPreview::class)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
spring.liquibase.enabled=false
|
||||
grpc.enabled=false
|
||||
grpc.enabled=true
|
||||
grpc.port=30000
|
||||
Reference in New Issue
Block a user