Compare commits

...
26 Commits
Author SHA1 Message Date
death-claw 6ce05e78b3 v3.3.6 2021-03-20 11:28:20 +01:00
death-claw 67a375150c Optimize build size 2021-03-20 11:27:06 +01:00
death-claw fba5f670a0 v3.3.5 2021-03-18 09:31:22 +01:00
death-claw 7d083630cc Bug fix 2021-03-18 09:29:45 +01:00
death-claw 335cbf70b4 v3.3.4 2021-03-18 09:12:48 +01:00
death-claw e25d306f1d Bug fixes 2021-03-18 09:11:01 +01:00
death-claw f395338a9d Update build plugins 2021-03-13 17:08:13 +01:00
death-claw 58a40682cc v3.3.3 2021-03-13 16:21:36 +01:00
death-claw ccc4032bb0 Remove unnecessary event logs 2021-03-13 16:15:56 +01:00
death-claw 1c5b8a0397 v3.3.2 2021-03-11 19:05:09 +01:00
death-claw cc2ce9482d Fix a bug with event logs
Change event names and add some icons
2021-03-11 19:02:01 +01:00
death-claw 41f1775360 v3.3.1 2021-02-18 16:04:34 +01:00
death-claw 733f1a08ac Add about menu
Fix README.md
2021-02-18 16:01:06 +01:00
death-claw 0cb0ee0100 v3.3.0 2021-02-16 19:15:58 +01:00
death-claw cb88e39c83 Add support for proxies
Add a Event Logs
Fix bugs with the database
2021-02-16 19:13:02 +01:00
death-claw 6375c0aed6 v3.2.3 2021-01-13 20:15:13 +01:00
death-claw 40ca4cf86b Finished posts are not cleared from the UI 2021-01-13 20:11:47 +01:00
death-clawandGitHub b3a798388b Update README.md 2021-01-13 12:54:51 +01:00
death-claw 6e69b2bce8 v3.2.2 2021-01-13 09:51:56 +01:00
death-claw bb6dcd77b9 Set total download to max value 2021-01-13 09:49:38 +01:00
death-claw 42e1aa73e2 v3.2.1 2021-01-12 20:02:17 +01:00
death-claw 26fde22af2 Code reformat 2021-01-12 19:37:12 +01:00
death-claw 798f39d54f Add settings for connection timeout
Add settings for maximum attempts
Enhance posts rename logic
Dependencies update
Switch reactive from rx-java to reactor
2021-01-12 19:32:43 +01:00
death-claw 3a21dfac38 Remove unused font 2021-01-06 14:55:49 +01:00
death-claw e8355b88b9 v3.2 2020-11-16 19:40:36 +01:00
death-claw 379660236d Commit missing files 2020-11-16 19:31:59 +01:00
189 changed files with 15920 additions and 18242 deletions
+74
View File
@@ -1,5 +1,79 @@
# Changelog
## [3.3.6] - 2021-03-20
### Changed
- Optimize build size
## [3.3.5] - 2021-03-18
### Changed
- Bug fixe
## [3.3.4] - 2021-03-18
### Changed
- Bug fixes
## [3.3.3] - 2021-03-13
### Changed
- Remove unnecessary event logs
## [3.3.2] - 2021-03-11
### Changed
- Fix a bug with event logs
- Change event names and add some icons
## [3.3.1] - 2021-02-18
### Added
- Add about menu
### Changed
- Fix README.md
## [3.3.0] - 2021-02-16
### Changed
- Add support for proxies
- Add a Event Logs
- Fix bugs with the database
## [3.2.3] - 2021-01-13
### Changed
- Finished posts are not cleared from the UI
## [3.2.2] - 2021-01-13
### Changed
- Set total download to max value
## [3.2.1] - 2021-01-12
### Added
- Add settings for connection timeout
- Add settings for maximum attempts
### Changed
- Enhance posts rename logic
- Dependencies update
- Switch reactive from rx-java to reactor
## [3.2.0] - 2020-11-16
### Changed
- Fix build issue
## [3.1.0] - 2020-11-16
### Changed
- UI revamp
+9 -3
View File
@@ -1,4 +1,4 @@
# Viper Ripper!
# VRipper!
This is my spin for a cross platform gallery ripper app for [vipergirls](https://vipergirls.to) website.
The purpose of this project is to build a robust and clean application to conveniently download photo galleries using modern web technologies, Java + Spring boot for the back end and angular + electron for the front end.
@@ -15,10 +15,16 @@ Most people will be interested only on the desktop app, however if you have a na
To build the server app:
mvn clean install -DskipTests
To build the desktop app:
mvn clean install -Pelectron -DskipTests
Maven will automatically handle front end compilation. However, for development, you will need to install a recent version of nodejs on your system.
Maven will automatically handle front end compilation. However, for development, you will need to install a recent
version of nodejs on your system.
[![Donate with PayPal](https://raw.githubusercontent.com/stefan-niedermann/paypal-donate-button/master/paypal-donate-button.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SC7M5LNWZ528Q)
If you feel generous and want to support me, you can donate some coins, and I would be very grateful 🙏
I accept Bitcoin (BTC) for donations, following is my address
bc1q9jzzw3st49r9vmxgtylq4vrd67cl7zfclf3lsq
+2 -2
View File
@@ -4,12 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.1.0</version>
<version>3.3.6</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
+1
View File
@@ -130,6 +130,7 @@ if (!gotTheLock) {
"-Xms256m",
"-Dvripper.server.port=" + port,
"-Dbase.dir=" + baseDir,
"-Djava.net.preferIPv4Stack=true",
"-jar",
jarPath
], {
-2504
View File
File diff suppressed because it is too large Load Diff
+7 -3
View File
@@ -1,6 +1,6 @@
{
"name": "vripper-electron",
"version": "3.1.0",
"version": "3.3.6",
"description": "A ripper for vipergirls.to built using web technolgies",
"main": "main.js",
"author": "death-claw <53543762+death-claw@users.noreply.github.com>",
@@ -22,6 +22,10 @@
"!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}",
"!**/{appveyor.yml,.travis.yml,circle.yml}",
"!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}",
"!**/build-dir",
"!**/java-runtime",
"!**/pre-build.js",
"!**/pom.xml",
{
"from": "./build/",
"to": "."
@@ -65,11 +69,11 @@
"dist": "node pre-build.js && electron-builder"
},
"devDependencies": {
"electron": "10.1.5",
"electron": "11.1.1",
"electron-builder": "22.9.1"
},
"dependencies": {
"axios": "0.19.2",
"axios": "0.21.1",
"cheerio": "1.0.0-rc.3",
"copy-dir": "1.3.0",
"electron-context-menu": "2.1.0",
+73 -71
View File
@@ -1,77 +1,79 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.1.0</version>
</parent>
<artifactId>vripper-electron</artifactId>
<name>vripper-electron</name>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${buildClassifier}</classifier>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>electron</id>
<properties>
<buildClassifier>electron</buildClassifier>
</properties>
<dependencies>
<dependency>
<groupId>tn.mnlr</groupId>
<artifactId>vripper-server</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<classifier>${buildClassifier}</classifier>
</dependency>
</dependencies>
<build>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.3.6</version>
</parent>
<artifactId>vripper-electron</artifactId>
<name>vripper-electron</name>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<nodeVersion>v12.2.0</nodeVersion>
<npmVersion>6.9.0</npmVersion>
<workingDirectory>build-dir</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<arguments>run dist</arguments>
<classifier>${buildClassifier}</classifier>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</build>
<profiles>
<profile>
<id>electron</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<buildClassifier>electron</buildClassifier>
</properties>
<dependencies>
<dependency>
<groupId>tn.mnlr</groupId>
<artifactId>vripper-server</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<classifier>${buildClassifier}</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.11.2</version>
<configuration>
<nodeVersion>v14.16.0</nodeVersion>
<yarnVersion>v1.22.10</yarnVersion>
<workingDirectory>build-dir</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
</execution>
<execution>
<id>yarn run build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run dist</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
+3 -3
View File
@@ -2,7 +2,7 @@ const cheerio = require('cheerio');
const fs = require('fs');
const rimraf = require("rimraf");
const copydir = require("copy-dir");
const { execSync } = require("child_process");
const {execSync} = require("child_process");
rimraf.sync('./build/vripper-ui');
copydir.sync('../vripper-ui/dist/vripper-ui', './build/vripper-ui', {});
@@ -19,7 +19,7 @@ fs.writeFileSync('./build/vripper-ui/index.html', $.html());
console.log('Building runtime environment');
rimraf.sync('java-runtime');
execSync('jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules java.base,java.desktop,java.instrument,java.management,java.naming,java.prefs,java.rmi,java.scripting,java.security.jgss,java.sql,jdk.httpserver,jdk.unsupported,jdk.crypto.ec --output java-runtime');
if(process.platform === 'linux') {
if (process.platform === 'linux') {
console.log('Stripping libjvm.so');
execSync('strip -p --strip-unneeded java-runtime/lib/server/libjvm.so');
}
}
+132
View File
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<webroots />
</configuration>
</facet>
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="vripper-server" scope="RUNTIME" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-jersey:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-json:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.41" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish:jakarta.el:3.0.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.41" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-validation:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.hibernate.validator:hibernate-validator:6.1.6.Final" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.jboss.logging:jboss-logging:3.4.1.Final" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-web:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-beans:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-core:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-jcl:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.core:jersey-server:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.core:jersey-common:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.core:jersey-client:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: jakarta.ws.rs:jakarta.ws.rs-api:2.1.6" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2.external:jakarta.inject:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: jakarta.validation:jakarta.validation-api:2.0.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: jakarta.xml.bind:jakarta.xml.bind-api:2.3.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: jakarta.activation:jakarta.activation-api:1.2.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet-core:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.containers:jersey-container-servlet:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.ext:jersey-bean-validation:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.ext:jersey-spring5:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-locator:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.javassist:javassist:3.25.0-GA" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-utils:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-api:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-core:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-runlevel:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:class-model:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.ow2.asm:asm:7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.ow2.asm:asm-analysis:7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.ow2.asm:asm-commons:7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.ow2.asm:asm-tree:7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.ow2.asm:asm-util:7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:spring-bridge:2.6.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-context:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-aop:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.media:jersey-media-json-jackson:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.ext:jersey-entity-filtering:2.32" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.11.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-web:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.13.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.logging.log4j:log4j-api:2.13.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:jul-to-slf4j:1.7.30" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.27" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-webmvc:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-expression:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-websocket:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-messaging:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-websocket:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-actuator:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-actuator:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.micrometer:micrometer-core:1.6.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.hdrhistogram:HdrHistogram:2.1.12" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-data-jdbc:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-jdbc:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.data:spring-data-jdbc:2.1.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.data:spring-data-relational:2.1.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework.data:spring-data-commons:2.4.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.springframework:spring-tx:5.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.liquibase:liquibase-core:3.10.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.hsqldb:hsqldb:2.5.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.httpcomponents:httpclient:4.5.13" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.apache.httpcomponents:httpcore:4.4.14" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: commons-codec:commons-codec:1.15" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: net.sourceforge.htmlcleaner:htmlcleaner:2.22" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.jdom:jdom2:2.0.6" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.projectreactor:reactor-core:3.4.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.reactivestreams:reactive-streams:1.0.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: net.jodah:failsafe:2.0.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.guava:guava:28.1-jre" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.checkerframework:checker-qual:2.8.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.errorprone:error_prone_annotations:2.3.2" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.18" level="project" />
<orderEntry type="module" module-name="vripper-ui" scope="RUNTIME" />
</component>
</module>
File diff suppressed because it is too large Load Diff
+9 -52
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.1.0</version>
<version>3.3.6</version>
</parent>
<artifactId>vripper-server</artifactId>
<name>vripper-server</name>
@@ -72,9 +72,8 @@
<version>2.22</version>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.6</version>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>net.jodah</groupId>
@@ -101,6 +100,12 @@
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${buildClassifier}</classifier>
<archive>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Built-By>${user.name}</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
@@ -118,54 +123,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.parent.basedir}/.git</dotGitDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Built-By>${user.name}</Built-By>
</manifestEntries>
<manifestSections>
<manifestSection>
<name>Versions</name>
<manifestEntries>
<Implementation-Version>${git.build.version}</Implementation-Version>
<Implementation-SCM-Revision>${git.commit.id}</Implementation-SCM-Revision>
<Implementation-SCM-Branch>${git.branch}</Implementation-SCM-Branch>
<Implementation-SCM-Time>${git.build.time}</Implementation-SCM-Time>
<Implementation-SCM-Dirty>${git.dirty}</Implementation-SCM-Dirty>
<Implementation-SCM-Tags>${git.tags}</Implementation-SCM-Tags>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
</plugins>
</build>
@@ -27,10 +27,7 @@ public class EventListenerBean {
@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
repositorySet.forEach(IRepository::init);
dataService.setDownloadingToStopped();
init = true;
}
}
}
@@ -0,0 +1,23 @@
package tn.mnlr.vripper;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@Slf4j
public class Utils {
public static String throwableToString(Throwable th) {
try (StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter)) {
th.printStackTrace(printWriter);
printWriter.flush();
stringWriter.flush();
return stringWriter.toString();
} catch (IOException e) {
log.error("Failed to convert throwable to string", e);
}
return "Cannot display error, please check the log file for details";
}
}
@@ -1,21 +1,13 @@
package tn.mnlr.vripper;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.RetryPolicy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.time.temporal.ChronoUnit;
@SpringBootApplication
@Slf4j
public class VripperApplication {
public static final RetryPolicy<Object> retryPolicy = new RetryPolicy<>()
.withDelay(1, 3, ChronoUnit.SECONDS)
.withMaxAttempts(5)
.onFailedAttempt(e -> log.warn(String.format("#%d tries failed", e.getAttemptCount()), e.getLastFailure()));
public static void main(String[] args) {
try {
Runtime.getRuntime().addShutdownHook(new Thread(SpringContext::close));
@@ -23,50 +23,29 @@ import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j
public class DownloadJob implements CheckedRunnable {
public enum ContextAttributes {
OPEN_CONNECTION("OPEN_CONNECTION");
private final String value;
ContextAttributes(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
private static final ReentrantLock LOCK = new ReentrantLock();
private static final Object LOCK = new Object();
private static final int READ_BUFFER_SIZE = 8192;
private final DataService dataService;
private final PathService pathService;
private final ConnectionService cm;
private final VGAuthService authService;
private final DownloadSpeedService downloadSpeedService;
private final SettingsService settingsService;
private final HttpClientContext context;
@Getter
private final Image image;
@Getter
private final Post post;
private boolean stopped = false;
private volatile boolean stopped = false;
@Getter
private boolean finished = false;
@@ -93,16 +72,21 @@ public class DownloadJob implements CheckedRunnable {
dataService.updateImageStatus(image.getStatus(), image.getId());
dataService.updateImageCurrent(image.getCurrent(), image.getId());
try {
LOCK.lock();
synchronized (LOCK) {
if (!post.getStatus().equals(Status.DOWNLOADING) && !post.getStatus().equals(Status.PARTIAL)) {
post.setStatus(Status.DOWNLOADING);
dataService.updatePostStatus(post.getStatus(), post.getId());
}
} finally {
LOCK.unlock();
}
// The post may be updated and the download directory might be set by another thread
Post updatedPost = dataService.findById(post.getId()).orElseThrow();
if (updatedPost.getDownloadDirectory() == null) {
pathService.createDefaultPostFolder(updatedPost);
}
if (settingsService.getSettings().getLeaveThanksOnStart() != null && settingsService.getSettings().getLeaveThanksOnStart()) {
authService.leaveThanks(updatedPost);
}
}
if (stopped) {
return;
@@ -139,22 +123,7 @@ public class DownloadJob implements CheckedRunnable {
if (stopped) {
return;
}
File destinationFolder, outputFile;
try {
LOCK.lock();
Post updatedPost = dataService.findPostById(post.getId()).orElseThrow();
if (updatedPost.getPostFolderName() == null) {
pathService.createDefaultPostFolder(updatedPost);
}
destinationFolder = pathService.getDownloadDestinationFolder(updatedPost);
if (settingsService.getSettings().getLeaveThanksOnStart()) {
authService.leaveThanks(updatedPost);
}
outputFile = new File(destinationFolder.getPath() + File.separator + String.format("%03d_", image.getIndex()) + nameAndUrl.getName() + ".tmp");
outputFile.getParentFile().mkdirs();
} finally {
LOCK.unlock();
}
File outputFile = Files.createTempFile("vripper", "tmp").toFile();
try (InputStream downloadStream = response.getEntity().getContent(); FileOutputStream fos = new FileOutputStream(outputFile)) {
if (stopped) {
@@ -181,7 +150,7 @@ public class DownloadJob implements CheckedRunnable {
return;
}
}
checkImageTypeAndRename(dataService.findPostById(post.getId()).orElseThrow(), outputFile, nameAndUrl.getName(), image.getIndex());
checkImageTypeAndRename(dataService.findById(post.getId()).orElseThrow(), outputFile, nameAndUrl.getName(), image.getIndex());
}
} catch (Exception e) {
if (stopped) {
@@ -208,7 +177,7 @@ public class DownloadJob implements CheckedRunnable {
throw new HostException("Image file is not recognized!");
}
ImageReader reader = it.next();
if (reader.getFormatName().toUpperCase().equals("JPEG")) {
if (reader.getFormatName().equalsIgnoreCase("JPEG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_jpg") && !imageNameLC.endsWith("_jpeg")) {
imageName += ".jpg";
@@ -223,7 +192,7 @@ public class DownloadJob implements CheckedRunnable {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".jpg";
}
}
} else if (reader.getFormatName().toUpperCase().equals("PNG")) {
} else if (reader.getFormatName().equalsIgnoreCase("PNG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_png")) {
imageName += ".png";
@@ -241,14 +210,19 @@ public class DownloadJob implements CheckedRunnable {
throw new HostException("Failed to guess image format", e);
}
try {
File downloadDestinationFolder = pathService.getDownloadDestinationFolder(post);
pathService.getDirectoryAccess().lock();
File downloadDestinationFolder = pathService.calcDownloadDirectory(post);
File outImage = new File(downloadDestinationFolder, (settingsService.getSettings().getForceOrder() ? String.format("%03d_", index) : "") + imageName);
if (outImage.exists() && outImage.delete()) {
log.debug(String.format("%s is deleted", outImage.toString()));
}
Files.move(outputFile.toPath(), outImage.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
Files.copy(outputFile.toPath(), outImage.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new HostException("Failed to rename the image", e);
} finally {
pathService.getDirectoryAccess().unlock();
try {
Files.delete(outputFile.toPath());
} catch (IOException e) {
log.warn(String.format("Failed to delete temporary file %s", outputFile.getAbsolutePath()));
}
}
}
@@ -285,4 +259,19 @@ public class DownloadJob implements CheckedRunnable {
}
this.stopped = true;
}
public enum ContextAttributes {
OPEN_CONNECTION("OPEN_CONNECTION");
private final String value;
ContextAttributes(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
}
@@ -3,28 +3,44 @@ package tn.mnlr.vripper.download;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.Utils;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
import tn.mnlr.vripper.services.ConnectionService;
import tn.mnlr.vripper.services.DataService;
import java.time.LocalDateTime;
@Slf4j
public class DownloadRunnable implements Runnable {
private final DownloadService downloadService;
private final DataService dataService;
private final ConnectionService connectionService;
private final IEventRepository eventRepository;
private final DownloadJob downloadJob;
public DownloadRunnable(final DownloadJob downloadJob) {
downloadService = SpringContext.getBean(DownloadService.class);
dataService = SpringContext.getBean(DataService.class);
connectionService = SpringContext.getBean(ConnectionService.class);
eventRepository = SpringContext.getBean(IEventRepository.class);
this.downloadJob = downloadJob;
}
@Override
public void run() {
Failsafe.with(VripperApplication.retryPolicy)
Failsafe.with(connectionService.getRetryPolicy())
.onFailure(e -> {
try {
Event event = new Event(Event.Type.DOWNLOAD, Event.Status.ERROR, LocalDateTime.now(), String.format("Failed to download %s\n %s", downloadJob.getImage().getUrl(), Utils.throwableToString(e.getFailure())));
eventRepository.save(event);
} catch (Exception exp) {
log.error("Failed to save event", exp);
}
log.error(String.format("Failed to download %s after %d tries", downloadJob.getImage().getUrl(), e.getAttemptCount()), e.getFailure());
downloadJob.getImage().setStatus(Status.ERROR);
dataService.updateImageStatus(downloadJob.getImage().getStatus(), downloadJob.getImage().getId());
@@ -8,12 +8,11 @@ import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.services.SettingsService;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.PostService;
import tn.mnlr.vripper.services.SettingsService;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -6,8 +6,8 @@ import org.springframework.stereotype.Service;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.services.SettingsService;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.SettingsService;
import javax.annotation.PostConstruct;
import java.util.*;
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class EventRemoveEvent extends ApplicationEvent {
private final Long id;
public EventRemoveEvent(Object source, Long id) {
super(source);
this.id = id;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class EventUpdateEvent extends ApplicationEvent {
private final Long id;
public EventUpdateEvent(Object source, Long id) {
super(source);
this.id = id;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class ImageUpdateEvent extends ApplicationEvent {
private final Long id;
public ImageUpdateEvent(Object source, Long id) {
super(source);
this.id = id;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class MetadataUpdateEvent extends ApplicationEvent {
private final Long postIdRef;
public MetadataUpdateEvent(Object source, Long postIdRef) {
super(source);
this.postIdRef = postIdRef;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class PostRemoveEvent extends ApplicationEvent {
private final String postId;
public PostRemoveEvent(Object source, String postId) {
super(source);
this.postId = postId;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class PostUpdateEvent extends ApplicationEvent {
private final Long id;
public PostUpdateEvent(Object source, Long id) {
super(source);
this.id = id;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class QueuedRemoveEvent extends ApplicationEvent {
private final String threadId;
public QueuedRemoveEvent(Object source, String threadId) {
super(source);
this.threadId = threadId;
}
}
@@ -0,0 +1,15 @@
package tn.mnlr.vripper.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class QueuedUpdateEvent extends ApplicationEvent {
private final Long id;
public QueuedUpdateEvent(Object source, Long id) {
super(source);
this.id = id;
}
}
@@ -10,6 +10,6 @@ public class HostException extends Exception {
}
public HostException(String message, Throwable e) {
super(message,e);
super(message, e);
}
}
@@ -0,0 +1,10 @@
package tn.mnlr.vripper.exception;
import java.io.IOException;
public class RenameException extends Exception {
public RenameException(String message, IOException e) {
super(message, e);
}
}
@@ -68,6 +68,9 @@ public class ImxHost extends Host {
try {
log.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
contDiv = xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH);
if (contDiv == null) {
throw new HostException(CONTINUE_BUTTON_XPATH + " cannot be found");
}
Node node = contDiv.getAttributes().getNamedItem("value");
if (node != null) {
value = node.getTextContent();
@@ -0,0 +1,66 @@
package tn.mnlr.vripper.jpa.domain;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Getter
@Setter
@ToString
@NoArgsConstructor
public class Event {
private Long id;
private Type type;
private Status status;
@JsonSerialize(using = DateTimeSerializer.class)
private LocalDateTime time;
private String message;
public Event(Type type, Status status, LocalDateTime time, String message) {
this.type = type;
this.status = status;
this.time = time;
this.message = message;
}
public enum Type {
POST,
QUEUED,
THANKS,
METADATA,
SCAN,
DOWNLOAD,
// Below are deprecated events
METADATA_CACHE_MISS,
QUEUED_CACHE_MISS
}
public enum Status {
PENDING, PROCESSING, DONE, ERROR
}
}
class DateTimeSerializer extends StdSerializer<LocalDateTime> {
private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.SSS");
protected DateTimeSerializer() {
super(LocalDateTime.class);
}
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString(value.format(DATE_TIME_FORMATTER));
}
}
@@ -1,6 +1,5 @@
package tn.mnlr.vripper.jpa.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -13,12 +12,20 @@ import java.util.List;
@NoArgsConstructor
public class Metadata {
@JsonIgnore
private Long id;
private Long postIdRef;
private List<String> resolvedNames = Collections.emptyList();
private String postId;
private String postedBy;
private Long postIdRef;
private List<String> resolvedNames = Collections.emptyList();
public static Metadata from(Metadata metadata) {
Metadata copy = new Metadata();
copy.postIdRef = metadata.postIdRef;
copy.postId = metadata.postId;
copy.postedBy = metadata.postedBy;
copy.resolvedNames = List.copyOf(metadata.resolvedNames);
return copy;
}
}
@@ -44,7 +44,7 @@ public class Post {
private String securityToken;
@JsonIgnore
private String postFolderName;
private String downloadDirectory;
private boolean thanked;
@@ -0,0 +1,21 @@
package tn.mnlr.vripper.jpa.repositories;
import tn.mnlr.vripper.jpa.domain.Event;
import java.util.List;
import java.util.Optional;
public interface IEventRepository extends IRepository {
Event save(Event event);
Event update(Event event);
List<Event> findAll();
Optional<Event> findById(Long id);
void delete(Long id);
void deleteAll();
}
@@ -8,8 +8,6 @@ public interface IMetadataRepository extends IRepository {
Metadata save(Metadata metadata);
Optional<Metadata> findById(Long id);
Optional<Metadata> findByPostId(String postId);
int deleteByPostId(String postId);
@@ -10,14 +10,12 @@ public interface IPostRepository extends IRepository {
Post save(Post post);
int delete(Long id);
Optional<Post> findByPostId(String postId);
List<String> findCompleted();
Optional<Post> findById(Long id);
List<String> findCompleted();
List<Post> findAll();
boolean existByPostId(String postId);
@@ -15,4 +15,6 @@ public interface IQueuedRepository extends IRepository {
Optional<Queued> findById(Long id);
int deleteByThreadId(String threadId);
void deleteAll();
}
@@ -1,6 +1,4 @@
package tn.mnlr.vripper.jpa.repositories;
public interface IRepository {
public void init();
}
@@ -0,0 +1,117 @@
package tn.mnlr.vripper.jpa.repositories.impl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.event.EventRemoveEvent;
import tn.mnlr.vripper.event.EventUpdateEvent;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
import tn.mnlr.vripper.services.SettingsService;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
public class EventRepository implements IEventRepository, ApplicationEventPublisherAware {
private final JdbcTemplate jdbcTemplate;
private final SettingsService settingsService;
private ApplicationEventPublisher applicationEventPublisher;
public EventRepository(JdbcTemplate jdbcTemplate, SettingsService settingsService) {
this.jdbcTemplate = jdbcTemplate;
this.settingsService = settingsService;
}
private synchronized Long nextId() {
return jdbcTemplate.queryForObject(
"CALL NEXT VALUE FOR SEQ_EVENT",
Long.class);
}
@Override
public synchronized Event save(@NonNull Event event) {
int maxRecords = settingsService.getSettings().getMaxEventLog() - 1;
Long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EVENT", Long.class);
if (count > maxRecords) {
List<Long> idList = jdbcTemplate.queryForList("SELECT ID FROM EVENT ORDER BY TIME ASC LIMIT ?", Long.class, count - maxRecords);
idList.forEach(this::delete);
}
long id = nextId();
jdbcTemplate.update(
"INSERT INTO EVENT (ID, TYPE, STATUS, TIME, MESSAGE) VALUES (?,?,?,?,?)",
id,
event.getType().name(),
event.getStatus().name(),
event.getTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
event.getMessage()
);
event.setId(id);
applicationEventPublisher.publishEvent(new EventUpdateEvent(EventRepository.class, id));
return event;
}
@Override
public Event update(@NonNull Event event) {
if (event.getId() == null) {
log.warn("Cannot update entity with null id");
return event;
}
jdbcTemplate.update(
"UPDATE EVENT SET TYPE = ?, STATUS = ?, TIME = ?, MESSAGE = ? WHERE ID = ?",
event.getType().name(),
event.getStatus().name(),
event.getTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
event.getMessage(),
event.getId()
);
applicationEventPublisher.publishEvent(new EventUpdateEvent(EventRepository.class, event.getId()));
return event;
}
@Override
public Optional<Event> findById(Long id) {
List<Event> events = jdbcTemplate.query(
"SELECT * FROM EVENT WHERE ID = ?",
new EventRowMapper(),
id);
if (events.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(events.get(0));
}
}
@Override
public List<Event> findAll() {
return jdbcTemplate.query(
"SELECT * FROM EVENT",
new EventRowMapper());
}
@Override
public void delete(Long id) {
jdbcTemplate.update("DELETE FROM EVENT WHERE ID = ?", id);
applicationEventPublisher.publishEvent(new EventRemoveEvent(EventRepository.class, id));
}
@Override
public void deleteAll() {
jdbcTemplate.update("DELETE FROM EVENT");
}
@Override
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}
@@ -0,0 +1,23 @@
package tn.mnlr.vripper.jpa.repositories.impl;
import org.springframework.jdbc.core.RowMapper;
import tn.mnlr.vripper.jpa.domain.Event;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class EventRowMapper implements RowMapper<Event> {
@Override
public Event mapRow(ResultSet rs, int rowNum) throws SQLException {
Event event = new Event();
event.setId(rs.getLong("ID"));
event.setType(Event.Type.valueOf(rs.getString("TYPE")));
event.setStatus(Event.Status.valueOf(rs.getString("STATUS")));
event.setTime(LocalDateTime.parse(rs.getString("TIME"), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
event.setMessage(rs.getString("MESSAGE"));
return event;
}
}
@@ -1,42 +1,39 @@
package tn.mnlr.vripper.jpa.repositories.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.event.ImageUpdateEvent;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.jpa.repositories.IImageRepository;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@Service
public class ImageRepository implements IImageRepository {
public class ImageRepository implements IImageRepository, ApplicationEventPublisherAware {
private final JdbcTemplate jdbcTemplate;
private final AtomicLong counter = new AtomicLong(0);
private ApplicationEventPublisher applicationEventPublisher;
@Autowired
public ImageRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void init() {
Long maxId = jdbcTemplate.queryForObject(
"SELECT MAX(ID) FROM IMAGE",
Long.class
);
if (maxId == null) {
maxId = 0L;
}
counter.set(maxId);
private synchronized Long nextId() {
return jdbcTemplate.queryForObject(
"CALL NEXT VALUE FOR SEQ_IMAGE",
Long.class);
}
@Override
public Image save(Image image) {
long id = counter.incrementAndGet();
long id = nextId();
jdbcTemplate.update(
"INSERT INTO IMAGE (ID, CURRENT, HOST, INDEX, POST_ID, STATUS, TOTAL, URL, POST_ID_REF) VALUES (?,?,?,?,?,?,?,?,?)",
id,
@@ -50,6 +47,7 @@ public class ImageRepository implements IImageRepository {
image.getPostIdRef()
);
image.setId(id);
applicationEventPublisher.publishEvent(new ImageUpdateEvent(ImageRepository.class, id));
return image;
}
@@ -62,9 +60,8 @@ public class ImageRepository implements IImageRepository {
public List<Image> findByPostId(String postId) {
return jdbcTemplate.query(
"SELECT * FROM IMAGE WHERE POST_ID = ?",
new Object[]{postId},
new ImageRowMapper()
);
new ImageRowMapper(),
postId);
}
@Override
@@ -79,9 +76,8 @@ public class ImageRepository implements IImageRepository {
public List<Image> findByPostIdAndIsNotCompleted(String postId) {
return jdbcTemplate.query(
"SELECT * FROM IMAGE AS image WHERE image.POST_ID = ? AND image.STATUS <> 'COMPLETE'",
new Object[]{postId},
new ImageRowMapper()
);
new ImageRowMapper(),
postId);
}
@Override
@@ -96,18 +92,16 @@ public class ImageRepository implements IImageRepository {
public List<Image> findByPostIdAndIsError(String postId) {
return jdbcTemplate.query(
"SELECT * FROM IMAGE AS image WHERE image.POST_ID = ? AND image.STATUS = 'ERROR'",
new Object[]{postId},
new ImageRowMapper()
);
new ImageRowMapper(),
postId);
}
@Override
public Optional<Image> findById(Long id) {
List<Image> images = jdbcTemplate.query(
"SELECT * FROM IMAGE AS image WHERE image.ID = ?",
new Object[]{id},
new ImageRowMapper()
);
new ImageRowMapper(),
id);
if (images.isEmpty()) {
return Optional.empty();
} else {
@@ -117,25 +111,36 @@ public class ImageRepository implements IImageRepository {
@Override
public int updateStatus(Status status, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE IMAGE AS image SET image.STATUS = ? WHERE image.ID = ?",
status.name(), id
);
applicationEventPublisher.publishEvent(new ImageUpdateEvent(ImageRepository.class, id));
return mutationCount;
}
@Override
public int updateCurrent(long current, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE IMAGE AS image SET image.CURRENT = ? WHERE image.ID = ?",
current, id
);
applicationEventPublisher.publishEvent(new ImageUpdateEvent(ImageRepository.class, id));
return mutationCount;
}
@Override
public int updateTotal(long total, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE IMAGE AS image SET image.TOTAL = ? WHERE image.ID = ?",
total, id
);
applicationEventPublisher.publishEvent(new ImageUpdateEvent(ImageRepository.class, id));
return mutationCount;
}
@Override
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}
@@ -1,72 +1,47 @@
package tn.mnlr.vripper.jpa.repositories.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.event.MetadataUpdateEvent;
import tn.mnlr.vripper.jpa.domain.Metadata;
import tn.mnlr.vripper.jpa.repositories.IMetadataRepository;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@Service
public class MetadataRepository implements IMetadataRepository {
public class MetadataRepository implements IMetadataRepository, ApplicationEventPublisherAware {
private final JdbcTemplate jdbcTemplate;
private final AtomicLong counter = new AtomicLong(0);
private ApplicationEventPublisher applicationEventPublisher;
@Autowired
public MetadataRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void init() {
Long maxId = jdbcTemplate.queryForObject(
"SELECT MAX(ID) FROM IMAGE",
Long.class
);
if (maxId == null) {
maxId = 0L;
}
counter.set(maxId);
}
@Override
public Metadata save(Metadata metadata) {
long id = counter.incrementAndGet();
jdbcTemplate.update(
"INSERT INTO METADATA (ID, POSTED_BY, RESOLVED_NAMES, POST_ID_REF) VALUES (?,?,?,?)",
id,
"INSERT INTO METADATA (POST_ID_REF, POST_ID, POSTED_BY, RESOLVED_NAMES) VALUES (?,?,?,?)",
metadata.getPostIdRef(),
metadata.getPostId(),
metadata.getPostedBy(),
String.join("%sep%", metadata.getResolvedNames()),
metadata.getPostIdRef()
String.join("%sep%", metadata.getResolvedNames())
);
metadata.setId(id);
applicationEventPublisher.publishEvent(new MetadataUpdateEvent(MetadataRepository.class, metadata.getPostIdRef()));
return metadata;
}
@Override
public Optional<Metadata> findById(Long id) {
List<Metadata> metadata = jdbcTemplate.query(
"SELECT * FROM METADATA AS metadata WHERE metadata.ID = ?",
new Object[]{id},
new MetadataRowMapper()
);
if (metadata.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(metadata.get(0));
}
}
@Override
public Optional<Metadata> findByPostId(String postId) {
List<Metadata> metadata = jdbcTemplate.query(
"SELECT metadata.* FROM METADATA AS metadata INNER JOIN POST post ON post.ID = metadata.POST_ID_REF WHERE post.POST_ID = ?",
new Object[]{postId},
new MetadataRowMapper()
"SELECT metadata.* FROM METADATA AS metadata WHERE metadata.POST_ID = ?",
new MetadataRowMapper(),
postId
);
if (metadata.isEmpty()) {
return Optional.empty();
@@ -78,8 +53,13 @@ public class MetadataRepository implements IMetadataRepository {
@Override
public int deleteByPostId(String postId) {
return jdbcTemplate.update(
"DELETE FROM METADATA AS metadata WHERE metadata.ID = (SELECT inner_metadata.ID FROM POST AS post INNER JOIN METADATA inner_metadata ON post.ID = inner_metadata.POST_ID_REF WHERE post.POST_ID = ?)",
"DELETE FROM METADATA AS metadata WHERE metadata.POST_ID = ?",
postId
);
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}
@@ -12,13 +12,13 @@ public class MetadataRowMapper implements RowMapper<Metadata> {
@Override
public Metadata mapRow(ResultSet rs, int rowNum) throws SQLException {
Metadata metadata = new Metadata();
metadata.setId(rs.getLong("ID"));
metadata.setPostIdRef(rs.getLong("POST_ID_REF"));
metadata.setPostId(rs.getString("POST_ID"));
metadata.setPostedBy(rs.getString("POSTED_BY"));
String resolvedNames = rs.getString("RESOLVED_NAMES");
if (resolvedNames != null && !resolvedNames.isBlank()) {
metadata.setResolvedNames(List.of(resolvedNames.split("%sep%")));
}
metadata.setPostIdRef(rs.getLong("POST_ID_REF"));
return metadata;
}
}
@@ -1,21 +1,25 @@
package tn.mnlr.vripper.jpa.repositories.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.event.PostRemoveEvent;
import tn.mnlr.vripper.event.PostUpdateEvent;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.jpa.repositories.IPostRepository;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@Service
public class PostRepository implements IPostRepository {
public class PostRepository implements IPostRepository, ApplicationEventPublisherAware {
private final JdbcTemplate jdbcTemplate;
private final AtomicLong counter = new AtomicLong(0);
private ApplicationEventPublisher applicationEventPublisher;
@Autowired
public PostRepository(JdbcTemplate jdbcTemplate) {
@@ -23,28 +27,22 @@ public class PostRepository implements IPostRepository {
}
@Override
public void init() {
Long maxId = jdbcTemplate.queryForObject(
"SELECT MAX(ID) FROM POST",
Long.class
);
if (maxId == null) {
maxId = 0L;
}
counter.set(maxId);
private synchronized Long nextId() {
return jdbcTemplate.queryForObject(
"CALL NEXT VALUE FOR SEQ_POST",
Long.class);
}
@Override
public Post save(Post post) {
long id = counter.incrementAndGet();
long id = nextId();
jdbcTemplate.update(
"INSERT INTO POST (ID, DONE, FORUM, HOSTS, POST_FOLDER_NAME, POST_ID, PREVIEWS, SECURITY_TOKEN, STATUS, THANKED, THREAD_ID, THREAD_TITLE, TITLE, TOTAL, URL) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
id,
post.getDone(),
post.getForum(),
String.join(";", post.getHosts()),
post.getPostFolderName(),
post.getDownloadDirectory(),
post.getPostId(),
String.join(";", post.getPreviews()),
post.getSecurityToken(),
@@ -57,24 +55,16 @@ public class PostRepository implements IPostRepository {
post.getUrl()
);
post.setId(id);
return null;
}
@Override
public int delete(Long id) {
return jdbcTemplate.update(
"DELETE FROM POST AS post WHERE post.ID = ?",
id
);
applicationEventPublisher.publishEvent(new PostUpdateEvent(PostRepository.class, id));
return post;
}
@Override
public Optional<Post> findByPostId(String postId) {
List<Post> posts = jdbcTemplate.query(
"SELECT metadata.*,post.* FROM METADATA metadata FULL JOIN POST post ON metadata.POST_ID_REF = post.ID WHERE POST_ID = ?",
new Object[]{postId},
new PostRowMapper()
);
"SELECT metadata.*,post.* FROM METADATA metadata FULL JOIN POST post ON metadata.POST_ID_REF = post.ID WHERE post.POST_ID = ?",
new PostRowMapper(),
postId);
if (posts.isEmpty()) {
return Optional.empty();
} else {
@@ -85,7 +75,7 @@ public class PostRepository implements IPostRepository {
@Override
public List<String> findCompleted() {
return jdbcTemplate.query(
"SELECT POST_ID FROM POST WHERE status = 'COMPLETE' AND done >= total",
"SELECT POST_ID FROM POST AS post WHERE status = 'COMPLETE' AND done >= total",
((rs, rowNum) -> rs.getString("POST_ID"))
);
}
@@ -94,9 +84,8 @@ public class PostRepository implements IPostRepository {
public Optional<Post> findById(Long id) {
List<Post> posts = jdbcTemplate.query(
"SELECT metadata.*,post.* FROM METADATA metadata FULL JOIN POST post ON metadata.POST_ID_REF = post.ID WHERE post.ID = ?",
new Object[]{id},
new PostRowMapper()
);
new PostRowMapper(),
id);
if (posts.isEmpty()) {
return Optional.empty();
} else {
@@ -116,9 +105,8 @@ public class PostRepository implements IPostRepository {
public boolean existByPostId(String postId) {
Integer count = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM POST AS post WHERE post.POST_ID = ?",
new Object[]{postId},
Integer.class
);
Integer.class,
postId);
if (count == null) {
return false;
} else {
@@ -135,49 +123,66 @@ public class PostRepository implements IPostRepository {
@Override
public int deleteByPostId(String postId) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"DELETE FROM POST AS post WHERE post.POST_ID = ?",
postId
);
applicationEventPublisher.publishEvent(new PostRemoveEvent(PostRepository.class, postId));
return mutationCount;
}
@Override
public int updateStatus(Status status, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE POST AS post SET post.STATUS = ? WHERE post.ID = ?",
status.name(), id
);
applicationEventPublisher.publishEvent(new PostUpdateEvent(PostRepository.class, id));
return mutationCount;
}
@Override
public int updateDone(int done, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE POST AS post SET post.DONE = ? WHERE post.ID = ?",
done, id
);
applicationEventPublisher.publishEvent(new PostUpdateEvent(PostRepository.class, id));
return mutationCount;
}
@Override
public int updateFolderName(String postFolderName, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE POST AS post SET post.POST_FOLDER_NAME = ? WHERE post.ID = ?",
postFolderName, id
);
applicationEventPublisher.publishEvent(new PostUpdateEvent(PostRepository.class, id));
return mutationCount;
}
@Override
public int updateTitle(String title, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE POST AS post SET post.TITLE = ? WHERE post.ID = ?",
title, id
);
applicationEventPublisher.publishEvent(new PostUpdateEvent(PostRepository.class, id));
return mutationCount;
}
@Override
public int updateThanked(boolean thanked, Long id) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"UPDATE POST AS post SET post.THANKED = ? WHERE post.ID = ?",
thanked, id
);
applicationEventPublisher.publishEvent(new PostUpdateEvent(PostRepository.class, id));
return mutationCount;
}
@Override
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}
@@ -19,34 +19,34 @@ public class PostRowMapper implements RowMapper<Post> {
Post post = new Post();
post.setId(rs.getLong("post.ID"));
post.setStatus(Status.valueOf(rs.getString("STATUS")));
post.setPostId(rs.getString("POST_ID"));
post.setThreadTitle(rs.getString("THREAD_TITLE"));
post.setThreadId(rs.getString("THREAD_ID"));
post.setTitle(rs.getString("TITLE"));
post.setUrl(rs.getString("URL"));
post.setDone(rs.getInt("DONE"));
post.setTotal(rs.getInt("TOTAL"));
post.setHosts(Set.of(rs.getString("HOSTS").split(DELIMITER)));
post.setForum(rs.getString("FORUM"));
post.setSecurityToken(rs.getString("SECURITY_TOKEN"));
post.setPostFolderName(rs.getString("POST_FOLDER_NAME"));
post.setThanked(rs.getBoolean("THANKED"));
post.setStatus(Status.valueOf(rs.getString("post.STATUS")));
post.setPostId(rs.getString("post.POST_ID"));
post.setThreadTitle(rs.getString("post.THREAD_TITLE"));
post.setThreadId(rs.getString("post.THREAD_ID"));
post.setTitle(rs.getString("post.TITLE"));
post.setUrl(rs.getString("post.URL"));
post.setDone(rs.getInt("post.DONE"));
post.setTotal(rs.getInt("post.TOTAL"));
post.setHosts(Set.of(rs.getString("post.HOSTS").split(DELIMITER)));
post.setForum(rs.getString("post.FORUM"));
post.setSecurityToken(rs.getString("post.SECURITY_TOKEN"));
post.setDownloadDirectory(rs.getString("post.POST_FOLDER_NAME"));
post.setThanked(rs.getBoolean("post.THANKED"));
String previews;
if ((previews = rs.getString("PREVIEWS")) != null) {
if ((previews = rs.getString("post.PREVIEWS")) != null) {
post.setPreviews(Set.of(previews.split(DELIMITER)));
}
Long metadataId = rs.getLong("metadata.ID");
Long metadataId = rs.getLong("metadata.POST_ID_REF");
if (!rs.wasNull()) {
Metadata metadata = new Metadata();
metadata.setId(metadataId);
metadata.setPostIdRef(rs.getLong("POST_ID_REF"));
String resolvedNames = rs.getString("RESOLVED_NAMES");
metadata.setPostIdRef(metadataId);
metadata.setPostId(rs.getString("metadata.POST_ID"));
String resolvedNames = rs.getString("metadata.RESOLVED_NAMES");
if (resolvedNames != null && !resolvedNames.isBlank()) {
metadata.setResolvedNames(List.of(resolvedNames.split("%sep%")));
}
metadata.setPostedBy(rs.getString("POSTED_BY"));
metadata.setPostedBy(rs.getString("metadata.POSTED_BY"));
post.setMetadata(metadata);
}
@@ -1,41 +1,38 @@
package tn.mnlr.vripper.jpa.repositories.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.event.QueuedRemoveEvent;
import tn.mnlr.vripper.event.QueuedUpdateEvent;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.jpa.repositories.IQueuedRepository;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
@Service
public class QueuedRepository implements IQueuedRepository {
public class QueuedRepository implements IQueuedRepository, ApplicationEventPublisherAware {
private final JdbcTemplate jdbcTemplate;
private final AtomicLong counter = new AtomicLong(0);
private ApplicationEventPublisher applicationEventPublisher;
@Autowired
public QueuedRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public void init() {
Long maxId = jdbcTemplate.queryForObject(
"SELECT MAX(ID) FROM QUEUED",
Long.class
);
if (maxId == null) {
maxId = 0L;
}
counter.set(maxId);
private synchronized Long nextId() {
return jdbcTemplate.queryForObject(
"CALL NEXT VALUE FOR SEQ_QUEUED",
Long.class);
}
@Override
public Queued save(Queued queued) {
long id = counter.incrementAndGet();
long id = nextId();
jdbcTemplate.update(
"INSERT INTO QUEUED (ID, TOTAL, LINK, LOADING, POST_ID, THREAD_ID) values (?,?,?,?,?,?)",
id,
@@ -46,6 +43,7 @@ public class QueuedRepository implements IQueuedRepository {
queued.getThreadId()
);
queued.setId(id);
applicationEventPublisher.publishEvent(new QueuedUpdateEvent(QueuedRepository.class, id));
return queued;
}
@@ -87,9 +85,21 @@ public class QueuedRepository implements IQueuedRepository {
@Override
public int deleteByThreadId(String threadId) {
return jdbcTemplate.update(
int mutationCount = jdbcTemplate.update(
"DELETE FROM QUEUED AS queued WHERE THREAD_ID = ?",
threadId
);
applicationEventPublisher.publishEvent(new QueuedRemoveEvent(QueuedRepository.class, threadId));
return mutationCount;
}
@Override
public void deleteAll() {
jdbcTemplate.update("DELETE FROM QUEUED");
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}
@@ -0,0 +1,7 @@
package tn.mnlr.vripper.listener;
import reactor.core.publisher.Flux;
public interface DataEventListener<T> {
Flux<T> getDataFlux();
}
@@ -0,0 +1,7 @@
package tn.mnlr.vripper.listener;
import reactor.core.publisher.Sinks.EmitFailureHandler;
public class EmitHandler {
public static final EmitFailureHandler RETRY = (signalType, emitResult) -> true;
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.EventRemoveEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class EventRemoveEventListener implements ApplicationListener<EventRemoveEvent>, DataEventListener<EventRemoveEvent> {
private final Sinks.Many<EventRemoveEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(EventRemoveEvent event) {
sink.emitNext(event, EmitHandler.RETRY);
}
@Override
public Flux<EventRemoveEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,33 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.EventUpdateEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class EventUpdateEventListener implements ApplicationListener<EventUpdateEvent>, DataEventListener<EventUpdateEvent> {
private final Sinks.Many<EventUpdateEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(@NonNull EventUpdateEvent event) {
sink.emitNext(event, EmitHandler.RETRY);
}
@Override
public Flux<EventUpdateEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.ImageUpdateEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class ImageUpdateEventListener implements ApplicationListener<ImageUpdateEvent>, DataEventListener<ImageUpdateEvent> {
private final Sinks.Many<ImageUpdateEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(ImageUpdateEvent event) {
sink.emitNext(event, EmitHandler.RETRY);
}
@Override
public Flux<ImageUpdateEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.MetadataUpdateEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class MetadataUpdateEventListener implements ApplicationListener<MetadataUpdateEvent>, DataEventListener<MetadataUpdateEvent> {
private final Sinks.Many<MetadataUpdateEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(MetadataUpdateEvent event) {
sink.emitNext(event, (signalType, emitResult) -> true);
}
@Override
public Flux<MetadataUpdateEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.PostRemoveEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class PostRemoveEventListener implements ApplicationListener<PostRemoveEvent>, DataEventListener<PostRemoveEvent> {
private final Sinks.Many<PostRemoveEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(PostRemoveEvent event) {
sink.emitNext(event, EmitHandler.RETRY);
}
@Override
public Flux<PostRemoveEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.PostUpdateEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class PostUpdateEventListener implements ApplicationListener<PostUpdateEvent>, DataEventListener<PostUpdateEvent> {
private final Sinks.Many<PostUpdateEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(PostUpdateEvent event) {
sink.emitNext(event, EmitHandler.RETRY);
}
@Override
public Flux<PostUpdateEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.QueuedRemoveEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class QueuedRemoveEventListener implements ApplicationListener<QueuedRemoveEvent>, DataEventListener<QueuedRemoveEvent> {
private final Sinks.Many<QueuedRemoveEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(QueuedRemoveEvent event) {
sink.emitNext(event, (signalType, emitResult) -> true);
}
@Override
public Flux<QueuedRemoveEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -0,0 +1,32 @@
package tn.mnlr.vripper.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.event.QueuedUpdateEvent;
import javax.annotation.PreDestroy;
@Component
@Slf4j
public class QueuedUpdateEventListener implements ApplicationListener<QueuedUpdateEvent>, DataEventListener<QueuedUpdateEvent> {
private final Sinks.Many<QueuedUpdateEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
@Override
public void onApplicationEvent(QueuedUpdateEvent event) {
sink.emitNext(event, (signalType, emitResult) -> true);
}
@Override
public Flux<QueuedUpdateEvent> getDataFlux() {
return sink.asFlux();
}
@PreDestroy
private void destroy() {
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
}
}
@@ -1,5 +1,8 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.RetryPolicy;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.AbstractExecutionAwareRequest;
@@ -13,37 +16,79 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import tn.mnlr.vripper.download.DownloadJob;
import javax.annotation.PreDestroy;
import java.net.URI;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
@EnableScheduling
@Slf4j
public class ConnectionService {
private ConnectionService() {
private final Disposable disposable;
private PoolingHttpClientConnectionManager pcm;
private RequestConfig rc;
@Getter
private RetryPolicy<Object> retryPolicy;
private int connectionTimeout;
private int maxAttempts;
public ConnectionService(SettingsService settingsService) {
connectionTimeout = settingsService.getSettings().getConnectionTimeout();
maxAttempts = settingsService.getSettings().getMaxAttempts();
Flux<SettingsService.Settings> settingsFlux = settingsService.getSettingsFlux();
disposable = settingsFlux.subscribe(settings -> {
if (connectionTimeout != settings.getConnectionTimeout()) {
connectionTimeout = settings.getConnectionTimeout();
buildRequestConfig();
}
if (maxAttempts != settings.getMaxAttempts()) {
maxAttempts = settings.getMaxAttempts();
buildRetryPolicy();
}
});
buildRequestConfig();
buildRetryPolicy();
buildConnectionPool();
}
private PoolingHttpClientConnectionManager pcm;
private RequestConfig rc = RequestConfig.custom()
.setConnectionRequestTimeout(5_000)
.setConnectTimeout(5_000)
.setSocketTimeout(5_000)
.setCookieSpec(CookieSpecs.STANDARD)
.build();
private void buildConnectionPool() {
pcm = new PoolingHttpClientConnectionManager();
pcm.setMaxTotal(50);
pcm.setDefaultMaxPerRoute(4);
@PreDestroy
private void destroy() {
disposable.dispose();
}
@Scheduled(fixedDelay = 1000)
private void buildRetryPolicy() {
retryPolicy = new RetryPolicy<>()
.withDelay(2, 5, ChronoUnit.SECONDS)
.withMaxAttempts(maxAttempts)
.onFailedAttempt(e -> log.warn(String.format("#%d tries failed", e.getAttemptCount()), e.getLastFailure()));
}
private void buildConnectionPool() {
pcm = new PoolingHttpClientConnectionManager();
pcm.setMaxTotal(Integer.MAX_VALUE);
pcm.setDefaultMaxPerRoute(Integer.MAX_VALUE);
}
private void buildRequestConfig() {
rc = RequestConfig.custom()
.setConnectionRequestTimeout(connectionTimeout * 1000)
.setConnectTimeout(connectionTimeout * 1000)
.setSocketTimeout(connectionTimeout * 1000)
.setCookieSpec(CookieSpecs.STANDARD)
.build();
}
@Scheduled(fixedDelay = 5_000)
private void idleConnectionMonitoring() {
pcm.closeExpiredConnections();
pcm.closeIdleConnections(30, TimeUnit.SECONDS);
@@ -1,21 +1,17 @@
package tn.mnlr.vripper.services;
import io.reactivex.Observable;
import io.reactivex.processors.PublishProcessor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Metadata;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.jpa.domain.*;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.jpa.repositories.IImageRepository;
import tn.mnlr.vripper.jpa.repositories.IMetadataRepository;
import tn.mnlr.vripper.jpa.repositories.IPostRepository;
import tn.mnlr.vripper.jpa.repositories.IQueuedRepository;
import tn.mnlr.vripper.jpa.repositories.impl.EventRepository;
import java.util.Collection;
import java.util.List;
@@ -31,56 +27,28 @@ public class DataService {
private final IQueuedRepository queuedRepository;
private final IMetadataRepository metadataRepository;
private final SettingsService settingsService;
private final PublishProcessor<Long> liveGrabQueue = PublishProcessor.create();
private final PublishProcessor<Long> liveImageUpdates = PublishProcessor.create();
private final PublishProcessor<Long> livePostsState = PublishProcessor.create();
private final PublishProcessor<String> postRemove = PublishProcessor.create();
private final PublishProcessor<String> queueRemove = PublishProcessor.create();
public Observable<Long> liveQueue() {
return liveGrabQueue.toObservable();
}
public Observable<Long> livePost() {
return livePostsState.toObservable();
}
public Observable<Long> liveImage() {
return liveImageUpdates.toObservable();
}
public Observable<String> queueRemove() {
return queueRemove.toObservable();
}
public Observable<String> postRemove() {
return postRemove.toObservable();
}
private final EventRepository eventRepository;
@Autowired
public DataService(IPostRepository postRepository, IImageRepository imageRepository, IQueuedRepository queuedRepository, IMetadataRepository metadataRepository, SettingsService settingsService) {
public DataService(IPostRepository postRepository, IImageRepository imageRepository, IQueuedRepository queuedRepository, IMetadataRepository metadataRepository, SettingsService settingsService, EventRepository eventRepository) {
this.postRepository = postRepository;
this.imageRepository = imageRepository;
this.queuedRepository = queuedRepository;
this.metadataRepository = metadataRepository;
this.settingsService = settingsService;
this.eventRepository = eventRepository;
}
private void save(Post post) {
postRepository.save(post);
livePostsState.onNext(post.getId());
}
private void save(Queued queued) {
queuedRepository.save(queued);
liveGrabQueue.onNext(queued.getId());
}
private void save(Image image) {
imageRepository.save(image);
liveImageUpdates.onNext(image.getId());
}
public boolean exists(String postId) {
@@ -110,7 +78,6 @@ public class DataService {
}
private void updatePostDone(int done, Long id) {
livePostsState.onNext(id);
postRepository.updateDone(done, id);
}
@@ -136,7 +103,6 @@ public class DataService {
imageRepository.deleteAllByPostId(postId);
metadataRepository.deleteByPostId(postId);
postRepository.deleteByPostId(postId);
postRemove.onNext(postId);
}
public void newQueueLink(@NonNull final Queued queued) {
@@ -145,7 +111,6 @@ public class DataService {
public void removeQueueLink(@NonNull final String threadId) {
queuedRepository.deleteByThreadId(threadId);
queueRemove.onNext(threadId);
}
public List<String> clearCompleted() {
@@ -177,7 +142,7 @@ public class DataService {
return imageRepository.findByPostId(postId);
}
public Iterable<Post> findAllPosts() {
public List<Post> findAllPosts() {
return postRepository.findAll();
}
@@ -193,11 +158,11 @@ public class DataService {
return queuedRepository.findByThreadId(threadId);
}
public Iterable<Queued> findAllQueued() {
public List<Queued> findAllQueued() {
return queuedRepository.findAll();
}
public Optional<Post> findPostById(Long aLong) {
public Optional<Post> findById(Long aLong) {
return postRepository.findById(aLong);
}
@@ -209,10 +174,11 @@ public class DataService {
return queuedRepository.findById(aLong);
}
public void setMetadata(Post post, Metadata metadata) {
metadata.setPostIdRef(post.getId());
metadataRepository.save(metadata);
livePostsState.onNext(post.getId());
public synchronized void setMetadata(Post post, Metadata metadata) {
if (metadataRepository.findByPostId(post.getPostId()).isEmpty()) {
metadata.setPostIdRef(post.getId());
metadataRepository.save(metadata);
}
}
public Optional<Metadata> findMetadataByPostId(String postId) {
@@ -221,36 +187,41 @@ public class DataService {
public void updateImageStatus(Status status, Long id) {
imageRepository.updateStatus(status, id);
liveImageUpdates.onNext(id);
}
public void updateImageCurrent(long current, Long id) {
imageRepository.updateCurrent(current, id);
liveImageUpdates.onNext(id);
}
public void updateImageTotal(long total, Long id) {
imageRepository.updateTotal(total, id);
liveImageUpdates.onNext(id);
}
public void updatePostStatus(Status status, Long id) {
postRepository.updateStatus(status, id);
livePostsState.onNext(id);
}
public void updatePostFolderName(String postFolderName, Long id) {
public void updateDownloadDirectory(String postFolderName, Long id) {
postRepository.updateFolderName(postFolderName, id);
livePostsState.onNext(id);
}
public void updatePostTitle(String title, Long id) {
postRepository.updateTitle(title, id);
livePostsState.onNext(id);
}
public void updatePostThanked(boolean thanked, Long id) {
postRepository.updateThanked(thanked, id);
livePostsState.onNext(id);
}
public Optional<Event> findEventById(Long id) {
return eventRepository.findById(id);
}
public List<Event> findAllEvents() {
return eventRepository.findAll();
}
public void clearQueueLinks() {
queuedRepository.deleteAll();
}
}
@@ -1,27 +1,30 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.listener.EmitHandler;
import javax.annotation.PreDestroy;
import java.util.concurrent.atomic.AtomicLong;
@Service
@EnableScheduling
public class DownloadSpeedService {
private AtomicLong read = new AtomicLong(0);
private final AtomicLong read = new AtomicLong(0);
private final Sinks.Many<Long> sink = Sinks.many().multicast().onBackpressureBuffer();
@Getter
private long currentValue;
@Getter
private final PublishProcessor<Long> readBytesPerSecond = PublishProcessor.create();
private boolean allowWrite = false;
public Flux<Long> getReadBytesPerSecond() {
return sink.asFlux();
}
public void increase(long read) {
if (allowWrite) {
this.read.addAndGet(read);
@@ -34,8 +37,13 @@ public class DownloadSpeedService {
long newValue = read.getAndSet(0);
if (newValue != currentValue) {
currentValue = newValue;
readBytesPerSecond.onNext(currentValue);
sink.emitNext(currentValue, EmitHandler.RETRY);
}
allowWrite = true;
}
@PreDestroy
private void destroy() {
sink.emitComplete(EmitHandler.RETRY);
}
}
@@ -1,15 +1,19 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.download.DownloadService;
import tn.mnlr.vripper.download.PendingQueue;
import tn.mnlr.vripper.listener.EmitHandler;
import tn.mnlr.vripper.services.domain.GlobalState;
import javax.annotation.PreDestroy;
@Service
@EnableScheduling
public class GlobalStateService {
@@ -17,13 +21,10 @@ public class GlobalStateService {
private final PendingQueue pendingQueue;
private final DownloadService downloadService;
private final DataService dataService;
private final Sinks.Many<GlobalState> sink = Sinks.many().multicast().onBackpressureBuffer();
@Getter
private GlobalState currentState;
@Getter
private final PublishProcessor<GlobalState> liveGlobalState = PublishProcessor.create();
@Autowired
public GlobalStateService(PendingQueue pendingQueue, DownloadService downloadService, DataService dataService) {
this.pendingQueue = pendingQueue;
@@ -31,6 +32,10 @@ public class GlobalStateService {
this.dataService = dataService;
}
public Flux<GlobalState> getGlobalState() {
return sink.asFlux();
}
@Scheduled(fixedDelay = 3000)
private void interval() {
GlobalState newGlobalState = new GlobalState(
@@ -39,7 +44,12 @@ public class GlobalStateService {
dataService.countErrorImages());
if (!newGlobalState.equals(currentState)) {
currentState = newGlobalState;
liveGlobalState.onNext(currentState);
sink.emitNext(currentState, EmitHandler.RETRY);
}
}
@PreDestroy
private void destroy() {
sink.emitComplete(EmitHandler.RETRY);
}
}
@@ -31,31 +31,6 @@ public class HostService {
this.htmlProcessorService = htmlProcessorService;
}
@Getter
public static class Response {
private final Document document;
private final Header[] headers;
protected Response(Document document, Header[] headers) {
this.document = document;
this.headers = headers;
}
}
@Getter
public static class NameUrl {
private String name;
private String url;
public NameUrl(String name, String url) {
this.name = name;
this.url = url;
}
}
public Response getResponse(final String url, final HttpClientContext context) throws HostException {
String basePage;
@@ -102,4 +77,28 @@ public class HostService {
log.debug(String.format("Extracting name from url %s: %s", imgUrl, imageTitle));
return imgUrl;
}
@Getter
public static class Response {
private final Document document;
private final Header[] headers;
protected Response(Document document, Header[] headers) {
this.document = document;
this.headers = headers;
}
}
@Getter
public static class NameUrl {
private final String name;
private final String url;
public NameUrl(String name, String url) {
this.name = name;
this.url = url;
}
}
}
@@ -4,27 +4,24 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.jpa.domain.Metadata;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.services.domain.tasks.MetadataRunnable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -34,46 +31,21 @@ import java.util.stream.Collectors;
@Service
public class MetadataService {
@Getter
static class Key {
private final String postId;
private final String threadId;
private final String url;
Key(String postId, String threadId, String url) {
this.postId = postId;
this.threadId = threadId;
this.url = url;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Key key = (Key) o;
return Objects.equals(postId, key.postId);
}
@Override
public int hashCode() {
return Objects.hash(postId);
}
}
private static final List<String> dictionary = Arrays.asList("download", "link", "rapidgator", "filefactory", "filefox");
private final LoadingCache<Key, Metadata> cache;
private final ConnectionService cm;
private final VGAuthService VGAuthService;
private final HtmlProcessorService htmlProcessorService;
private final XpathService xpathService;
private final Map<String, MetadataRunnable> fetchingMetadata = new ConcurrentHashMap<>();
private final ThreadPoolService threadPoolService;
@Autowired
public MetadataService(ConnectionService cm, VGAuthService VGAuthService, HtmlProcessorService htmlProcessorService, XpathService xpathService) {
public MetadataService(ConnectionService cm, VGAuthService VGAuthService, HtmlProcessorService htmlProcessorService, XpathService xpathService, ThreadPoolService threadPoolService) {
this.cm = cm;
this.VGAuthService = VGAuthService;
this.htmlProcessorService = htmlProcessorService;
this.xpathService = xpathService;
this.threadPoolService = threadPoolService;
CacheLoader<Key, Metadata> loader = new CacheLoader<>() {
@Override
@@ -87,17 +59,29 @@ public class MetadataService {
}
public Metadata get(Post post) throws ExecutionException {
Metadata metadata = new Metadata();
Metadata cachedMetadata = cache.get(new Key(post.getPostId(), post.getThreadId(), post.getUrl()));
metadata.setPostedBy(cachedMetadata.getPostedBy());
metadata.setResolvedNames(List.copyOf(cachedMetadata.getResolvedNames()));
return metadata;
Key key = new Key(post.getPostId(), post.getThreadId(), post.getUrl());
return Metadata.from(cache.get(key));
}
public void startFetchingMetadata(Post post) {
MetadataRunnable runnable = new MetadataRunnable(post);
threadPoolService.getGeneralExecutor().submit(runnable);
fetchingMetadata.put(post.getPostId(), runnable);
}
public void stopFetchingMetadata(Post post) {
this.fetchingMetadata.forEach((k, v) -> {
if (k.equals(post.getPostId())) {
v.setInterrupted(true);
}
});
fetchingMetadata.remove(post.getPostId());
}
private Metadata fetchMetadata(Key key) {
HttpGet httpGet = cm.buildHttpGet(key.getUrl(), null);
Metadata metadata = new Metadata();
Failsafe.with(VripperApplication.retryPolicy)
Failsafe.with(cm.getRetryPolicy())
.onFailure(e -> {
if (e.getFailure() instanceof InterruptedException || e.getFailure().getCause() instanceof InterruptedException) {
log.debug("Fetching interrupted");
@@ -122,6 +106,8 @@ public class MetadataService {
Node node = xpathService.getAsNode(document, String.format("//div[@id='post_message_%s']", key.getPostId()));
metadata.setResolvedNames(findTitleInContent(node));
metadata.setPostId(key.getPostId());
} catch (Exception e) {
throw new PostParseException(String.format("Failed to parse thread %s, post %s", key.getThreadId(), key.getPostId()), e);
} finally {
@@ -162,4 +148,30 @@ public class MetadataService {
}
}
}
@Getter
static class Key {
private final String postId;
private final String threadId;
private final String url;
Key(String postId, String threadId, String url) {
this.postId = postId;
this.threadId = threadId;
this.url = url;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Key key = (Key) o;
return Objects.equals(postId, key.postId);
}
@Override
public int hashCode() {
return Objects.hash(postId);
}
}
}
@@ -1,108 +1,82 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.exception.RenameException;
import tn.mnlr.vripper.jpa.domain.Post;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.concurrent.locks.ReentrantLock;
@Service
@Slf4j
public class PathService {
public static final int MAX_ATTEMPTS = 24;
private final SettingsService settingsService;
private final DataService dataService;
private final ThreadPoolService threadPoolService;
@Getter
private final ReentrantLock directoryAccess = new ReentrantLock();
@Autowired
public PathService(SettingsService settingsService, DataService dataService, ThreadPoolService threadPoolService) {
public PathService(SettingsService settingsService, DataService dataService) {
this.settingsService = settingsService;
this.dataService = dataService;
this.threadPoolService = threadPoolService;
}
public final File getDownloadDestinationFolder(Post post) {
return _getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), post.getPostFolderName(), post.getPostId());
public final File calcDownloadDirectory(Post post) {
return new File(settingsService.getSettings().getDownloadPath(), post.getDownloadDirectory());
}
private File _getRootFolder(@NonNull String forum, @NonNull String threadTitle) {
private File getRootFolder(@NonNull String forum, @NonNull String threadTitle) {
File sourceFolder = settingsService.getSettings().getSubLocation() ? new File(settingsService.getSettings().getDownloadPath(), sanitize(forum)) : new File(settingsService.getSettings().getDownloadPath());
return settingsService.getSettings().getThreadSubLocation() ? new File(sourceFolder, threadTitle) : sourceFolder;
}
private File _getDownloadDestinationFolder(@NonNull String forum, @NonNull String threadTitle, @NonNull String title, @NonNull String postId) {
File sourceFolder = _getRootFolder(forum, threadTitle);
return new File(sourceFolder, title);
}
private File _createDownloadDestinationFolder(@NonNull String forum, @NonNull String threadTitle, @NonNull String title, @NonNull String postId) {
File sourceFolder = _getRootFolder(forum, threadTitle);
return new File(sourceFolder, settingsService.getSettings().getAppendPostId() ? title + "_" + postId : title);
}
public final void createDefaultPostFolder(Post post) {
File sourceFolder = _createDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(post.getTitle()), post.getPostId());
File destFolder = makeDirs(sourceFolder);
post.setPostFolderName(destFolder.getName());
dataService.updatePostFolderName(post.getPostFolderName(), post.getId());
File downloadDirectory = getRootFolder(post.getForum(), post.getThreadTitle());
downloadDirectory = new File(downloadDirectory, settingsService.getSettings().getAppendPostId() ? sanitize(post.getTitle()) + "_" + post.getPostId() : sanitize(post.getTitle()));
downloadDirectory = makeDir(downloadDirectory);
post.setDownloadDirectory(downloadDirectory.getAbsolutePath().replace(settingsService.getSettings().getDownloadPath(), ""));
dataService.updateDownloadDirectory(post.getDownloadDirectory(), post.getId());
}
public final void rename(@NonNull String postId, @NonNull String altName) {
public final void rename(@NonNull String postId, @NonNull String altName) throws RenameException {
Post post = dataService.findPostByPostId(postId).orElseThrow();
threadPoolService.getGeneralExecutor().submit(() -> {
if (altName.equals(post.getTitle())) {
return;
}
if (altName.equals(post.getTitle())) {
return;
}
// Download have not started yet
if (post.getDownloadDirectory() == null) {
post.setTitle(altName);
dataService.updatePostTitle(post.getTitle(), post.getId());
if (post.getPostFolderName() == null) {
return;
}
File newDestFolder = makeDirs(_getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(altName), postId));
File currentDesFolder = getDownloadDestinationFolder(post);
post.setPostFolderName(newDestFolder.getName());
dataService.updatePostFolderName(post.getPostFolderName(), post.getId());
return;
}
List<File> files = Arrays.stream(Objects.requireNonNull(currentDesFolder.listFiles())).filter(e -> !e.getName().endsWith(".tmp")).collect(Collectors.toList());
for (File f : files) {
try {
Files.move(f.toPath(), Paths.get(newDestFolder.toString(), f.toPath().getFileName().toString()), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.error(String.format("Failed to move files from %s to %s", currentDesFolder.toString(), newDestFolder.toString()), e);
return;
}
}
File newDownloadDirectory = getRootFolder(post.getForum(), post.getThreadTitle());
newDownloadDirectory = new File(newDownloadDirectory, sanitize(altName));
File currentDownloadDirectory = calcDownloadDirectory(post);
try {
directoryAccess.lock();
Files.move(currentDownloadDirectory.toPath(), newDownloadDirectory.toPath(), StandardCopyOption.ATOMIC_MOVE);
post.setDownloadDirectory(newDownloadDirectory.getAbsolutePath().replace(settingsService.getSettings().getDownloadPath(), ""));
dataService.updateDownloadDirectory(post.getDownloadDirectory(), post.getId());
int attempts = 0;
while (currentDesFolder.exists() && attempts <= MAX_ATTEMPTS) {
attempts++;
if (!currentDesFolder.delete()) {
log.warn(String.format("Failed to remove %s", currentDesFolder.toString()));
}
try {
Thread.sleep(5_000);
} catch (InterruptedException ignored) {
}
}
if (attempts > MAX_ATTEMPTS) {
log.error(String.format("Failed to rename post %s", postId));
}
});
post.setTitle(altName);
dataService.updatePostTitle(post.getTitle(), post.getId());
} catch (IOException e) {
throw new RenameException(String.format("Failed to move files from %s to %s", currentDownloadDirectory.toString(), newDownloadDirectory.toString()), e);
} finally {
directoryAccess.unlock();
}
}
private File makeDirs(@NonNull final File sourceFolder) {
private File makeDir(@NonNull final File sourceFolder) {
int counter = 1;
File folder = sourceFolder;
@@ -3,54 +3,40 @@ package tn.mnlr.vripper.services;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.download.PendingQueue;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.services.domain.*;
import tn.mnlr.vripper.services.domain.MultiPostScanParser;
import tn.mnlr.vripper.services.domain.MultiPostScanResult;
import tn.mnlr.vripper.services.domain.tasks.AddPostRunnable;
import tn.mnlr.vripper.services.domain.tasks.AddQueuedRunnable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class PostService {
private final SettingsService settingsService;
private final PendingQueue pendingQueue;
private final DataService dataService;
private final ThreadPoolService threadPoolService;
private final Map<String, Future<?>> fetchingMetadata = new ConcurrentHashMap<>();
private final VGAuthService VGAuthService;
@Getter
private final LoadingCache<Queued, List<MultiPostItem>> cache;
private final MetadataService metadataService;
private final LoadingCache<Queued, MultiPostScanResult> cache;
@Autowired
public PostService(SettingsService settingsService, PendingQueue pendingQueue, DataService dataService, ThreadPoolService threadPoolService, VGAuthService VGAuthService) {
this.settingsService = settingsService;
this.pendingQueue = pendingQueue;
public PostService(DataService dataService, ThreadPoolService threadPoolService, MetadataService metadataService) {
this.dataService = dataService;
this.threadPoolService = threadPoolService;
this.VGAuthService = VGAuthService;
this.metadataService = metadataService;
CacheLoader<Queued, List<MultiPostItem>> loader = new CacheLoader<>() {
CacheLoader<Queued, MultiPostScanResult> loader = new CacheLoader<>() {
@Override
public List<MultiPostItem> load(@NonNull Queued multiPostItem) throws Exception {
ApiThreadParser apiThreadParser = new ApiThreadParser(multiPostItem);
return apiThreadParser.parse();
public MultiPostScanResult load(@NonNull Queued multiPostItem) throws Exception {
return new MultiPostScanParser(multiPostItem).parse();
}
};
@@ -59,95 +45,22 @@ public class PostService {
.build(loader);
}
public void addPost(String postId, String threadId) throws PostParseException {
if (dataService.exists(postId)) {
log.warn(String.format("skipping %s, already loaded", postId));
return;
}
ApiPostParser apiPostParser = new ApiPostParser(threadId, postId);
ApiPost apiPost = apiPostParser.parse();
if (apiPost.getPost().isEmpty()) {
throw new PostParseException(String.format("parsing failed for thread %s, post %s", threadId, postId));
}
Post post = apiPost.getPost().get();
Set<Image> images = apiPost.getImages();
dataService.newPost(post, images);
// Metadata thread
fetchingMetadata.put(post.getPostId(), threadPoolService.getGeneralExecutor().submit(new MetadataRunnable(post)));
if (settingsService.getSettings().getAutoStart()) {
log.debug("Auto start downloads option is enabled");
post.setStatus(Status.PENDING);
try {
pendingQueue.enqueue(post, images);
} catch (InterruptedException e) {
log.warn("Interruption was caught");
Thread.currentThread().interrupt();
return;
}
log.debug(String.format("Done enqueuing jobs for %s", post.getUrl()));
} else {
post.setStatus(Status.STOPPED);
log.debug("Auto start downloads option is disabled");
}
if (!settingsService.getSettings().getLeaveThanksOnStart()) {
VGAuthService.leaveThanks(post);
}
dataService.updatePostStatus(post.getStatus(), post.getId());
}
public void stopFetchingMetadata(Post post) {
this.fetchingMetadata.forEach((k, v) -> {
if (k.equals(post.getPostId())) {
v.cancel(true);
}
});
fetchingMetadata.remove(post.getPostId());
metadataService.stopFetchingMetadata(post);
}
public void processMultiPost(List<Queued> queuedList) throws Exception {
public void processMultiPost(List<Queued> queuedList) {
for (Queued queued : queuedList) {
if (queued.getPostId() != null) {
addPost(queued.getPostId(), queued.getThreadId());
threadPoolService.getGeneralExecutor().submit(new AddPostRunnable(queued.getPostId(), queued.getThreadId()));
} else {
threadPoolService.getGeneralExecutor().submit(() -> this.multiPost(queued));
threadPoolService.getGeneralExecutor().submit(new AddQueuedRunnable(queued));
}
}
}
private void multiPost(Queued queued) {
List<MultiPostItem> multiPostItems;
try {
multiPostItems = cache.get(queued);
} catch (ExecutionException e) {
log.error(String.format("Failed to add post with thread id %s, postId %s", queued.getThreadId(), queued.getPostId()), e);
return;
}
queued.setTotal(multiPostItems.size());
queued.done();
log.debug(String.format("%d found for %s", multiPostItems.size(), queued.getLink()));
if (multiPostItems.size() == 1) {
try {
addPost(multiPostItems.get(0).getPostId(), multiPostItems.get(0).getThreadId());
} catch (PostParseException e) {
log.error(String.format("Failed to add post with postId %s", multiPostItems.get(0).getPostId()), e);
return;
}
log.debug(String.format("threadId %s, postId %s is added automatically for download", queued.getThreadId(), queued.getPostId()));
} else {
if(dataService.findQueuedByThreadId(queued.getThreadId()).isEmpty()) {
dataService.newQueueLink(queued);
} else {
log.info(String.format("Thread with id = %s is already loaded", queued.getThreadId()));
}
}
public MultiPostScanResult get(Queued queued) throws ExecutionException {
return cache.get(queued);
}
public void remove(String threadId) {
@@ -2,6 +2,7 @@ package tn.mnlr.vripper.services;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
@@ -10,39 +11,95 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.exception.ValidationException;
import tn.mnlr.vripper.listener.EmitHandler;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static java.nio.file.StandardOpenOption.*;
@Service
@Getter
@Setter
@Slf4j
public class SettingsService {
private final Path configPath;
private final Path customProxiesPath;
private final ObjectMapper om = new ObjectMapper();
private final Set<String> proxies = new HashSet<>();
private Sinks.Many<Settings> sink = Sinks.many().multicast().onBackpressureBuffer();
@Getter
private Settings settings = new Settings();
@Value("classpath:proxies.json")
private Resource defaultProxies;
public SettingsService(@Value("${base.dir}") String baseDir, @Value("${base.dir.name}") String baseDirName) {
this.configPath = Paths.get(baseDir, baseDirName, "config.json");
this.customProxiesPath = Paths.get(baseDir, baseDirName, "proxies.json");
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
@PostConstruct
private void init() {
loadViperProxies();
restore();
sink.emitNext(settings, EmitHandler.RETRY);
}
private void loadViperProxies() {
try (InputStream defaultProxiesIs = defaultProxies.getInputStream()) {
List<String> defaultProxies = om.readValue(defaultProxiesIs, new TypeReference<>() {
});
List<String> customProxies = new ArrayList<>();
if (customProxiesPath.toFile().exists() && customProxiesPath.toFile().isFile()) {
customProxies = om.readValue(customProxiesPath.toFile(), new TypeReference<>() {
});
} else {
if (!customProxiesPath.toFile().createNewFile()) {
log.warn("Unable to create " + customProxiesPath.toFile().getAbsolutePath());
} else {
try (FileWriter fw = new FileWriter(customProxiesPath.toFile())) {
fw.append("[]").append(System.lineSeparator());
fw.flush();
} catch (IOException e) {
log.warn("Unable to create " + customProxiesPath.toFile().getAbsolutePath(), e);
}
}
}
proxies.addAll(customProxies);
proxies.addAll(defaultProxies);
} catch (IOException e) {
log.error("Failed to load vipergirls proxies list", e);
}
proxies.add("https://vipergirls.to");
}
Flux<Settings> getSettingsFlux() {
return sink.asFlux();
}
public List<String> getProxies() {
return new ArrayList<>(proxies);
}
public void newSettings(Settings settings) {
@@ -60,16 +117,13 @@ public class SettingsService {
this.settings = settings;
save();
sink.emitNext(settings, EmitHandler.RETRY);
}
public void restore() {
try {
settings = om.readValue(configPath.toFile(), Settings.class);
try {
check(this.settings);
} catch (ValidationException e) {
log.error(String.format("Your settings are invalid, either remove %s, or fix it", configPath.toString()), e);
SpringContext.close();
if (configPath.toFile().exists()) {
settings = om.readValue(configPath.toFile(), Settings.class);
}
} catch (IOException e) {
log.error("Failed restore user settings", e);
@@ -140,19 +194,47 @@ public class SettingsService {
settings.setLeaveThanksOnStart(false);
}
if (settings.getConnectionTimeout() == null) {
settings.setConnectionTimeout(30);
}
if (settings.getMaxAttempts() == null) {
settings.setMaxAttempts(5);
}
if (settings.getVProxy() == null || !proxies.contains(settings.getVProxy())) {
settings.setVProxy("https://vipergirls.to");
}
if (settings.getMaxEventLog() == null) {
settings.setMaxEventLog(1000);
}
try {
check(this.settings);
} catch (ValidationException e) {
log.error(String.format("Your settings are invalid, either remove %s, or fix it", configPath.toString()), e);
SpringContext.close();
}
save();
}
@PreDestroy
public void save() {
try {
Files.write(configPath, om.writeValueAsBytes(settings), CREATE, WRITE, TRUNCATE_EXISTING, SYNC);
} catch (IOException e) {
log.error("Failed to store user settings", e);
}
}
@PreDestroy
private void destroy() {
save();
sink.emitComplete(EmitHandler.RETRY);
}
public void check(Settings settings) throws ValidationException {
Path path;
@@ -174,6 +256,22 @@ public class SettingsService {
if (settings.getMaxThreads() < 1 || settings.getMaxThreads() > 4) {
throw new ValidationException(String.format("Invalid max concurrent download settings, values must be in [%d,%d]", 1, 4));
}
if (settings.getConnectionTimeout() < 1 || settings.getConnectionTimeout() > 300) {
throw new ValidationException(String.format("Invalid connection timeout settings, values must be in [%d,%d]", 1, 300));
}
if (settings.getMaxAttempts() < 1 || settings.getMaxAttempts() > 10) {
throw new ValidationException(String.format("Invalid maximum attempts settings, values must be in [%d,%d]", 1, 10));
}
if (settings.getMaxEventLog() < 100 || settings.getMaxEventLog() > 10_000) {
throw new ValidationException(String.format("Invalid maximum event log record settings, values must be in [%d,%d]", 100, 10_000));
}
if (!settings.getVThanks() && settings.getLeaveThanksOnStart() != null && settings.getLeaveThanksOnStart()) {
throw new ValidationException("Invalid value, leave thanks must be checked");
}
}
public Theme getTheme() {
@@ -250,5 +348,18 @@ public class SettingsService {
@JsonProperty("leaveThanksOnStart")
private Boolean leaveThanksOnStart;
@JsonProperty("connectionTimeout")
private Integer connectionTimeout;
@JsonProperty("maxAttempts")
private Integer maxAttempts;
@JsonProperty("vProxy")
private String vProxy;
@JsonProperty("maxEventLog")
private Integer maxEventLog;
}
}
@@ -1,11 +1,8 @@
package tn.mnlr.vripper.services;
import io.reactivex.Scheduler;
import io.reactivex.schedulers.Schedulers;
import lombok.Getter;
import org.springframework.stereotype.Service;
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -14,15 +11,9 @@ import java.util.concurrent.TimeUnit;
public class ThreadPoolService {
@Getter
private final ExecutorService generalExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
private final ExecutorService schedulerExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Getter
private final Scheduler scheduler = Schedulers.from(schedulerExecutor);
public void destroy() throws Exception {
generalExecutor.shutdown();
generalExecutor.awaitTermination(5, TimeUnit.SECONDS);
schedulerExecutor.shutdown();
schedulerExecutor.awaitTermination(5, TimeUnit.SECONDS);
}
}
@@ -1,6 +1,5 @@
package tn.mnlr.vripper.services;
import io.reactivex.processors.PublishProcessor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.NameValuePair;
@@ -15,10 +14,16 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import tn.mnlr.vripper.exception.VripperException;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.listener.EmitHandler;
import tn.mnlr.vripper.services.domain.tasks.LeaveThanksRunnable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.List;
@@ -29,39 +34,42 @@ public class VGAuthService {
private final ConnectionService cm;
private final SettingsService settingsService;
private final ThreadPoolService threadPoolService;
private final DataService dataService;
private final Disposable disposable;
@Getter
private final HttpClientContext context = HttpClientContext.create();
private final Sinks.Many<String> sink = Sinks.many().multicast().onBackpressureBuffer();
@Getter
private boolean authenticated = false;
@Getter
private String loggedUser = "";
@Getter
private final PublishProcessor<String> loggedInUser = PublishProcessor.create();
@Autowired
public VGAuthService(ConnectionService cm, SettingsService settingsService, ThreadPoolService threadPoolService, DataService dataService) {
public VGAuthService(ConnectionService cm, SettingsService settingsService, ThreadPoolService threadPoolService) {
this.cm = cm;
this.settingsService = settingsService;
this.threadPoolService = threadPoolService;
this.dataService = dataService;
disposable = settingsService.getSettingsFlux().subscribe(settings -> this.authenticate());
}
@PostConstruct
private void init() {
context.setCookieStore(new BasicCookieStore());
try {
authenticate();
} catch (VripperException e) {
log.error("Cannot authenticate user with ViperGirls", e);
}
authenticate();
}
public void authenticate() throws VripperException {
@PreDestroy
private void destroy() {
sink.emitComplete(EmitHandler.RETRY);
disposable.dispose();
}
public Flux<String> getLoggedInUser() {
return sink.asFlux();
}
public void authenticate() {
log.info("Authenticating using ViperGirls credentials");
authenticated = false;
@@ -70,7 +78,7 @@ public class VGAuthService {
log.debug("Authentication option is disabled");
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
sink.emitNext(loggedUser, EmitHandler.RETRY);
return;
}
@@ -81,11 +89,11 @@ public class VGAuthService {
log.error("Cannot authenticate with ViperGirls credentials, username or password is empty");
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
sink.emitNext(loggedUser, EmitHandler.RETRY);
return;
}
HttpPost postAuth = cm.buildHttpPost("https://vipergirls.to/login.php?do=login", null);
HttpPost postAuth = cm.buildHttpPost(settingsService.getSettings().getVProxy() + "/login.php?do=login", null);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("vb_login_username", username));
@@ -97,12 +105,13 @@ public class VGAuthService {
} catch (Exception e) {
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
throw new VripperException(e);
sink.emitNext(loggedUser, EmitHandler.RETRY);
log.error("Failed to authenticate user with " + settingsService.getSettings().getVProxy(), e);
return;
}
postAuth.addHeader("Referer", "https://vipergirls.to/");
postAuth.addHeader("Host", "vipergirls.to");
postAuth.addHeader("Referer", settingsService.getSettings().getVProxy());
postAuth.addHeader("Host", settingsService.getSettings().getVProxy().replace("https://", "").replace("http://", ""));
CloseableHttpClient client = cm.getClient().build();
@@ -115,81 +124,23 @@ public class VGAuthService {
log.debug(String.format("Authentication with ViperGirls response body:%n%s", responseBody));
EntityUtils.consumeQuietly(response.getEntity());
if (context.getCookieStore().getCookies().stream().map(Cookie::getName).noneMatch(e -> e.equals("vg_userid"))) {
throw new VripperException("Failed to authenticate user with ViperRipper");
log.error(String.format("Failed to authenticate user with %s, missing vg_userid cookie", settingsService.getSettings().getVProxy()));
return;
}
} catch (Exception e) {
context.getCookieStore().clear();
loggedUser = "";
loggedInUser.onNext(loggedUser);
if (e instanceof VripperException) {
throw (VripperException) e;
} else {
throw new VripperException(e);
}
sink.emitNext(loggedUser, EmitHandler.RETRY);
log.error("Failed to authenticate user with " + settingsService.getSettings().getVProxy(), e);
return;
}
authenticated = true;
loggedUser = username;
log.info(String.format("Authenticated: %s", username));
loggedInUser.onNext(loggedUser);
sink.emitNext(loggedUser, EmitHandler.RETRY);
}
public void leaveThanks(Post post) {
if (!settingsService.getSettings().getVLogin()) {
log.debug("Authentication with ViperGirls option is disabled");
return;
}
if (!settingsService.getSettings().getVThanks()) {
log.debug("Leave thanks option is disabled");
return;
}
if (!authenticated) {
log.error("You are not authenticated");
return;
}
if (post.isThanked()) {
log.debug("Already left a thanks");
return;
}
threadPoolService.getGeneralExecutor().submit(() -> {
try {
postThanks(post);
} catch (Exception e) {
log.error(String.format("Failed to leave a thanks for url %s, post id %s", post.getUrl(), post.getPostId()), e);
}
});
}
private void postThanks(Post post) throws VripperException {
HttpPost postThanks = cm.buildHttpPost("https://vipergirls.to/post_thanks.php", null);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("do", "post_thanks_add"));
params.add(new BasicNameValuePair("using_ajax", "1"));
params.add(new BasicNameValuePair("p", post.getPostId()));
params.add(new BasicNameValuePair("securitytoken", post.getSecurityToken()));
try {
postThanks.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new VripperException(e);
}
postThanks.addHeader("Referer", "https://vipergirls.to/");
postThanks.addHeader("Host", "vipergirls.to");
CloseableHttpClient client = cm.getClient().build();
try (CloseableHttpResponse response = client.execute(postThanks, context)) {
if (response.getStatusLine().getStatusCode() / 100 == 2) {
post.setThanked(true);
dataService.updatePostThanked(post.isThanked(), post.getId());
}
EntityUtils.consumeQuietly(response.getEntity());
} catch (Exception e) {
throw new VripperException(e);
}
if (!post.isThanked()) {
throw new VripperException("Failed to leave");
}
threadPoolService.getGeneralExecutor().submit(new LeaveThanksRunnable(post, authenticated, context));
}
}
@@ -12,7 +12,7 @@ import javax.xml.xpath.XPathFactory;
@Service
public class XpathService {
private XPath xpath = XPathFactory.newInstance().newXPath();
private final XPath xpath = XPathFactory.newInstance().newXPath();
public Node getAsNode(Node source, String xpathExpression) throws XpathException {
try {
@@ -1,45 +0,0 @@
package tn.mnlr.vripper.services.domain;
import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.FailsafeException;
import org.apache.http.impl.execchain.RequestAbortedException;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.jpa.domain.Metadata;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.MetadataService;
@Slf4j
public class MetadataRunnable implements Runnable {
@Getter
private final Post post;
private final MetadataService metadataService;
private final DataService dataService;
public MetadataRunnable(@NonNull Post post) {
this.post = post;
this.metadataService = SpringContext.getBean(MetadataService.class);
this.dataService = SpringContext.getBean(DataService.class);
}
@Override
public void run() {
try {
if(Thread.interrupted()) {
log.debug(String.format("Metadata fetching for postId=%s, threadId=%s interrupted", post.getPostId(), post.getThreadId()));
return;
}
Metadata metadata = metadataService.get(post);
dataService.setMetadata(post, metadata);
} catch (Exception e) {
if (e.getCause() instanceof InterruptedException || (e.getCause() instanceof FailsafeException && (e.getCause().getCause() instanceof InterruptedException || e.getCause().getCause() instanceof RequestAbortedException))) {
return;
}
log.error(String.format("Failed to get metadata for postId %s", post.getPostId()), e);
}
}
}
@@ -0,0 +1,98 @@
package tn.mnlr.vripper.services.domain;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.services.SettingsService;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class MultiPostScanHandler extends DefaultHandler {
private final Queued queued;
private final Collection<Host> supportedHosts;
private final SettingsService settingsService;
private final Map<Host, AtomicInteger> hostMap = new HashMap<>();
private final List<MultiPostItem> posts = new ArrayList<>();
private String error;
private List<String> previews = new ArrayList<>();
private String threadTitle;
private String postId;
private String postTitle;
private int imageCount;
private int postCounter;
private int previewCounter = 0;
public MultiPostScanHandler(Queued queued) {
this.queued = queued;
supportedHosts = SpringContext.getBeansOfType(Host.class).values();
settingsService = SpringContext.getBean(SettingsService.class);
}
public MultiPostScanResult getScanResult() {
return new MultiPostScanResult(posts, error);
}
@Override
public void startDocument() {
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
switch (qName.toLowerCase()) {
case "error":
error = attributes.getValue("details");
break;
case "thread":
threadTitle = attributes.getValue("title").trim();
break;
case "post":
imageCount = Integer.parseInt(attributes.getValue("imagecount").trim());
postId = attributes.getValue("id").trim();
postCounter = Integer.parseInt(attributes.getValue("number").trim());
postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
break;
case "image":
Optional.ofNullable(attributes.getValue("main_url"))
.map(String::trim)
.flatMap(mainUrl -> supportedHosts.stream().filter(host -> host.isSupported(mainUrl)).findFirst())
.ifPresent(host -> Optional.ofNullable(hostMap.get(host)).ifPresentOrElse(AtomicInteger::incrementAndGet, () -> hostMap.put(host, new AtomicInteger(1))));
if (previewCounter++ < 4) {
Optional.ofNullable(attributes.getValue("thumb_url")).map(String::trim).ifPresent(previews::add);
}
break;
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if ("post".equalsIgnoreCase(qName)) {
if (imageCount != 0) {
posts.add(new MultiPostItem(
queued.getThreadId(),
postId,
postCounter,
postTitle,
imageCount,
String.format("%s/threads/?p=%s&viewfull=1#post%s", settingsService.getSettings().getVProxy(), postId, postId),
previews,
hostMap.entrySet().stream().filter(v -> v.getValue().get() > 0).map(e -> e.getKey().getHost() + " (" + e.getValue().get() + ")").collect(Collectors.joining(", "))
));
queued.increment();
}
previewCounter = 0;
previews = new ArrayList<>();
hostMap.clear();
}
}
@Override
public void endDocument() {
queued.done();
}
}
@@ -0,0 +1,80 @@
package tn.mnlr.vripper.services.domain;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.services.ConnectionService;
import tn.mnlr.vripper.services.SettingsService;
import tn.mnlr.vripper.services.VGAuthService;
import javax.xml.parsers.SAXParserFactory;
import java.io.BufferedInputStream;
import java.net.URISyntaxException;
import java.util.concurrent.atomic.AtomicReference;
@Slf4j
public class MultiPostScanParser {
private static final SAXParserFactory factory = SAXParserFactory.newInstance();
private final Queued queued;
private final ConnectionService cm;
private final VGAuthService VGAuthService;
private final SettingsService settingsService;
public MultiPostScanParser(Queued queued) {
this.queued = queued;
cm = SpringContext.getBean(ConnectionService.class);
VGAuthService = SpringContext.getBean(VGAuthService.class);
settingsService = SpringContext.getBean(SettingsService.class);
}
public MultiPostScanResult parse() throws PostParseException {
log.debug(String.format("Parsing thread %s", queued));
HttpGet httpGet;
try {
URIBuilder uriBuilder = new URIBuilder(settingsService.getSettings().getVProxy() + "/vr.php");
uriBuilder.setParameter("t", queued.getThreadId());
httpGet = cm.buildHttpGet(uriBuilder.build(), null);
} catch (URISyntaxException e) {
throw new PostParseException(e);
}
MultiPostScanHandler multiPostScanHandler = new MultiPostScanHandler(queued);
AtomicReference<Throwable> thr = new AtomicReference<>();
log.debug(String.format("Requesting %s", httpGet));
MultiPostScanResult multiPostScanResult = Failsafe.with(cm.getRetryPolicy())
.onFailure(e -> thr.set(e.getFailure()))
.get(() -> {
HttpClient connection = cm.getClient().build();
try (CloseableHttpResponse response = (CloseableHttpResponse) connection.execute(httpGet, VGAuthService.getContext())) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
}
try {
// System.out.println(EntityUtils.toString(response.getEntity()));
factory.newSAXParser().parse(new BufferedInputStream(response.getEntity().getContent()), multiPostScanHandler);
return multiPostScanHandler.getScanResult();
} catch (Exception e) {
throw new PostParseException(String.format("Failed to parse thread %s", queued), e);
} finally {
EntityUtils.consumeQuietly(response.getEntity());
}
}
});
if (thr.get() != null) {
log.error(String.format("parsing failed for thread %s", queued), thr.get());
throw new PostParseException(thr.get());
}
return multiPostScanResult;
}
}
@@ -0,0 +1,16 @@
package tn.mnlr.vripper.services.domain;
import lombok.Getter;
import java.util.List;
@Getter
public class MultiPostScanResult {
private final List<MultiPostItem> posts;
private final String error;
public MultiPostScanResult(List<MultiPostItem> posts, String error) {
this.posts = posts;
this.error = error;
}
}
@@ -7,7 +7,7 @@ import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.host.Host;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.services.domain.ApiPost;
import tn.mnlr.vripper.services.SettingsService;
import java.util.Collection;
import java.util.HashSet;
@@ -16,7 +16,7 @@ import java.util.Set;
import java.util.stream.Collectors;
@Slf4j
class ApiPostHandler extends DefaultHandler {
class PostScanHandler extends DefaultHandler {
private final Collection<Host> supportedHosts;
@@ -26,23 +26,23 @@ class ApiPostHandler extends DefaultHandler {
private final Set<Image> images = new HashSet<>();
private Set<String> previews = new HashSet<>();
private String threadTitle;
private String postTitle;
private String forum;
private String userHash;
private int index = 0;
private Post parsedPost;
ApiPostHandler(String threadId, String postId) {
PostScanHandler(String threadId, String postId) {
this.threadId = threadId;
this.postId = postId;
this.postUrl = String.format("https://vipergirls.to/threads/%s/?p=%s&viewfull=1#post%s", this.threadId, this.postId, this.postId);
this.supportedHosts = SpringContext.getBeansOfType(Host.class).values();
supportedHosts = SpringContext.getBeansOfType(Host.class).values();
SettingsService settingsService = SpringContext.getBean(SettingsService.class);
postUrl = String.format("%s/threads/%s/?p=%s&viewfull=1#post%s", settingsService.getSettings().getVProxy(), this.threadId, this.postId, this.postId);
}
public ApiPost getParsedPost() {
return new ApiPost(parsedPost, images);
public PostScanResult getParsedPost() {
return new PostScanResult(parsedPost, images);
}
@Override
@@ -63,7 +63,7 @@ class ApiPostHandler extends DefaultHandler {
threadTitle = attributes.getValue("title").trim();
break;
case "post":
postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
String postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
parsedPost = new Post(
postTitle,
postUrl,
@@ -96,7 +96,7 @@ class ApiPostHandler extends DefaultHandler {
@Override
public void endElement(String uri, String localName, String qName) {
if ("post".equals(qName.toLowerCase())) {
if ("post".equalsIgnoreCase(qName)) {
parsedPost.setTotal(images.size());
if (!previews.isEmpty()) {
parsedPost.setPreviews(previews);
@@ -8,10 +8,10 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.services.ConnectionService;
import tn.mnlr.vripper.services.SettingsService;
import tn.mnlr.vripper.services.VGAuthService;
import javax.xml.parsers.SAXParserFactory;
@@ -19,9 +19,7 @@ import java.net.URISyntaxException;
import java.util.concurrent.atomic.AtomicReference;
@Slf4j
public class ApiPostParser {
private static final String VR_API = "https://vipergirls.to/vr.php";
public class PostScanParser {
private static final SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -29,20 +27,22 @@ public class ApiPostParser {
private final String postId;
private final ConnectionService cm;
private final VGAuthService VGAuthService;
private final SettingsService settingsService;
public ApiPostParser(String threadId, String postId) {
public PostScanParser(String threadId, String postId) {
this.threadId = threadId;
this.postId = postId;
this.cm = SpringContext.getBean(ConnectionService.class);
this.VGAuthService = SpringContext.getBean(VGAuthService.class);
cm = SpringContext.getBean(ConnectionService.class);
VGAuthService = SpringContext.getBean(VGAuthService.class);
settingsService = SpringContext.getBean(SettingsService.class);
}
public ApiPost parse() throws PostParseException {
public PostScanResult parse() throws PostParseException {
log.debug(String.format("Parsing post %s", postId));
HttpGet httpGet;
try {
URIBuilder uriBuilder = new URIBuilder(VR_API);
URIBuilder uriBuilder = new URIBuilder(settingsService.getSettings().getVProxy() + "/vr.php");
uriBuilder.setParameter("p", postId);
httpGet = cm.buildHttpGet(uriBuilder.build(), null);
} catch (URISyntaxException e) {
@@ -50,9 +50,9 @@ public class ApiPostParser {
}
AtomicReference<Throwable> thr = new AtomicReference<>();
ApiPostHandler apiPostHandler = new ApiPostHandler(threadId, postId);
PostScanHandler postScanHandler = new PostScanHandler(threadId, postId);
log.debug(String.format("Requesting %s", httpGet));
ApiPost post = getPost(httpGet, apiPostHandler, thr);
PostScanResult post = getPost(httpGet, postScanHandler, thr);
if (thr.get() != null) {
log.error(String.format("parsing failed for thread %s, post %s", threadId, postId), thr.get());
throw new PostParseException(thr.get());
@@ -60,8 +60,8 @@ public class ApiPostParser {
return post;
}
private ApiPost getPost(HttpGet httpGet, ApiPostHandler apiPostHandler, AtomicReference<Throwable> thr) {
return Failsafe.with(VripperApplication.retryPolicy)
private PostScanResult getPost(HttpGet httpGet, PostScanHandler postScanHandler, AtomicReference<Throwable> thr) {
return Failsafe.with(cm.getRetryPolicy())
.onFailure(e -> thr.set(e.getFailure()))
.get(() -> {
HttpClient connection = cm.getClient().build();
@@ -70,9 +70,9 @@ public class ApiPostParser {
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
}
factory.newSAXParser().parse(response.getEntity().getContent(), apiPostHandler);
factory.newSAXParser().parse(response.getEntity().getContent(), postScanHandler);
EntityUtils.consumeQuietly(response.getEntity());
return apiPostHandler.getParsedPost();
return postScanHandler.getParsedPost();
}
});
}
@@ -7,14 +7,14 @@ import tn.mnlr.vripper.jpa.domain.Post;
import java.util.Optional;
import java.util.Set;
public class ApiPost {
public class PostScanResult {
private final Post post;
@Getter
private final Set<Image> images;
public ApiPost(Post post, Set<Image> images) {
public PostScanResult(Post post, Set<Image> images) {
this.post = post;
this.images = images;
}
@@ -0,0 +1,135 @@
package tn.mnlr.vripper.services.domain.tasks;
import lombok.extern.slf4j.Slf4j;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.Utils;
import tn.mnlr.vripper.download.PendingQueue;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.MetadataService;
import tn.mnlr.vripper.services.SettingsService;
import tn.mnlr.vripper.services.VGAuthService;
import tn.mnlr.vripper.services.domain.PostScanParser;
import tn.mnlr.vripper.services.domain.PostScanResult;
import java.time.LocalDateTime;
import java.util.Set;
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
import static tn.mnlr.vripper.jpa.domain.Event.Status.PROCESSING;
@Slf4j
public class AddPostRunnable implements Runnable {
private final String postId;
private final String threadId;
private final DataService dataService;
private final MetadataService metadataService;
private final SettingsService settingsService;
private final PendingQueue pendingQueue;
private final VGAuthService VGAuthService;
private final Event event;
private final IEventRepository eventRepository;
private final String link;
public AddPostRunnable(String postId, String threadId) {
this.postId = postId;
this.threadId = threadId;
this.dataService = SpringContext.getBean(DataService.class);
this.metadataService = SpringContext.getBean(MetadataService.class);
this.settingsService = SpringContext.getBean(SettingsService.class);
this.pendingQueue = SpringContext.getBean(PendingQueue.class);
this.VGAuthService = SpringContext.getBean(VGAuthService.class);
this.eventRepository = SpringContext.getBean(IEventRepository.class);
link = settingsService.getSettings().getVProxy() + String.format("/threads/%s?%s", threadId, (postId != null ? "p=" + postId : ""));
event = new Event(Event.Type.POST, Event.Status.PENDING, LocalDateTime.now(), String.format("Processing %s", link));
eventRepository.save(event);
}
@Override
public void run() {
try {
event.setStatus(PROCESSING);
eventRepository.update(event);
if (dataService.exists(postId)) {
log.warn(String.format("skipping %s, already loaded", postId));
event.setMessage(String.format("Gallery %s is already loaded", link));
event.setStatus(ERROR);
eventRepository.update(event);
return;
}
PostScanParser postScanParser = new PostScanParser(threadId, postId);
PostScanResult postScanResult;
try {
postScanResult = postScanParser.parse();
} catch (PostParseException e) {
String error = String.format("parsing failed for gallery %s", link);
log.error(error, e);
event.setMessage(error + "\n" + Utils.throwableToString(e));
event.setStatus(ERROR);
eventRepository.update(event);
return;
}
if (postScanResult.getPost().isEmpty()) {
String error = String.format("Gallery %s contains no galleries", link);
log.error(error);
event.setMessage(error);
event.setStatus(ERROR);
eventRepository.update(event);
return;
}
if (postScanResult.getImages().isEmpty()) {
String error = String.format("Gallery %s contains no images to download", link);
log.error(error);
event.setMessage(error);
event.setStatus(ERROR);
eventRepository.update(event);
return;
}
Post post = postScanResult.getPost().get();
Set<Image> images = postScanResult.getImages();
dataService.newPost(post, images);
metadataService.startFetchingMetadata(post);
if (settingsService.getSettings().getAutoStart()) {
log.debug("Auto start downloads option is enabled");
post.setStatus(Status.PENDING);
try {
pendingQueue.enqueue(post, images);
} catch (InterruptedException e) {
log.warn("Interruption was caught");
Thread.currentThread().interrupt();
return;
}
log.debug(String.format("Done enqueuing jobs for %s", post.getUrl()));
} else {
post.setStatus(Status.STOPPED);
log.debug("Auto start downloads option is disabled");
}
if (!settingsService.getSettings().getLeaveThanksOnStart()) {
VGAuthService.leaveThanks(post);
}
dataService.updatePostStatus(post.getStatus(), post.getId());
event.setMessage(String.format("Gallery %s is successfully added to download queue", link));
event.setStatus(Event.Status.DONE);
eventRepository.update(event);
} catch (Exception e) {
String error = String.format("Error when adding gallery %s", link);
log.error(error, e);
event.setMessage(error + "\n" + Utils.throwableToString(e));
event.setStatus(ERROR);
eventRepository.update(event);
}
}
}
@@ -0,0 +1,90 @@
package tn.mnlr.vripper.services.domain.tasks;
import lombok.extern.slf4j.Slf4j;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.Utils;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.PostService;
import tn.mnlr.vripper.services.ThreadPoolService;
import tn.mnlr.vripper.services.domain.MultiPostScanResult;
import java.time.LocalDateTime;
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
import static tn.mnlr.vripper.jpa.domain.Event.Status.PROCESSING;
@Slf4j
public class AddQueuedRunnable implements Runnable {
private final Queued queued;
private final ThreadPoolService threadPoolService;
private final DataService dataService;
private final IEventRepository eventRepository;
private final PostService postService;
private final Event event;
public AddQueuedRunnable(Queued queued) {
this.queued = queued;
threadPoolService = SpringContext.getBean(ThreadPoolService.class);
dataService = SpringContext.getBean(DataService.class);
eventRepository = SpringContext.getBean(IEventRepository.class);
postService = SpringContext.getBean(PostService.class);
event = new Event(Event.Type.QUEUED, Event.Status.PENDING, LocalDateTime.now(), String.format("Processing multi-post link %s", queued.getLink()));
eventRepository.save(event);
}
@Override
public void run() {
try {
event.setStatus(PROCESSING);
eventRepository.update(event);
MultiPostScanResult multiPostScanResult = postService.get(queued);
if (multiPostScanResult == null) {
String message = String.format("Fetching multi-post link %s failed", queued.getLink());
event.setStatus(ERROR);
event.setMessage(message);
eventRepository.update(event);
return;
} else if (multiPostScanResult.getError() != null) {
String message = "Nothing found for " + queued.getLink() + "\n" + multiPostScanResult.getError();
event.setStatus(ERROR);
event.setMessage(message);
eventRepository.update(event);
return;
} else if (multiPostScanResult.getPosts().isEmpty()) {
String message = "Nothing found for " + queued.getLink();
event.setStatus(ERROR);
event.setMessage(message);
eventRepository.update(event);
return;
}
queued.setTotal(multiPostScanResult.getPosts().size());
queued.done();
if (multiPostScanResult.getPosts().size() == 1) {
threadPoolService.getGeneralExecutor().submit(new AddPostRunnable(multiPostScanResult.getPosts().get(0).getPostId(), multiPostScanResult.getPosts().get(0).getThreadId()));
event.setStatus(Event.Status.DONE);
event.setMessage(String.format("Link %s is added to download queue", queued.getLink()));
} else {
if (dataService.findQueuedByThreadId(queued.getThreadId()).isEmpty()) {
dataService.newQueueLink(queued);
event.setStatus(Event.Status.DONE);
event.setMessage(String.format("Link %s is added to multi-post links", queued.getLink()));
} else {
log.info(String.format("Link %s is already loaded", queued.getLink()));
event.setStatus(Event.Status.ERROR);
event.setMessage(String.format("%s has already been added to multi-post links", queued.getLink()));
}
}
eventRepository.update(event);
} catch (Exception e) {
String error = String.format("Error when adding multi-post link %s", queued.getLink());
log.error(error, e);
event.setMessage(error + "\n" + Utils.throwableToString(e));
event.setStatus(ERROR);
eventRepository.update(event);
}
}
}
@@ -0,0 +1,119 @@
package tn.mnlr.vripper.services.domain.tasks;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.Utils;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
import tn.mnlr.vripper.services.ConnectionService;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.SettingsService;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class LeaveThanksRunnable implements Runnable {
private final ConnectionService cm;
private final DataService dataService;
private final HttpClientContext context;
private final SettingsService settingsService;
private final IEventRepository eventRepository;
private final boolean authenticated;
private final Post post;
private final Event event;
public LeaveThanksRunnable(Post post, boolean authenticated, HttpClientContext context) {
this.post = post;
this.authenticated = authenticated;
this.context = context;
cm = SpringContext.getBean(ConnectionService.class);
dataService = SpringContext.getBean(DataService.class);
eventRepository = SpringContext.getBean(IEventRepository.class);
settingsService = SpringContext.getBean(SettingsService.class);
event = new Event(Event.Type.THANKS, Event.Status.PENDING, LocalDateTime.now(), String.format("Leaving thanks for %s", post.getUrl()));
eventRepository.save(event);
}
@Override
public void run() {
try {
event.setStatus(Event.Status.PROCESSING);
eventRepository.update(event);
if (!settingsService.getSettings().getVLogin()) {
event.setMessage(String.format("Will not send a like for %s\nAuthentication with ViperGirls option is disabled", post.getUrl()));
event.setStatus(Event.Status.DONE);
eventRepository.update(event);
return;
}
if (!settingsService.getSettings().getVThanks()) {
event.setMessage(String.format("Will not send a like for %s\nLeave thanks option is disabled", post.getUrl()));
event.setStatus(Event.Status.DONE);
eventRepository.update(event);
return;
}
if (!authenticated) {
event.setMessage(String.format("Will not send a like for %s\nYou are not authenticated", post.getUrl()));
event.setStatus(Event.Status.ERROR);
eventRepository.update(event);
return;
}
if (post.isThanked()) {
event.setMessage(String.format("Will not send a like for %s\nAlready left a thanks", post.getUrl()));
event.setStatus(Event.Status.DONE);
eventRepository.update(event);
return;
}
HttpPost postThanks = cm.buildHttpPost(settingsService.getSettings().getVProxy() + "/post_thanks.php", null);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("do", "post_thanks_add"));
params.add(new BasicNameValuePair("using_ajax", "1"));
params.add(new BasicNameValuePair("p", post.getPostId()));
params.add(new BasicNameValuePair("securitytoken", post.getSecurityToken()));
try {
postThanks.setEntity(new UrlEncodedFormEntity(params));
} catch (UnsupportedEncodingException e) {
String error = String.format("Request error for %s", post.getUrl());
log.error(error, e);
event.setMessage(error + "\n" + Utils.throwableToString(e));
event.setStatus(Event.Status.ERROR);
eventRepository.update(event);
return;
}
postThanks.addHeader("Referer", settingsService.getSettings().getVProxy());
postThanks.addHeader("Host", settingsService.getSettings().getVProxy().replace("https://", "").replace("http://", ""));
CloseableHttpClient client = cm.getClient().build();
try (CloseableHttpResponse response = client.execute(postThanks, context)) {
if (response.getStatusLine().getStatusCode() / 100 == 2) {
post.setThanked(true);
dataService.updatePostThanked(post.isThanked(), post.getId());
}
EntityUtils.consumeQuietly(response.getEntity());
}
event.setStatus(Event.Status.DONE);
eventRepository.update(event);
} catch (Exception e) {
String error = String.format("Failed to leave a thanks for %s", post.getUrl());
log.error(error, e);
event.setMessage(error + "\n" + Utils.throwableToString(e));
event.setStatus(Event.Status.ERROR);
eventRepository.update(event);
}
}
}
@@ -0,0 +1,95 @@
package tn.mnlr.vripper.services.domain.tasks;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.Utils;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.jpa.repositories.impl.EventRepository;
import tn.mnlr.vripper.services.PostService;
import tn.mnlr.vripper.services.SettingsService;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
@Slf4j
public class LinkScanRunnable implements Runnable {
private final static Object LOCK = new Object();
private final List<String> urlList;
private final SettingsService settingsService;
private final PostService postService;
private final EventRepository eventRepository;
private final Event event;
public LinkScanRunnable(@NonNull List<String> urlList) {
this.urlList = urlList;
settingsService = SpringContext.getBean(SettingsService.class);
postService = SpringContext.getBean(PostService.class);
eventRepository = SpringContext.getBean(EventRepository.class);
event = new Event(Event.Type.SCAN, Event.Status.PENDING, LocalDateTime.now(), "Links to scan:\n\t" + String.join("\n\t", urlList));
eventRepository.save(event);
}
@Override
public void run() {
synchronized (LOCK) {
try {
event.setStatus(Event.Status.PROCESSING);
eventRepository.update(event);
ArrayList<Queued> queuedList = new ArrayList<>();
List<String> unsupported = new ArrayList<>();
List<String> unrecognized = new ArrayList<>();
for (String url : urlList) {
log.debug(String.format("Starting to process thread: %s", url));
if (!url.startsWith(settingsService.getSettings().getVProxy())) {
log.error(String.format("Unsupported link %s", url));
unsupported.add(url);
continue;
}
String threadId, postId;
Matcher m = Pattern.compile(Pattern.quote(settingsService.getSettings().getVProxy()) + "/threads/(\\d+)((.*p=)(\\d+))?").matcher(url);
if (m.find()) {
threadId = m.group(1);
postId = m.group(4);
} else {
log.error(String.format("Cannot retrieve thread id from URL %s", url));
unrecognized.add(url);
continue;
}
queuedList.add(new Queued(url, threadId, postId));
}
StringBuilder errorMessage = new StringBuilder();
if (!unsupported.isEmpty()) {
errorMessage.append("Unsupported links:\n\t").append(String.join("\n\t", unsupported)).append("\n\n");
}
if (!unrecognized.isEmpty()) {
errorMessage.append("Unrecognized links:\n\t").append(String.join("\n\t", unrecognized)).append("\n\n");
}
postService.processMultiPost(queuedList);
if (!unsupported.isEmpty() || !unrecognized.isEmpty()) {
event.setStatus(Event.Status.ERROR);
event.setMessage("Some links failed to be scanned: \n" + errorMessage.toString());
} else {
event.setStatus(Event.Status.DONE);
}
eventRepository.update(event);
} catch (Exception e) {
String error = "Error when scanning links";
log.error(error, e);
event.setMessage(error + "\n" + Utils.throwableToString(e));
event.setStatus(ERROR);
eventRepository.update(event);
}
}
}
}
@@ -0,0 +1,78 @@
package tn.mnlr.vripper.services.domain.tasks;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.Utils;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.Metadata;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.MetadataService;
import java.time.LocalDateTime;
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
@Slf4j
public class MetadataRunnable implements Runnable {
@Getter
private final Post post;
private final MetadataService metadataService;
private final DataService dataService;
private final IEventRepository eventRepository;
private final Event event;
@Setter
private volatile boolean interrupted = false;
public MetadataRunnable(@NonNull Post post) {
this.post = post;
metadataService = SpringContext.getBean(MetadataService.class);
dataService = SpringContext.getBean(DataService.class);
eventRepository = SpringContext.getBean(IEventRepository.class);
event = new Event(Event.Type.METADATA, Event.Status.PENDING, LocalDateTime.now(), "Fetching metadata for " + post.getUrl());
eventRepository.save(event);
}
@Override
public void run() {
try {
event.setStatus(Event.Status.PROCESSING);
eventRepository.update(event);
if (interrupted) {
String message = String.format("Fetching metadata for %s interrupted", post.getUrl());
event.setStatus(Event.Status.DONE);
event.setMessage(message);
eventRepository.update(event);
return;
}
Metadata metadata = metadataService.get(post);
if (metadata == null) {
String message = String.format("Fetching metadata for %s failed", post.getUrl());
event.setStatus(ERROR);
event.setMessage(message);
eventRepository.update(event);
return;
}
dataService.setMetadata(post, metadata);
event.setStatus(Event.Status.DONE);
eventRepository.update(event);
} catch (Exception e) {
String message = String.format("Failed to fetch metadata for %s", post.getUrl());
log.error(message, e);
event.setMessage(message + "\n" + Utils.throwableToString(e));
event.setStatus(ERROR);
eventRepository.update(event);
}
}
}
@@ -0,0 +1,27 @@
package tn.mnlr.vripper.web.restendpoints;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
@Slf4j
@RestController
@CrossOrigin(value = "*")
public class EventLogRestEndpoint {
private final IEventRepository eventRepository;
public EventLogRestEndpoint(IEventRepository eventRepository) {
this.eventRepository = eventRepository;
}
@GetMapping("/events/clear")
@ResponseStatus(value = HttpStatus.OK)
public void clear() {
eventRepository.deleteAll();
}
}
@@ -6,17 +6,18 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import tn.mnlr.vripper.download.DownloadService;
import tn.mnlr.vripper.exception.PostParseException;
import tn.mnlr.vripper.jpa.domain.Metadata;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.services.ThreadPoolService;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.PathService;
import tn.mnlr.vripper.services.domain.MultiPostItem;
import tn.mnlr.vripper.services.PostService;
import tn.mnlr.vripper.services.ThreadPoolService;
import tn.mnlr.vripper.services.domain.MultiPostItem;
import tn.mnlr.vripper.services.domain.MultiPostScanResult;
import tn.mnlr.vripper.services.domain.tasks.AddPostRunnable;
import tn.mnlr.vripper.services.domain.tasks.LinkScanRunnable;
import tn.mnlr.vripper.web.restendpoints.domain.*;
import tn.mnlr.vripper.web.restendpoints.domain.PostId;
import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
import tn.mnlr.vripper.web.restendpoints.exceptions.NotFoundException;
import tn.mnlr.vripper.web.restendpoints.exceptions.ServerErrorException;
@@ -25,9 +26,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Slf4j
@@ -35,16 +33,13 @@ import java.util.stream.Collectors;
@CrossOrigin(value = "*")
public class PostRestEndpoint {
private static final Pattern VG_URL_PATTERN = Pattern.compile("https://vipergirls\\.to/threads/(\\d+)((.*p=)(\\d+))?");
private static final Object LOCK = new Object();
private final DataService dataService;
private final PathService pathService;
private final DownloadService downloadService;
private final PostService postService;
private final ThreadPoolService threadPoolService;
private static final Object LOCK = new Object();
@Autowired
public PostRestEndpoint(DataService dataService, PathService pathService, DownloadService downloadService, PostService postService, ThreadPoolService threadPoolService) {
this.dataService = dataService;
@@ -63,30 +58,7 @@ public class PostRestEndpoint {
throw new BadRequestException("Cannot process empty requests");
}
List<String> urlList = Arrays.stream(_url.getUrl().split("\\r?\\n")).map(String::trim).filter(e -> !e.isEmpty()).collect(Collectors.toList());
ArrayList<Queued> queuedList = new ArrayList<>();
for (String url : urlList) {
log.debug(String.format("Starting to process thread: %s", url));
if (!url.startsWith("https://vipergirls.to")) {
log.error(String.format("Unsupported link %s", url));
continue;
}
String threadId, postId;
Matcher m = VG_URL_PATTERN.matcher(url);
if (m.find()) {
threadId = m.group(1);
postId = m.group(4);
} else {
throw new BadRequestException(String.format("Cannot retrieve thread id from URL %s", url));
}
queuedList.add(new Queued(url, threadId, postId));
}
try {
postService.processMultiPost(queuedList);
} catch (Exception e) {
log.error("Failed to parse links", e);
throw new ServerErrorException(e.getMessage());
}
threadPoolService.getGeneralExecutor().submit(new LinkScanRunnable(urlList));
}
}
@@ -103,14 +75,7 @@ public class PostRestEndpoint {
public void addPost(@RequestBody List<PostToAdd> posts) {
synchronized (LOCK) {
for (PostToAdd post : posts) {
threadPoolService.getGeneralExecutor().submit(() -> {
try {
postService.addPost(post.getPostId(), post.getThreadId());
} catch (PostParseException e) {
log.error(String.format("Failed to add post %s", post.getPostId()), e);
throw new ServerErrorException(String.format("Failed to add post %s", post.getPostId()));
}
});
threadPoolService.getGeneralExecutor().submit(new AddPostRunnable(post.getPostId(), post.getThreadId()));
}
}
}
@@ -127,11 +92,11 @@ public class PostRestEndpoint {
Optional<Post> _post = dataService.findPostByPostId(postId);
if (_post.isPresent()) {
Post post = _post.get();
if (post.getPostFolderName() == null) {
if (post.getDownloadDirectory() == null) {
log.error("Download has not been started yet for this post");
throw new NotFoundException("Download has not been started yet for this post");
} else {
return new DownloadPath(pathService.getDownloadDestinationFolder(post).getPath());
return new DownloadPath(pathService.calcDownloadDirectory(post).getPath());
}
} else {
log.error(String.format("Unable to find post with postId = %s", postId));
@@ -185,12 +150,14 @@ public class PostRestEndpoint {
}
private void renamePosts(@RequestBody @NonNull List<AltPostName> postToRename) {
for (AltPostName altPostName : postToRename) {
try {
pathService.rename(altPostName.getPostId(), altPostName.getAltName());
} catch (Exception e) {
log.error(String.format("Failed to rename post with postId = %s", altPostName.getPostId()), e);
throw new ServerErrorException(e.getMessage());
synchronized (LOCK) {
for (AltPostName altPostName : postToRename) {
try {
pathService.rename(altPostName.getPostId(), altPostName.getAltName());
} catch (Exception e) {
log.error(String.format("Failed to rename post with postId = %s", altPostName.getPostId()), e);
throw new ServerErrorException(e.getMessage());
}
}
}
}
@@ -238,19 +205,36 @@ public class PostRestEndpoint {
@GetMapping("/grab/{threadId}")
@ResponseStatus(value = HttpStatus.OK)
public List<MultiPostItem> grab(@PathVariable("threadId") @NonNull String threadId) {
Queued queued = dataService.findQueuedByThreadId(threadId).orElseThrow(() -> new NotFoundException(String.format("Unable to find links for threadId = %s", threadId)));
try {
return postService.getCache().get(queued);
} catch (ExecutionException e) {
log.error(String.format("Failed to get links for threadId = %s", threadId), e);
throw new ServerErrorException(String.format("Failed to get links for threadId = %s", threadId));
synchronized (LOCK) {
try {
Queued queued = dataService.findQueuedByThreadId(threadId).orElseThrow(() -> new NotFoundException(String.format("Unable to find links for threadId = %s", threadId)));
MultiPostScanResult multiPostScanResult = postService.get(queued);
if (multiPostScanResult == null) {
log.error(String.format("Failed to get links for threadId = %s", threadId));
throw new ServerErrorException(String.format("Failed to get links for threadId = %s", threadId));
} else {
return multiPostScanResult.getPosts();
}
} catch (Exception e) {
throw new ServerErrorException(String.format("Failed to get links for threadId = %s, %s", threadId, e.getMessage()));
}
}
}
@PostMapping("/grab/remove")
@ResponseStatus(value = HttpStatus.OK)
public ThreadId grabRemove(@RequestBody @NonNull ThreadId threadId) {
postService.remove(threadId.getThreadId());
return threadId;
synchronized (LOCK) {
postService.remove(threadId.getThreadId());
return threadId;
}
}
@GetMapping("/grab/clear")
@ResponseStatus(value = HttpStatus.OK)
public void grabClear() {
synchronized (LOCK) {
dataService.clearQueueLinks();
}
}
}
@@ -6,21 +6,20 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import tn.mnlr.vripper.exception.ValidationException;
import tn.mnlr.vripper.services.SettingsService;
import tn.mnlr.vripper.services.VGAuthService;
import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
import java.util.List;
@RestController
@Slf4j
@CrossOrigin(value = "*")
public class SettingsRestEndpoint {
private final SettingsService settingsService;
private final VGAuthService VGAuthService;
@Autowired
public SettingsRestEndpoint(SettingsService settingsService, VGAuthService VGAuthService) {
public SettingsRestEndpoint(SettingsService settingsService) {
this.settingsService = settingsService;
this.VGAuthService = VGAuthService;
}
@PostMapping("/settings/theme")
@@ -38,7 +37,7 @@ public class SettingsRestEndpoint {
@PostMapping("/settings")
@ResponseStatus(value = HttpStatus.OK)
public SettingsService.Settings postSettings(@RequestBody SettingsService.Settings settings) throws Exception {
public SettingsService.Settings postSettings(@RequestBody SettingsService.Settings settings) {
try {
this.settingsService.check(settings);
@@ -48,7 +47,6 @@ public class SettingsRestEndpoint {
}
this.settingsService.newSettings(settings);
VGAuthService.authenticate();
return getAppSettingsService();
}
@@ -58,4 +56,10 @@ public class SettingsRestEndpoint {
return settingsService.getSettings();
}
@GetMapping("/settings/proxies")
@ResponseStatus(value = HttpStatus.OK)
public List<String> mirrors() {
return settingsService.getProxies();
}
}
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@@ -1,6 +1,9 @@
package tn.mnlr.vripper.web.restendpoints.domain;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@@ -1,19 +1,27 @@
package tn.mnlr.vripper.web.wsendpoints;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import reactor.core.Disposable;
import tn.mnlr.vripper.event.*;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.services.*;
import tn.mnlr.vripper.listener.*;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.DownloadSpeedService;
import tn.mnlr.vripper.services.GlobalStateService;
import tn.mnlr.vripper.services.VGAuthService;
import tn.mnlr.vripper.services.domain.DownloadSpeed;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@@ -26,46 +34,72 @@ public class DataBroadcast {
private final DownloadSpeedService downloadSpeedService;
private final DataService dataService;
private final PostUpdateEventListener postUpdateEventListener;
private final MetadataUpdateEventListener metadataUpdateEventListener;
private final ImageUpdateEventListener imageUpdateEventListener;
private final QueuedUpdateEventListener queuedUpdateEventListener;
private final EventUpdateEventListener eventUpdateEventListener;
private final QueuedRemoveEventListener queuedRemoveEventListener;
private final PostRemoveEventListener postRemoveEventListener;
private final EventRemoveEventListener eventRemoveEventListener;
private final List<Disposable> disposables = new ArrayList<>();
@Autowired
public DataBroadcast(SimpMessagingTemplate template, VGAuthService VGAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService) {
public DataBroadcast(SimpMessagingTemplate template, VGAuthService VGAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService, PostUpdateEventListener postUpdateEventListener, MetadataUpdateEventListener metadataUpdateEventListener, ImageUpdateEventListener imageUpdateEventListener, QueuedUpdateEventListener queuedUpdateEventListener, EventUpdateEventListener eventUpdateEventListener, QueuedRemoveEventListener queuedRemoveEventListener, PostRemoveEventListener postRemoveEventListener, EventRemoveEventListener eventRemoveEventListener) {
this.template = template;
this.VGAuthService = VGAuthService;
this.globalStateService = globalStateService;
this.downloadSpeedService = downloadSpeedService;
this.dataService = dataService;
this.postUpdateEventListener = postUpdateEventListener;
this.metadataUpdateEventListener = metadataUpdateEventListener;
this.imageUpdateEventListener = imageUpdateEventListener;
this.queuedUpdateEventListener = queuedUpdateEventListener;
this.eventUpdateEventListener = eventUpdateEventListener;
this.queuedRemoveEventListener = queuedRemoveEventListener;
this.postRemoveEventListener = postRemoveEventListener;
this.eventRemoveEventListener = eventRemoveEventListener;
}
@PostConstruct
private void run() {
disposables.add(VGAuthService.getLoggedInUser()
.subscribeOn(Schedulers.io())
.onBackpressureBuffer()
.map(DataController.LoggedUser::new)
.subscribe(user -> template.convertAndSend("/topic/user", user), e -> log.error("Failed to send data to client", e)));
disposables.add(globalStateService.getLiveGlobalState()
.subscribeOn(Schedulers.io())
.onBackpressureBuffer()
disposables.add(globalStateService.getGlobalState()
.subscribe(state -> template.convertAndSend("/topic/download-state", state), e -> log.error("Failed to send data to client", e)));
disposables.add(downloadSpeedService.getReadBytesPerSecond()
.subscribeOn(Schedulers.io())
.onBackpressureBuffer()
.map(DownloadSpeed::new)
.subscribe(speed -> template.convertAndSend("/topic/speed", speed), e -> log.error("Failed to send data to client", e)));
disposables.add(dataService.livePost()
.subscribeOn(Schedulers.io())
.buffer(500, TimeUnit.MILLISECONDS)
disposables.add(postUpdateEventListener.getDataFlux()
.map(PostUpdateEvent::getId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(ids -> template.convertAndSend("/topic/posts", ids.stream().map(dataService::findPostById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e)));
.subscribe(ids -> template.convertAndSend("/topic/posts", ids.stream().map(dataService::findById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e)));
disposables.add(dataService.liveImage()
.subscribeOn(Schedulers.io())
.buffer(500, TimeUnit.MILLISECONDS)
disposables.add(metadataUpdateEventListener.getDataFlux()
.map(MetadataUpdateEvent::getPostIdRef)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(ids -> template.convertAndSend("/topic/posts", ids.stream().map(dataService::findById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e)));
disposables.add(eventUpdateEventListener.getDataFlux()
.map(EventUpdateEvent::getId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(ids -> template.convertAndSend("/topic/events", ids.stream().map(dataService::findEventById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e)));
disposables.add(imageUpdateEventListener.getDataFlux()
.map(ImageUpdateEvent::getId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(id -> id
@@ -78,29 +112,37 @@ public class DataBroadcast {
e -> log.error("Failed to send data to client", e))
);
disposables.add(dataService.liveQueue()
.subscribeOn(Schedulers.io())
.buffer(500, TimeUnit.MILLISECONDS)
disposables.add(queuedUpdateEventListener.getDataFlux()
.map(QueuedUpdateEvent::getId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(ids -> template.convertAndSend("/topic/queued", ids.stream().map(dataService::findQueuedById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e))
);
disposables.add(dataService.queueRemove()
.subscribeOn(Schedulers.io())
.buffer(500, TimeUnit.MILLISECONDS)
disposables.add(queuedRemoveEventListener.getDataFlux()
.map(QueuedRemoveEvent::getThreadId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(threadIds -> template.convertAndSend("/topic/queued/deleted", threadIds), e -> log.error("Failed to send data to client", e))
);
disposables.add(dataService.postRemove()
.subscribeOn(Schedulers.io())
.buffer(500, TimeUnit.MILLISECONDS)
disposables.add(postRemoveEventListener.getDataFlux()
.map(PostRemoveEvent::getPostId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(postIds -> template.convertAndSend("/topic/posts/deleted", postIds), e -> log.error("Failed to send data to client", e))
);
disposables.add(eventRemoveEventListener.getDataFlux()
.map(EventRemoveEvent::getId)
.buffer(Duration.of(500, ChronoUnit.MILLIS))
.map(HashSet::new)
.filter(e -> !e.isEmpty())
.subscribe(postIds -> template.convertAndSend("/topic/events/deleted", postIds), e -> log.error("Failed to send data to client", e))
);
}
@PreDestroy
@@ -5,17 +5,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import tn.mnlr.vripper.jpa.domain.Event;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.Queued;
import tn.mnlr.vripper.services.*;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.DownloadSpeedService;
import tn.mnlr.vripper.services.GlobalStateService;
import tn.mnlr.vripper.services.VGAuthService;
import tn.mnlr.vripper.services.domain.DownloadSpeed;
import tn.mnlr.vripper.services.domain.GlobalState;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@Controller
public class DataController {
@@ -33,16 +35,6 @@ public class DataController {
this.dataService = dataService;
}
@Getter
public static class LoggedUser {
private final String user;
LoggedUser(String user) {
this.user = user;
}
}
@SubscribeMapping("/user")
public LoggedUser user() {
return new LoggedUser(VGAuthService.getLoggedUser());
@@ -60,7 +52,7 @@ public class DataController {
@SubscribeMapping("/posts")
public Collection<Post> posts() {
return StreamSupport.stream(dataService.findAllPosts().spliterator(), false).collect(Collectors.toList());
return dataService.findAllPosts();
}
@SubscribeMapping("/images/{postId}")
@@ -70,6 +62,21 @@ public class DataController {
@SubscribeMapping("/queued")
public Collection<Queued> queued() {
return StreamSupport.stream(dataService.findAllQueued().spliterator(), false).collect(Collectors.toList());
return dataService.findAllQueued();
}
@SubscribeMapping("/events")
public Collection<Event> events() {
return dataService.findAllEvents();
}
@Getter
public static class LoggedUser {
private final String user;
LoggedUser(String user) {
this.user = user;
}
}
}
@@ -8,7 +8,7 @@ management.endpoints.web.exposure.include=shutdown
management.endpoint.shutdown.enabled=true
server.error.include-message=always
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml
spring.datasource.url=jdbc:hsqldb:file:${base.dir}/${base.dir.name}/db/xparty;hsqldb.lock_file=false
spring.datasource.url=jdbc:hsqldb:file:${base.dir}/${base.dir.name}/db/vripper;hsqldb.lock_file=false
spring.datasource.username=SA
spring.datasource.password=lEtmEIn
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
@@ -2,10 +2,60 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet author="sysgen" id="1595764509827-1">
<createSequence sequenceName="HIBERNATE_SEQUENCE"/>
</changeSet>
<changeSet author="sysgen" id="1595764509827-2">
<changeSet author="death-claw" id="1613151442-1">
<createTable tableName="POST">
<column name="ID" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="DONE" type="INT">
<constraints nullable="false"/>
</column>
<column name="FORUM" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="HOSTS" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="POST_FOLDER_NAME" type="VARCHAR(500)"/>
<column name="POST_ID" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="PREVIEWS" type="VARCHAR(16777216)"/>
<column name="SECURITY_TOKEN" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="THANKED" type="BOOLEAN">
<constraints nullable="false"/>
</column>
<column name="THREAD_ID" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="THREAD_TITLE" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="TITLE" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="TOTAL" type="INT">
<constraints nullable="false"/>
</column>
<column name="URL" type="VARCHAR(3000)">
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="METADATA">
<column name="POST_ID_REF" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="POST_ID" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="POSTED_BY" type="VARCHAR(255)"/>
<column name="RESOLVED_NAMES" type="VARCHAR(16777216)"/>
</createTable>
<createTable tableName="IMAGE">
<column name="ID" type="BIGINT">
<constraints nullable="false"/>
@@ -31,61 +81,10 @@
<column name="URL" type="VARCHAR(3000)">
<constraints nullable="false"/>
</column>
<column name="POST_ID_REF" type="BIGINT"/>
</createTable>
</changeSet>
<changeSet author="sysgen" id="1595764509827-3">
<createTable tableName="METADATA">
<column name="ID" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="POSTED_BY" type="VARCHAR(255)"/>
<column name="RESOLVED_NAMES" type="VARCHAR(16777216)"/>
<column name="POST_ID_REF" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="sysgen" id="1595764509827-4">
<createTable tableName="POST">
<column name="ID" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="DONE" type="INT">
<constraints nullable="false"/>
</column>
<column name="FORUM" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="HOSTS" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="POST_FOLDER_NAME" type="VARCHAR(500)"/>
<column name="POST_ID" type="VARCHAR(255)"/>
<column name="PREVIEWS" type="VARCHAR(16777216)"/>
<column name="SECURITY_TOKEN" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="THANKED" type="BOOLEAN"/>
<column name="THREAD_ID" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="THREAD_TITLE" type="VARCHAR(500)"/>
<column name="TITLE" type="VARCHAR(500)">
<constraints nullable="false"/>
</column>
<column name="TOTAL" type="INT">
<constraints nullable="false"/>
</column>
<column name="URL" type="VARCHAR(3000)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="sysgen" id="1595764509827-5">
<createTable tableName="QUEUED">
<column name="ID" type="BIGINT">
<constraints nullable="false"/>
@@ -104,69 +103,62 @@
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="EVENT">
<column name="ID" type="BIGINT">
<constraints nullable="false"/>
</column>
<column name="TYPE" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="TIME" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="MESSAGE" type="VARCHAR(16777216)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="sysgen" id="1595764509827-6">
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10092" tableName="IMAGE"/>
<changeSet author="death-claw" id="1613151442-2">
<createSequence sequenceName="SEQ_IMAGE" incrementBy="1" startValue="1"/>
<createSequence sequenceName="SEQ_POST" incrementBy="1" startValue="1"/>
<createSequence sequenceName="SEQ_QUEUED" incrementBy="1" startValue="1"/>
<createSequence sequenceName="SEQ_EVENT" incrementBy="1" startValue="1"/>
</changeSet>
<changeSet author="sysgen" id="1595764509827-7">
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10110" tableName="METADATA"/>
<changeSet author="death-claw" id="1613151442-3">
<addPrimaryKey columnNames="ID" constraintName="EVENT_PK" tableName="EVENT"/>
<addPrimaryKey columnNames="ID" constraintName="IMAGE_PK" tableName="IMAGE"/>
<addPrimaryKey columnNames="POST_ID_REF" constraintName="METADATA_PK" tableName="METADATA"/>
<addPrimaryKey columnNames="ID" constraintName="POST_PK" tableName="POST"/>
<addPrimaryKey columnNames="ID" constraintName="QUEUED_PK" tableName="QUEUED"/>
</changeSet>
<changeSet author="sysgen" id="1595764509827-8">
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10116" tableName="POST"/>
</changeSet>
<changeSet author="sysgen" id="1595764509827-9">
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10138" tableName="QUEUED"/>
</changeSet>
<changeSet author="sysgen" id="1595764509827-10">
<changeSet author="death-claw" id="1613151442-4">
<createIndex indexName="IMAGE_POST_ID_IDX" tableName="IMAGE">
<column name="POST_ID"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-11">
<createIndex indexName="IMAGE_STATUS_IDX" tableName="IMAGE">
<column name="STATUS"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-12">
<createIndex indexName="POST_POST_ID_IDX" tableName="POST">
<column name="POST_ID"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-13">
<createIndex indexName="POST_STATUS_IDX" tableName="POST">
<column name="STATUS"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-14">
<createIndex indexName="QUEUED_THREAD_ID_IDX" tableName="QUEUED">
<column name="THREAD_ID"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-15">
<createIndex indexName="SYS_IDX_IMAGE_POST_ID_REF_POST_ID_FK_10150" tableName="IMAGE">
<column name="POST_ID_REF"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-16">
<createIndex indexName="SYS_IDX_METADATA_POST_ID_REF_POST_ID_FK_10160" tableName="METADATA">
<column name="POST_ID_REF"/>
</createIndex>
</changeSet>
<changeSet author="sysgen" id="1595764509827-17">
<changeSet author="death-claw" id="1613151442-5">
<addForeignKeyConstraint baseColumnNames="POST_ID_REF" baseTableName="IMAGE"
constraintName="IMAGE_POST_ID_REF_POST_ID_FK" deferrable="false"
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
referencedColumnNames="ID" referencedTableName="POST"/>
</changeSet>
<changeSet author="sysgen" id="1595764509827-18">
<addForeignKeyConstraint baseColumnNames="POST_ID_REF" baseTableName="METADATA"
constraintName="METADATA_POST_ID_REF_POST_ID_FK" deferrable="false"
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
referencedColumnNames="ID" referencedTableName="POST"/>
</changeSet>
<changeSet id="1600798657000-01" author="sysgen">
<createIndex tableName="POST" indexName="POST_UQ_POST_ID_IDX">
<column name="POST_ID"/>
</createIndex>
</changeSet>
</databaseChangeLog>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

@@ -0,0 +1,8 @@
[
"https://planetviper.club",
"https://viperbb.rocks",
"https://viperkats.eu",
"https://viperohilia.art",
"https://viperproxy.org",
"https://vipervault.link"
]
+8 -1
View File
@@ -26,10 +26,17 @@
"assets": [
"src/favicon.ico",
"src/assets",
{ "glob": "mdi.svg", "input": "./node_modules/@mdi/angular-material", "output": "./assets" }
{
"glob": "mdi.svg",
"input": "./node_modules/@mdi/angular-material",
"output": "./assets"
}
],
"styles": [
"src/styles.scss"
],
"allowedCommonJsDependencies": [
"@stomp/rx-stomp"
]
},
"configurations": {
-14267
View File
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -1,6 +1,6 @@
{
"name": "vripper-ui",
"version": "3.1.0",
"version": "3.3.6",
"scripts": {
"ng": "ng",
"start": "ng serve",
@@ -13,17 +13,17 @@
},
"private": true,
"dependencies": {
"@angular/animations": "11.0.0",
"@angular/cdk": "11.0.0",
"@angular/common": "11.0.0",
"@angular/compiler": "11.0.0",
"@angular/core": "11.0.0",
"@angular/animations": "11.0.8",
"@angular/cdk": "11.0.3",
"@angular/common": "11.0.8",
"@angular/compiler": "11.0.8",
"@angular/core": "11.0.8",
"@angular/flex-layout": "11.0.0-beta.33",
"@angular/forms": "11.0.0",
"@angular/material": "11.0.0",
"@angular/platform-browser": "11.0.0",
"@angular/platform-browser-dynamic": "11.0.0",
"@angular/router": "11.0.0",
"@angular/forms": "11.0.8",
"@angular/material": "11.0.3",
"@angular/platform-browser": "11.0.8",
"@angular/platform-browser-dynamic": "11.0.8",
"@angular/router": "11.0.8",
"@mdi/angular-material": "^5.8.55",
"@stomp/rx-stomp": "^0.3.5",
"ag-grid-angular": "24.1.0",
@@ -35,15 +35,15 @@
"zone.js": "0.10.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.1100.0",
"@angular/cli": "11.0.0",
"@angular/compiler-cli": "11.0.0",
"@angular/language-service": "11.0.0",
"@angular-devkit/build-angular": "^0.1100.6",
"@angular/cli": "11.0.6",
"@angular/compiler-cli": "11.0.8",
"@angular/language-service": "11.0.8",
"@types/jasmine": "3.5.12",
"@types/jasminewd2": "2.0.8",
"@types/node": "12.12.21",
"codelyzer": "6.0.0",
"electron": "10.1.5",
"electron": "11.1.1",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.1",
+19 -21
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.1.0</version>
<version>3.3.6</version>
</parent>
<artifactId>vripper-ui</artifactId>
<name>vripper-ui</name>
@@ -33,34 +33,33 @@
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.3</version>
<version>1.11.2</version>
<configuration>
<nodeVersion>v12.2.0</nodeVersion>
<npmVersion>6.9.0</npmVersion>
<nodeVersion>v14.16.0</nodeVersion>
<yarnVersion>v1.22.10</yarnVersion>
<workingDirectory>build-dir</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-npm</goal>
<goal>install-node-and-yarn</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<id>yarn install</id>
<goals>
<goal>npm</goal>
<goal>yarn</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<id>yarn run build</id>
<goals>
<goal>npm</goal>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run build-web</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
@@ -77,34 +76,33 @@
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.3</version>
<version>1.11.2</version>
<configuration>
<nodeVersion>v12.2.0</nodeVersion>
<npmVersion>6.9.0</npmVersion>
<nodeVersion>v14.16.0</nodeVersion>
<yarnVersion>v1.22.10</yarnVersion>
<workingDirectory>build-dir</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-npm</goal>
<goal>install-node-and-yarn</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<id>yarn install</id>
<goals>
<goal>npm</goal>
<goal>yarn</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<id>yarn run build</id>
<goals>
<goal>npm</goal>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run build-electron</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
@@ -0,0 +1,10 @@
@import '~@angular/material/theming';
@mixin about-component-theme($theme) {
$foreground: map-get($theme, foreground);
$background: map-get($theme, background);
.about-link, .about-icon {
color: mat-color($foreground, text);
}
}

Some files were not shown because too many files have changed in this diff Show More