mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
Fix imagebam
Code enhancements
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
<version>2.4.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<modules>
|
||||
<module>vripper-server</module>
|
||||
|
||||
@@ -18,7 +18,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');
|
||||
execSync('jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules java.base,java.desktop,java.instrument,java.management,java.security.jgss,java.sql,jdk.unsupported,jdk.crypto.ec --output java-runtime');
|
||||
if (process.platform === 'linux') {
|
||||
console.log('Stripping libjvm.so');
|
||||
execSync('strip -p --strip-unneeded java-runtime/lib/server/libjvm.so');
|
||||
|
||||
@@ -5,23 +5,23 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.jpa.repositories.IPostRepository;
|
||||
|
||||
@Component
|
||||
public class EventListenerBean {
|
||||
|
||||
@Getter private static boolean init = false;
|
||||
|
||||
private final DataService dataService;
|
||||
private final IPostRepository postRepository;
|
||||
|
||||
@Autowired
|
||||
public EventListenerBean(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
public EventListenerBean(IPostRepository postRepository) {
|
||||
this.postRepository = postRepository;
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
dataService.setDownloadingToStopped();
|
||||
postRepository.setDownloadingToStopped();
|
||||
init = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Event<T> {
|
||||
}
|
||||
|
||||
public static <T> Event<T> wrap(Kind kind, T data) {
|
||||
return new Event(kind, data);
|
||||
return new Event<>(kind, data);
|
||||
}
|
||||
|
||||
public enum Kind {
|
||||
|
||||
@@ -10,13 +10,13 @@ import javax.annotation.PreDestroy;
|
||||
public class EventBus {
|
||||
|
||||
public static final Sinks.EmitFailureHandler RETRY = (signalType, emitResult) -> true;
|
||||
private final Sinks.Many<Event> sink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
private final Sinks.Many<Event<?>> sink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
|
||||
public void publishEvent(Event event) {
|
||||
public void publishEvent(Event<?> event) {
|
||||
sink.emitNext(event, RETRY);
|
||||
}
|
||||
|
||||
public Flux<Event> flux() {
|
||||
public Flux<Event<?>> flux() {
|
||||
return sink.asFlux();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class ImageBamHost extends Host {
|
||||
|
||||
private static final String host = "imagebam.com";
|
||||
private static final String IMG_XPATH = "//img[contains(@class,'main-image')]";
|
||||
private static final String CONTINUE_XPATH = "//*[contains(text(), 'Continue')]";
|
||||
|
||||
private final HostService hostService;
|
||||
private final XpathService xpathService;
|
||||
@@ -47,6 +48,17 @@ public class ImageBamHost extends Host {
|
||||
HostService.Response response = hostService.getResponse(url, context);
|
||||
Document doc = response.getDocument();
|
||||
|
||||
try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_XPATH, url));
|
||||
if (xpathService.getAsNode(doc, CONTINUE_XPATH) != null) {
|
||||
// Button detected. No need to actually click it, just make the call again.
|
||||
response = hostService.getResponse(url, context);
|
||||
doc = response.getDocument();
|
||||
}
|
||||
} catch (XpathException e) {
|
||||
throw new HostException(e);
|
||||
}
|
||||
|
||||
Node imgNode;
|
||||
try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", IMG_XPATH, url));
|
||||
|
||||
@@ -70,10 +70,6 @@ public class DataService {
|
||||
});
|
||||
}
|
||||
|
||||
public void setDownloadingToStopped() {
|
||||
postRepository.setDownloadingToStopped();
|
||||
}
|
||||
|
||||
public synchronized void afterJobFinish(Image image, Post post) {
|
||||
if (image.getStatus().equals(Status.COMPLETE)) {
|
||||
post.setDone(post.getDone() + 1);
|
||||
@@ -88,6 +84,22 @@ public class DataService {
|
||||
postRepository.updateDone(done, id);
|
||||
}
|
||||
|
||||
public void updatePostStatus(Status status, Long id) {
|
||||
postRepository.updateStatus(status, id);
|
||||
}
|
||||
|
||||
public void updatePostThanks(boolean thanked, Long id) {
|
||||
postRepository.updateThanked(thanked, id);
|
||||
}
|
||||
|
||||
public void updatePostTitle(String title, Long id) {
|
||||
postRepository.updateTitle(title, id);
|
||||
}
|
||||
|
||||
public void updatePostDownloadDirectory(String postFolderName, Long id) {
|
||||
postRepository.updateFolderName(postFolderName, id);
|
||||
}
|
||||
|
||||
public void finishPost(@NonNull Post post) {
|
||||
if (!imageRepository.findByPostIdAndIsError(post.getPostId()).isEmpty()) {
|
||||
post.setStatus(Status.ERROR);
|
||||
@@ -203,22 +215,6 @@ public class DataService {
|
||||
imageRepository.updateTotal(total, id);
|
||||
}
|
||||
|
||||
public void updatePostStatus(Status status, Long id) {
|
||||
postRepository.updateStatus(status, id);
|
||||
}
|
||||
|
||||
public void updateDownloadDirectory(String postFolderName, Long id) {
|
||||
postRepository.updateFolderName(postFolderName, id);
|
||||
}
|
||||
|
||||
public void updatePostTitle(String title, Long id) {
|
||||
postRepository.updateTitle(title, id);
|
||||
}
|
||||
|
||||
public void updatePostThanked(boolean thanked, Long id) {
|
||||
postRepository.updateThanked(thanked, id);
|
||||
}
|
||||
|
||||
public Optional<LogEvent> findEventById(Long id) {
|
||||
return eventRepository.findById(id);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PathService {
|
||||
downloadDirectory = makeDir(downloadDirectory);
|
||||
post.setDownloadDirectory(
|
||||
downloadDirectory.getAbsolutePath().replace(settings.getDownloadPath(), ""));
|
||||
dataService.updateDownloadDirectory(post.getDownloadDirectory(), post.getId());
|
||||
dataService.updatePostDownloadDirectory(post.getDownloadDirectory(), post.getId());
|
||||
}
|
||||
|
||||
public final void rename(@NonNull String postId, @NonNull String altName, Settings settings)
|
||||
@@ -78,7 +78,7 @@ public class PathService {
|
||||
StandardCopyOption.ATOMIC_MOVE);
|
||||
post.setDownloadDirectory(
|
||||
newDownloadDirectory.getAbsolutePath().replace(settings.getDownloadPath(), ""));
|
||||
dataService.updateDownloadDirectory(post.getDownloadDirectory(), post.getId());
|
||||
dataService.updatePostDownloadDirectory(post.getDownloadDirectory(), post.getId());
|
||||
|
||||
post.setTitle(altName);
|
||||
dataService.updatePostTitle(post.getTitle(), post.getId());
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ public class LeaveThanksRunnable implements Runnable {
|
||||
try (CloseableHttpResponse response = client.execute(postThanks, context)) {
|
||||
if (response.getStatusLine().getStatusCode() / 100 == 2) {
|
||||
post.setThanked(true);
|
||||
dataService.updatePostThanked(post.isThanked(), post.getId());
|
||||
dataService.updatePostThanks(post.isThanked(), post.getId());
|
||||
}
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import tn.mnlr.vripper.event.Event;
|
||||
import tn.mnlr.vripper.event.EventBus;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.services.DownloadSpeedService;
|
||||
import tn.mnlr.vripper.services.GlobalStateService;
|
||||
import tn.mnlr.vripper.services.domain.DownloadSpeed;
|
||||
import tn.mnlr.vripper.services.domain.GlobalState;
|
||||
|
||||
@@ -34,12 +32,7 @@ public class DataBroadcast {
|
||||
private Disposable disposable;
|
||||
|
||||
@Autowired
|
||||
public DataBroadcast(
|
||||
SimpMessagingTemplate template,
|
||||
GlobalStateService globalStateService,
|
||||
DownloadSpeedService downloadSpeedService,
|
||||
DataService dataService,
|
||||
EventBus eventBus) {
|
||||
public DataBroadcast(SimpMessagingTemplate template, DataService dataService, EventBus eventBus) {
|
||||
this.template = template;
|
||||
this.dataService = dataService;
|
||||
this.eventBus = eventBus;
|
||||
@@ -54,7 +47,7 @@ public class DataBroadcast {
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
.subscribe(
|
||||
data -> {
|
||||
Map<Event.Kind, List<Event>> eventMap =
|
||||
Map<Event.Kind, List<Event<?>>> eventMap =
|
||||
data.stream().collect(Collectors.groupingBy(Event::getKind));
|
||||
|
||||
eventMap.forEach(
|
||||
|
||||
Reference in New Issue
Block a user