mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6375c0aed6 | ||
|
|
40ca4cf86b | ||
|
|
b3a798388b | ||
|
|
6e69b2bce8 | ||
|
|
bb6dcd77b9 | ||
|
|
42e1aa73e2 | ||
|
|
26fde22af2 | ||
|
|
798f39d54f | ||
|
|
3a21dfac38 |
+18
-1
@@ -1,6 +1,23 @@
|
||||
# Changelog
|
||||
|
||||
## [3.2] - 2020-11-16
|
||||
## [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
|
||||
|
||||
|
||||
@@ -20,5 +20,3 @@ 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.
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SC7M5LNWZ528Q)
|
||||
@@ -4,12 +4,12 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.2.3</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>
|
||||
|
||||
Generated
+14
-32
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vripper-electron",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -271,11 +271,11 @@
|
||||
"dev": true
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
|
||||
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||
"requires": {
|
||||
"follow-redirects": "1.5.10"
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"balanced-match": {
|
||||
@@ -831,9 +831,9 @@
|
||||
}
|
||||
},
|
||||
"electron": {
|
||||
"version": "10.1.5",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-10.1.5.tgz",
|
||||
"integrity": "sha512-fys/KnEfJq05TtMij+lFvLuKkuVH030CHYx03iZrW5DNNLwjE6cW3pysJ420lB0FRSfPjTHBMu2eVCf5TG71zQ==",
|
||||
"version": "11.1.1",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-11.1.1.tgz",
|
||||
"integrity": "sha512-tlbex3xosJgfileN6BAQRotevPRXB/wQIq48QeQ08tUJJrXwE72c8smsM/hbHx5eDgnbfJ2G3a60PmRjHU2NhA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@electron/get": "^1.0.1",
|
||||
@@ -1129,27 +1129,9 @@
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||
"requires": {
|
||||
"debug": "=3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
"version": "1.13.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz",
|
||||
"integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg=="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "8.1.0",
|
||||
@@ -1384,9 +1366,9 @@
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
|
||||
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==",
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
|
||||
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==",
|
||||
"dev": true
|
||||
},
|
||||
"is-ci": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vripper-electron",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.3",
|
||||
"description": "A ripper for vipergirls.to built using web technolgies",
|
||||
"main": "main.js",
|
||||
"author": "death-claw <53543762+death-claw@users.noreply.github.com>",
|
||||
@@ -65,11 +65,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",
|
||||
|
||||
+71
-71
@@ -1,77 +1,77 @@
|
||||
<?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.2.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.2.3</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>
|
||||
<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.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>
|
||||
<configuration>
|
||||
<arguments>run dist</arguments>
|
||||
</configuration>
|
||||
<phase>generate-resources</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<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" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.2.3</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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@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()) {
|
||||
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,8 +3,8 @@ 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.jpa.domain.enums.Status;
|
||||
import tn.mnlr.vripper.services.ConnectionService;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
|
||||
@Slf4j
|
||||
@@ -12,18 +12,20 @@ public class DownloadRunnable implements Runnable {
|
||||
|
||||
private final DownloadService downloadService;
|
||||
private final DataService dataService;
|
||||
private final ConnectionService connectionService;
|
||||
|
||||
private final DownloadJob downloadJob;
|
||||
|
||||
public DownloadRunnable(final DownloadJob downloadJob) {
|
||||
downloadService = SpringContext.getBean(DownloadService.class);
|
||||
dataService = SpringContext.getBean(DataService.class);
|
||||
connectionService = SpringContext.getBean(ConnectionService.class);
|
||||
this.downloadJob = downloadJob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Failsafe.with(VripperApplication.retryPolicy)
|
||||
Failsafe.with(connectionService.getRetryPolicy())
|
||||
.onFailure(e -> {
|
||||
log.error(String.format("Failed to download %s after %d tries", downloadJob.getImage().getUrl(), e.getAttemptCount()), e.getFailure());
|
||||
downloadJob.getImage().setStatus(Status.ERROR);
|
||||
|
||||
@@ -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 ImageUpdateEvent extends ApplicationEvent {
|
||||
|
||||
private final Long id;
|
||||
|
||||
public ImageUpdateEvent(Object source, Long id) {
|
||||
super(source);
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package tn.mnlr.vripper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class MetadataUpdateEvent extends ApplicationEvent {
|
||||
|
||||
private final Long id;
|
||||
private final Long postIdRef;
|
||||
|
||||
public MetadataUpdateEvent(Object source, Long id, Long postIdRef) {
|
||||
super(source);
|
||||
this.id = id;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class Post {
|
||||
private String securityToken;
|
||||
|
||||
@JsonIgnore
|
||||
private String postFolderName;
|
||||
private String downloadDirectory;
|
||||
|
||||
private boolean thanked;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2,5 +2,5 @@ package tn.mnlr.vripper.jpa.repositories;
|
||||
|
||||
public interface IRepository {
|
||||
|
||||
public void init();
|
||||
void init();
|
||||
}
|
||||
|
||||
+28
-16
@@ -1,8 +1,11 @@
|
||||
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.ImageUpdateEvent;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.jpa.domain.enums.Status;
|
||||
import tn.mnlr.vripper.jpa.repositories.IImageRepository;
|
||||
@@ -12,10 +15,11 @@ 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) {
|
||||
@@ -50,6 +54,7 @@ public class ImageRepository implements IImageRepository {
|
||||
image.getPostIdRef()
|
||||
);
|
||||
image.setId(id);
|
||||
applicationEventPublisher.publishEvent(new ImageUpdateEvent(ImageRepository.class, id));
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -62,9 +67,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 +83,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 +99,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 +118,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(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-1
@@ -1,8 +1,11 @@
|
||||
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;
|
||||
|
||||
@@ -11,10 +14,11 @@ 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) {
|
||||
@@ -44,6 +48,7 @@ public class MetadataRepository implements IMetadataRepository {
|
||||
metadata.getPostIdRef()
|
||||
);
|
||||
metadata.setId(id);
|
||||
applicationEventPublisher.publishEvent(new MetadataUpdateEvent(MetadataRepository.class, id, metadata.getPostIdRef()));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@@ -82,4 +87,9 @@ public class MetadataRepository implements IMetadataRepository {
|
||||
postId
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
|
||||
+38
-26
@@ -1,8 +1,12 @@
|
||||
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.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;
|
||||
@@ -12,10 +16,11 @@ 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) {
|
||||
@@ -44,7 +49,7 @@ public class PostRepository implements IPostRepository {
|
||||
post.getDone(),
|
||||
post.getForum(),
|
||||
String.join(";", post.getHosts()),
|
||||
post.getPostFolderName(),
|
||||
post.getDownloadDirectory(),
|
||||
post.getPostId(),
|
||||
String.join(";", post.getPreviews()),
|
||||
post.getSecurityToken(),
|
||||
@@ -57,24 +62,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()
|
||||
);
|
||||
new PostRowMapper(),
|
||||
postId);
|
||||
if (posts.isEmpty()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
@@ -94,9 +91,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 +112,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 +130,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(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class PostRowMapper implements RowMapper<Post> {
|
||||
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.setDownloadDirectory(rs.getString("POST_FOLDER_NAME"));
|
||||
post.setThanked(rs.getBoolean("THANKED"));
|
||||
String previews;
|
||||
if ((previews = rs.getString("PREVIEWS")) != null) {
|
||||
|
||||
+15
-2
@@ -1,8 +1,12 @@
|
||||
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;
|
||||
|
||||
@@ -11,10 +15,11 @@ 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) {
|
||||
@@ -46,6 +51,7 @@ public class QueuedRepository implements IQueuedRepository {
|
||||
queued.getThreadId()
|
||||
);
|
||||
queued.setId(id);
|
||||
applicationEventPublisher.publishEvent(new QueuedUpdateEvent(QueuedRepository.class, id));
|
||||
return queued;
|
||||
}
|
||||
|
||||
@@ -87,9 +93,16 @@ 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 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.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);
|
||||
}
|
||||
}
|
||||
+32
@@ -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,7 +1,5 @@
|
||||
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;
|
||||
@@ -32,33 +30,6 @@ public class DataService {
|
||||
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();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public DataService(IPostRepository postRepository, IImageRepository imageRepository, IQueuedRepository queuedRepository, IMetadataRepository metadataRepository, SettingsService settingsService) {
|
||||
this.postRepository = postRepository;
|
||||
@@ -70,17 +41,14 @@ public class DataService {
|
||||
|
||||
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() {
|
||||
@@ -197,7 +162,7 @@ public class DataService {
|
||||
return queuedRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<Post> findPostById(Long aLong) {
|
||||
public Optional<Post> findById(Long aLong) {
|
||||
return postRepository.findById(aLong);
|
||||
}
|
||||
|
||||
@@ -212,7 +177,6 @@ public class DataService {
|
||||
public void setMetadata(Post post, Metadata metadata) {
|
||||
metadata.setPostIdRef(post.getId());
|
||||
metadataRepository.save(metadata);
|
||||
livePostsState.onNext(post.getId());
|
||||
}
|
||||
|
||||
public Optional<Metadata> findMetadataByPostId(String postId) {
|
||||
@@ -221,36 +185,29 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
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;
|
||||
@@ -34,40 +33,12 @@ 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;
|
||||
|
||||
@Autowired
|
||||
public MetadataService(ConnectionService cm, VGAuthService VGAuthService, HtmlProcessorService htmlProcessorService, XpathService xpathService) {
|
||||
this.cm = cm;
|
||||
@@ -97,7 +68,7 @@ public class MetadataService {
|
||||
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");
|
||||
@@ -162,4 +133,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;
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ public class PostService {
|
||||
}
|
||||
log.debug(String.format("threadId %s, postId %s is added automatically for download", queued.getThreadId(), queued.getPostId()));
|
||||
} else {
|
||||
if(dataService.findQueuedByThreadId(queued.getThreadId()).isEmpty()) {
|
||||
if (dataService.findQueuedByThreadId(queued.getThreadId()).isEmpty()) {
|
||||
dataService.newQueueLink(queued);
|
||||
} else {
|
||||
log.info(String.format("Thread with id = %s is already loaded", queued.getThreadId()));
|
||||
|
||||
@@ -11,8 +11,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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;
|
||||
@@ -25,7 +28,6 @@ import java.nio.file.Paths;
|
||||
import static java.nio.file.StandardOpenOption.*;
|
||||
|
||||
@Service
|
||||
@Getter
|
||||
@Setter
|
||||
@Slf4j
|
||||
public class SettingsService {
|
||||
@@ -33,6 +35,9 @@ public class SettingsService {
|
||||
private final Path configPath;
|
||||
private final ObjectMapper om = new ObjectMapper();
|
||||
|
||||
private Sinks.Many<Settings> sink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
|
||||
@Getter
|
||||
private Settings settings = new Settings();
|
||||
|
||||
public SettingsService(@Value("${base.dir}") String baseDir, @Value("${base.dir.name}") String baseDirName) {
|
||||
@@ -43,6 +48,11 @@ public class SettingsService {
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
restore();
|
||||
sink.emitNext(settings, EmitHandler.RETRY);
|
||||
}
|
||||
|
||||
Flux<Settings> getSettingsFlux() {
|
||||
return sink.asFlux();
|
||||
}
|
||||
|
||||
public void newSettings(Settings settings) {
|
||||
@@ -60,17 +70,12 @@ 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();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Failed restore user settings", e);
|
||||
settings = new Settings();
|
||||
@@ -140,19 +145,39 @@ public class SettingsService {
|
||||
settings.setLeaveThanksOnStart(false);
|
||||
}
|
||||
|
||||
if (settings.getConnectionTimeout() == null) {
|
||||
settings.setConnectionTimeout(30);
|
||||
}
|
||||
|
||||
if (settings.getMaxAttempts() == null) {
|
||||
settings.setMaxAttempts(5);
|
||||
}
|
||||
|
||||
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 +199,14 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
public Theme getTheme() {
|
||||
@@ -250,5 +283,11 @@ public class SettingsService {
|
||||
|
||||
@JsonProperty("leaveThanksOnStart")
|
||||
private Boolean leaveThanksOnStart;
|
||||
|
||||
@JsonProperty("connectionTimeout")
|
||||
private Integer connectionTimeout;
|
||||
|
||||
@JsonProperty("maxAttempts")
|
||||
private Integer maxAttempts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,15 @@ 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 javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,37 +35,42 @@ public class VGAuthService {
|
||||
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) {
|
||||
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 +79,7 @@ public class VGAuthService {
|
||||
log.debug("Authentication option is disabled");
|
||||
context.getCookieStore().clear();
|
||||
loggedUser = "";
|
||||
loggedInUser.onNext(loggedUser);
|
||||
sink.emitNext(loggedUser, EmitHandler.RETRY);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +90,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -97,8 +106,9 @@ 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 vipergirls.to", e);
|
||||
return;
|
||||
}
|
||||
|
||||
postAuth.addHeader("Referer", "https://vipergirls.to/");
|
||||
@@ -115,22 +125,20 @@ 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("Failed to authenticate user with vipergirls.to, missing vg_userid cookie");
|
||||
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 vipergirls.to", 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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -7,7 +7,6 @@ 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 java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -96,7 +95,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,7 +8,6 @@ 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;
|
||||
@@ -61,7 +60,7 @@ public class ApiPostParser {
|
||||
}
|
||||
|
||||
private ApiPost getPost(HttpGet httpGet, ApiPostHandler apiPostHandler, AtomicReference<Throwable> thr) {
|
||||
return Failsafe.with(VripperApplication.retryPolicy)
|
||||
return Failsafe.with(cm.getRetryPolicy())
|
||||
.onFailure(e -> thr.set(e.getFailure()))
|
||||
.get(() -> {
|
||||
HttpClient connection = cm.getClient().build();
|
||||
|
||||
@@ -16,6 +16,8 @@ public class ApiThreadHandler extends DefaultHandler {
|
||||
private final Queued queued;
|
||||
private final Collection<Host> supportedHosts;
|
||||
private final Map<Host, AtomicInteger> hostMap = new HashMap<>();
|
||||
@Getter
|
||||
private final List<MultiPostItem> posts = new ArrayList<>();
|
||||
private List<String> previews = new ArrayList<>();
|
||||
private String threadTitle;
|
||||
private String postId;
|
||||
@@ -24,9 +26,6 @@ public class ApiThreadHandler extends DefaultHandler {
|
||||
private int postCounter;
|
||||
private int previewCounter = 0;
|
||||
|
||||
@Getter
|
||||
private final List<MultiPostItem> posts = new ArrayList<>();
|
||||
|
||||
public ApiThreadHandler(Queued queued) {
|
||||
this.queued = queued;
|
||||
this.supportedHosts = SpringContext.getBeansOfType(Host.class).values();
|
||||
@@ -63,7 +62,7 @@ public class ApiThreadHandler extends DefaultHandler {
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if ("post".equals(qName.toLowerCase())) {
|
||||
if ("post".equalsIgnoreCase(qName)) {
|
||||
if (imageCount != 0) {
|
||||
posts.add(new MultiPostItem(
|
||||
queued.getThreadId(),
|
||||
|
||||
@@ -8,7 +8,6 @@ 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.jpa.domain.Queued;
|
||||
@@ -52,7 +51,7 @@ public class ApiThreadParser {
|
||||
ApiThreadHandler apiThreadHandler = new ApiThreadHandler(queued);
|
||||
AtomicReference<Throwable> thr = new AtomicReference<>();
|
||||
log.debug(String.format("Requesting %s", httpGet));
|
||||
List<MultiPostItem> posts = Failsafe.with(VripperApplication.retryPolicy)
|
||||
List<MultiPostItem> posts = Failsafe.with(cm.getRetryPolicy())
|
||||
.onFailure(e -> thr.set(e.getFailure()))
|
||||
.get(() -> {
|
||||
HttpClient connection = cm.getClient().build();
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MetadataRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(Thread.interrupted()) {
|
||||
if (Thread.interrupted()) {
|
||||
log.debug(String.format("Metadata fetching for postId=%s, threadId=%s interrupted", post.getPostId(), post.getThreadId()));
|
||||
return;
|
||||
}
|
||||
|
||||
+25
-22
@@ -10,13 +10,12 @@ 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.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;
|
||||
@@ -36,15 +35,13 @@ import java.util.stream.Collectors;
|
||||
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;
|
||||
@@ -127,11 +124,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 +182,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 +237,23 @@ 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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -6,7 +6,6 @@ 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;
|
||||
|
||||
@RestController
|
||||
@@ -15,12 +14,10 @@ import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
|
||||
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")
|
||||
@@ -48,7 +45,6 @@ public class SettingsRestEndpoint {
|
||||
}
|
||||
|
||||
this.settingsService.newSettings(settings);
|
||||
VGAuthService.authenticate();
|
||||
return getAppSettingsService();
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
+4
-1
@@ -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;
|
||||
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
+4
-1
@@ -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,61 @@ 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 QueuedRemoveEventListener queuedRemoveEventListener;
|
||||
private final PostRemoveEventListener postRemoveEventListener;
|
||||
|
||||
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, QueuedRemoveEventListener queuedRemoveEventListener, PostRemoveEventListener postRemoveEventListener) {
|
||||
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.queuedRemoveEventListener = queuedRemoveEventListener;
|
||||
this.postRemoveEventListener = postRemoveEventListener;
|
||||
}
|
||||
|
||||
@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(imageUpdateEventListener.getDataFlux()
|
||||
.map(ImageUpdateEvent::getId)
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
.map(HashSet::new)
|
||||
.filter(e -> !e.isEmpty())
|
||||
.subscribe(id -> id
|
||||
@@ -78,25 +101,25 @@ 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))
|
||||
|
||||
@@ -8,7 +8,10 @@ import org.springframework.stereotype.Controller;
|
||||
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;
|
||||
|
||||
@@ -33,16 +36,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());
|
||||
@@ -72,4 +65,14 @@ public class DataController {
|
||||
public Collection<Queued> queued() {
|
||||
return StreamSupport.stream(dataService.findAllQueued().spliterator(), false).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class LoggedUser {
|
||||
|
||||
private final String user;
|
||||
|
||||
LoggedUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+240
-547
File diff suppressed because it is too large
Load Diff
+16
-16
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vripper-ui",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.3",
|
||||
"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",
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.2.3</version>
|
||||
</parent>
|
||||
<artifactId>vripper-ui</artifactId>
|
||||
<name>vripper-ui</name>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule} from '@angular/router';
|
||||
import { HomeComponent } from './home/home.component';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {HomeComponent} from './home/home.component';
|
||||
|
||||
|
||||
const routes: Routes = [
|
||||
@@ -10,10 +10,11 @@ const routes: Routes = [
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' })
|
||||
RouterModule.forRoot(routes, {relativeLinkResolution: 'legacy'})
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
]
|
||||
})
|
||||
export class AppRoutingModule { }
|
||||
export class AppRoutingModule {
|
||||
}
|
||||
|
||||
@@ -46,31 +46,71 @@
|
||||
animation: sk-chase-dot-before 2.0s infinite ease-in-out both;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(1) { animation-delay: -1.1s; }
|
||||
.sk-chase-dot:nth-child(2) { animation-delay: -1.0s; }
|
||||
.sk-chase-dot:nth-child(3) { animation-delay: -0.9s; }
|
||||
.sk-chase-dot:nth-child(4) { animation-delay: -0.8s; }
|
||||
.sk-chase-dot:nth-child(5) { animation-delay: -0.7s; }
|
||||
.sk-chase-dot:nth-child(6) { animation-delay: -0.6s; }
|
||||
.sk-chase-dot:nth-child(1):before { animation-delay: -1.1s; }
|
||||
.sk-chase-dot:nth-child(2):before { animation-delay: -1.0s; }
|
||||
.sk-chase-dot:nth-child(3):before { animation-delay: -0.9s; }
|
||||
.sk-chase-dot:nth-child(4):before { animation-delay: -0.8s; }
|
||||
.sk-chase-dot:nth-child(5):before { animation-delay: -0.7s; }
|
||||
.sk-chase-dot:nth-child(6):before { animation-delay: -0.6s; }
|
||||
.sk-chase-dot:nth-child(1) {
|
||||
animation-delay: -1.1s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(2) {
|
||||
animation-delay: -1.0s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(3) {
|
||||
animation-delay: -0.9s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(4) {
|
||||
animation-delay: -0.8s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(5) {
|
||||
animation-delay: -0.7s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(6) {
|
||||
animation-delay: -0.6s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(1):before {
|
||||
animation-delay: -1.1s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(2):before {
|
||||
animation-delay: -1.0s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(3):before {
|
||||
animation-delay: -0.9s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(4):before {
|
||||
animation-delay: -0.8s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(5):before {
|
||||
animation-delay: -0.7s;
|
||||
}
|
||||
|
||||
.sk-chase-dot:nth-child(6):before {
|
||||
animation-delay: -0.6s;
|
||||
}
|
||||
|
||||
@keyframes sk-chase {
|
||||
100% { transform: rotate(360deg); }
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes sk-chase-dot {
|
||||
80%, 100% { transform: rotate(360deg); }
|
||||
80%, 100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes sk-chase-dot-before {
|
||||
50% {
|
||||
transform: scale(0.4);
|
||||
} 100%, 0% {
|
||||
}
|
||||
100%, 0% {
|
||||
transform: scale(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ import {RxStompState} from '@stomp/rx-stomp';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class AppComponent implements OnDestroy, AfterViewInit {
|
||||
electron: Subject<boolean>;
|
||||
loaded: Subject<boolean> = new BehaviorSubject(false);
|
||||
private subscriptions: Subscription[] = [];
|
||||
|
||||
constructor(
|
||||
private dialog: MatDialog,
|
||||
public ws: WsConnectionService,
|
||||
@@ -26,11 +30,6 @@ export class AppComponent implements OnDestroy, AfterViewInit {
|
||||
this.electron = new BehaviorSubject(electronService.isElectronApp);
|
||||
}
|
||||
|
||||
private subscriptions: Subscription[] = [];
|
||||
electron: Subject<boolean>;
|
||||
|
||||
loaded: Subject<boolean> = new BehaviorSubject(false);
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.appService.renderer = this.renderer;
|
||||
this.subscriptions.push(
|
||||
|
||||
@@ -11,5 +11,6 @@ export interface DialogConfirmation {
|
||||
templateUrl: 'confirmation-dialog.html'
|
||||
})
|
||||
export class ConfirmDialogComponent {
|
||||
constructor(public dialogRef: MatDialogRef<ConfirmDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: DialogConfirmation) {}
|
||||
constructor(public dialogRef: MatDialogRef<ConfirmDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: DialogConfirmation) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Credentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface DownloadPath {
|
||||
path: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export class DownloadSpeed {
|
||||
constructor(public speed: string) {}
|
||||
constructor(public speed: string) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export class GlobalState {
|
||||
constructor(public running: number, public remaining: number, public error: number) {
|
||||
}
|
||||
constructor(public running: number, public remaining: number, public error: number) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,5 +7,6 @@ export class MultiPostModel {
|
||||
public removed: boolean,
|
||||
public total: number,
|
||||
public loading: boolean
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@ export class Photo {
|
||||
public progress: number,
|
||||
public status: string,
|
||||
public index: number
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface RemoveAllResponse {
|
||||
removed: number;
|
||||
postIds: string[];
|
||||
}
|
||||
removed: number;
|
||||
postIds: string[];
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export interface RemoveResponse {
|
||||
postId: string;
|
||||
}
|
||||
postId: string;
|
||||
}
|
||||
|
||||
@@ -10,4 +10,6 @@ export interface Settings {
|
||||
desktopClipboard: boolean;
|
||||
viewPhotos: boolean;
|
||||
resolveTitle: boolean;
|
||||
connectionTimeout: number;
|
||||
maxAttempts: number;
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ export class MultiPostItem {
|
||||
public url: string,
|
||||
public previews: string[],
|
||||
public hosts: string
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export class WSMessage {
|
||||
|
||||
constructor(public destination: string, public payload?: string) {
|
||||
}
|
||||
constructor(public destination: string, public payload?: string) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class PostAltRendererNative implements ICellRendererComp {
|
||||
private contextMenuService: PostContextMenuService;
|
||||
|
||||
destroy(): void {
|
||||
if(this.gui) {
|
||||
if (this.gui) {
|
||||
this.gui.removeEventListener('contextmenu', this.context.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export class PostFilesRendererNative implements ICellRendererComp {
|
||||
private contextMenuService: PostContextMenuService;
|
||||
|
||||
destroy(): void {
|
||||
if(this.gui) {
|
||||
if (this.gui) {
|
||||
this.gui.removeEventListener('contextmenu', this.context.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export class PostProgressRendererNative extends ProgressRendererNative {
|
||||
private contextMenuService: PostContextMenuService;
|
||||
|
||||
destroy(): void {
|
||||
if(this.gui) {
|
||||
if (this.gui) {
|
||||
this.gui.removeEventListener('contextmenu', this.context.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export class PostStatusRendererNative extends StatusRendererNative {
|
||||
private contextMenuService: PostContextMenuService;
|
||||
|
||||
destroy(): void {
|
||||
if(this.gui) {
|
||||
if (this.gui) {
|
||||
this.gui.removeEventListener('contextmenu', this.context.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,30 +6,28 @@ import {AppPreviewComponent} from '../preview-tooltip/preview-tooltip.component'
|
||||
import {ComponentRef, NgZone} from '@angular/core';
|
||||
|
||||
export class TitleRendererNative implements ICellRendererComp {
|
||||
tooltipPortal = new ComponentPortal(AppPreviewComponent);
|
||||
appPreview: string[];
|
||||
private gui: HTMLElement;
|
||||
private text: HTMLSpanElement;
|
||||
private gridApi: GridApi;
|
||||
private node: RowNode;
|
||||
private contextMenuService: PostContextMenuService;
|
||||
private icon: HTMLSpanElement;
|
||||
|
||||
private overlayPositionBuilder: OverlayPositionBuilder;
|
||||
private overlay: Overlay;
|
||||
private zone: NgZone;
|
||||
|
||||
private overlayRef: OverlayRef;
|
||||
tooltipPortal = new ComponentPortal(AppPreviewComponent);
|
||||
appPreview: string[];
|
||||
|
||||
destroy(): void {
|
||||
if(this.gui) {
|
||||
if (this.gui) {
|
||||
this.gui.removeEventListener('contextmenu', this.context.bind(this));
|
||||
}
|
||||
if(this.overlayRef) {
|
||||
if (this.overlayRef) {
|
||||
this.overlayRef.dispose();
|
||||
}
|
||||
|
||||
if(this.icon) {
|
||||
if (this.icon) {
|
||||
this.icon.removeEventListener('mouseenter', this.mouseenter.bind(this));
|
||||
this.icon.removeEventListener('mouseleave', this.mouseout.bind(this));
|
||||
}
|
||||
@@ -86,7 +84,7 @@ export class TitleRendererNative implements ICellRendererComp {
|
||||
overlayY: 'bottom'
|
||||
}
|
||||
]);
|
||||
this.overlayRef = this.overlay.create({ positionStrategy, scrollStrategy: this.overlay.scrollStrategies.close() });
|
||||
this.overlayRef = this.overlay.create({positionStrategy, scrollStrategy: this.overlay.scrollStrategies.close()});
|
||||
|
||||
this.icon.addEventListener('mouseenter', this.mouseenter.bind(this));
|
||||
this.icon.addEventListener('mouseleave', this.mouseout.bind(this));
|
||||
|
||||
@@ -10,7 +10,7 @@ export class UrlRendererNative implements ICellRendererComp {
|
||||
private url: string;
|
||||
|
||||
destroy(): void {
|
||||
if(this.link) {
|
||||
if (this.link) {
|
||||
this.link.removeEventListener('click', this.goTo.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<mat-tab-group animationDuration="0" dynamicHeight style="height: 100%; margin-bottom: 20px;">
|
||||
<mat-tab label="Downloads">
|
||||
<app-posts></app-posts>
|
||||
<app-posts></app-posts>
|
||||
</mat-tab>
|
||||
<mat-tab>
|
||||
<ng-template mat-tab-label>
|
||||
|
||||
@@ -14,6 +14,8 @@ import {HttpClient} from '@angular/common/http';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class HomeComponent implements OnInit, OnDestroy {
|
||||
clipboardSub: Subscription;
|
||||
|
||||
constructor(
|
||||
private clipboardService: ClipboardService,
|
||||
public dialog: MatDialog,
|
||||
@@ -22,15 +24,14 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
private _snackBar: MatSnackBar,
|
||||
private ngZone: NgZone,
|
||||
public linkCollectorService: LinkCollectorService
|
||||
) {}
|
||||
|
||||
clipboardSub: Subscription;
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.clipboardSub = this.clipboardService.links.subscribe(e => {
|
||||
this.ngZone.run(() => {
|
||||
this.httpClient
|
||||
.post<{ threadId: string; postId: string }>(this.serverService.baseUrl + '/post', { url: e })
|
||||
.post<{ threadId: string; postId: string }>(this.serverService.baseUrl + '/post', {url: e})
|
||||
.subscribe(
|
||||
response => {
|
||||
this._snackBar.open('Clipboard scan complete', null, {
|
||||
|
||||
@@ -17,7 +17,7 @@ import {MatSlideToggleModule} from '@angular/material/slide-toggle';
|
||||
import {MatSnackBar, MatSnackBarModule} from '@angular/material/snack-bar';
|
||||
import {MatTabsModule} from '@angular/material/tabs';
|
||||
import {MatToolbarModule} from '@angular/material/toolbar';
|
||||
import {MatSelectModule} from "@angular/material/select";
|
||||
import {MatSelectModule} from '@angular/material/select';
|
||||
import {MatTooltipModule} from '@angular/material/tooltip';
|
||||
|
||||
@NgModule({
|
||||
|
||||
@@ -5,6 +5,8 @@ import {GridOptions, RowNode} from 'ag-grid-community';
|
||||
import {NgZone} from '@angular/core';
|
||||
|
||||
export class MultiPostGridDataSource {
|
||||
subscriptions: Subscription[] = [];
|
||||
|
||||
constructor(
|
||||
private ws: WsConnectionService,
|
||||
private gridOptions: GridOptions,
|
||||
@@ -12,8 +14,6 @@ export class MultiPostGridDataSource {
|
||||
) {
|
||||
}
|
||||
|
||||
subscriptions: Subscription[] = [];
|
||||
|
||||
connect() {
|
||||
this.subscriptions.push(this.ws.multiPosts$.subscribe((e: MultiPostModel[]) => {
|
||||
this.zone.run(() => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {LinkCollectorService} from '../services/link-collector.service';
|
||||
import {MultiPostGridDataSource} from './multi-post-grid-data.source';
|
||||
import {ChangeDetectionStrategy, Component, NgZone, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ChangeDetectionStrategy, Component, NgZone, OnDestroy} from '@angular/core';
|
||||
import {GridOptions} from 'ag-grid-community';
|
||||
import {WsConnectionService} from '../services/ws-connection.service';
|
||||
import {CollectorActionsRendererNative} from '../grid-custom-cells/collector-actions-renderer.native';
|
||||
@@ -32,7 +32,7 @@ export class MultiPostGridComponent implements OnDestroy {
|
||||
sort: 'asc',
|
||||
cellRenderer: 'urlCellRenderer',
|
||||
cellRendererParams: {
|
||||
electronService: this.electronService
|
||||
electronService: this.electronService
|
||||
},
|
||||
flex: 1
|
||||
}, {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
$cell-space: 8px;
|
||||
|
||||
.title-cell {
|
||||
margin-right: $cell-space;
|
||||
margin-right: $cell-space;
|
||||
}
|
||||
|
||||
.progress-cell {
|
||||
margin-left: $cell-space;
|
||||
}
|
||||
margin-left: $cell-space;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,8 @@ export class MultiPostItemsComponent {
|
||||
})
|
||||
)
|
||||
.subscribe(
|
||||
() => {},
|
||||
() => {
|
||||
},
|
||||
error => {
|
||||
this._snackBar.open(error?.error?.message || 'Unexpected error, check log file', null, {
|
||||
duration: 5000
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<div fxLayout="column" class="dialog-container" style="height: 100%;">
|
||||
<div class="dialog-container" fxLayout="column" style="height: 100%;">
|
||||
<div fxFlex="nogrow">
|
||||
<h2 class="no-wrap" mat-dialog-title>{{ dialogData.title }}</h2>
|
||||
<h2 class="no-wrap" mat-dialog-title>{{ dialogData.title }}</h2>
|
||||
</div>
|
||||
<mat-dialog-content fxFlex="grow">
|
||||
<ag-grid-angular style="width: 100%; height: 100%;" class="ag-theme-alpine" [gridOptions]="gridOptions">
|
||||
<ag-grid-angular [gridOptions]="gridOptions" class="ag-theme-alpine" style="width: 100%; height: 100%;">
|
||||
</ag-grid-angular>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions fxFlex="nogrow" align="end">
|
||||
<button mat-raised-button color="primary" (click)="onNoClick()">Close</button>
|
||||
<mat-dialog-actions align="end" fxFlex="nogrow">
|
||||
<button (click)="onNoClick()" color="primary" mat-raised-button>Close</button>
|
||||
</mat-dialog-actions>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
$cell-space: 8px;
|
||||
|
||||
.title-cell {
|
||||
margin-right: $cell-space;
|
||||
margin-right: $cell-space;
|
||||
}
|
||||
|
||||
.progress-cell {
|
||||
margin-left: $cell-space;
|
||||
}
|
||||
margin-left: $cell-space;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ import {ElectronService} from 'ngx-electron';
|
||||
})
|
||||
export class PhotosComponent implements OnInit, OnDestroy {
|
||||
|
||||
gridOptions: GridOptions;
|
||||
dataSource: PhotosDatasource;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<PhotosComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public dialogData: Post,
|
||||
@@ -79,9 +82,6 @@ export class PhotosComponent implements OnInit, OnDestroy {
|
||||
|
||||
}
|
||||
|
||||
gridOptions: GridOptions;
|
||||
dataSource: PhotosDatasource;
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user