mirror of
https://github.com/dev-claw/vripper-project.git
synced 2026-08-19 08:35:41 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58a40682cc | ||
|
|
ccc4032bb0 | ||
|
|
1c5b8a0397 | ||
|
|
cc2ce9482d | ||
|
|
41f1775360 | ||
|
|
733f1a08ac | ||
|
|
0cb0ee0100 | ||
|
|
cb88e39c83 | ||
|
|
6375c0aed6 | ||
|
|
40ca4cf86b | ||
|
|
b3a798388b | ||
|
|
6e69b2bce8 | ||
|
|
bb6dcd77b9 |
@@ -1,5 +1,48 @@
|
||||
# Changelog
|
||||
|
||||
## [3.3.3] - 2021-03-13
|
||||
|
||||
### Changed
|
||||
|
||||
- Remove unnecessary event logs
|
||||
|
||||
## [3.3.2] - 2021-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix a bug with event logs
|
||||
- Change event names and add some icons
|
||||
|
||||
## [3.3.1] - 2021-02-18
|
||||
|
||||
### Added
|
||||
|
||||
- Add about menu
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix README.md
|
||||
|
||||
## [3.3.0] - 2021-02-16
|
||||
|
||||
### Changed
|
||||
|
||||
- Add support for proxies
|
||||
- Add a Event Logs
|
||||
- Fix bugs with the database
|
||||
|
||||
## [3.2.3] - 2021-01-13
|
||||
|
||||
### Changed
|
||||
|
||||
- Finished posts are not cleared from the UI
|
||||
|
||||
## [3.2.2] - 2021-01-13
|
||||
|
||||
### Changed
|
||||
|
||||
- Set total download to max value
|
||||
|
||||
## [3.2.1] - 2021-01-12
|
||||
### Added
|
||||
- Add settings for connection timeout
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Viper Ripper!
|
||||
# VRipper!
|
||||
|
||||
This is my spin for a cross platform gallery ripper app for [vipergirls](https://vipergirls.to) website.
|
||||
The purpose of this project is to build a robust and clean application to conveniently download photo galleries using modern web technologies, Java + Spring boot for the back end and angular + electron for the front end.
|
||||
@@ -15,10 +15,16 @@ Most people will be interested only on the desktop app, however if you have a na
|
||||
To build the server app:
|
||||
|
||||
mvn clean install -DskipTests
|
||||
|
||||
To build the desktop app:
|
||||
|
||||
mvn clean install -Pelectron -DskipTests
|
||||
|
||||
Maven will automatically handle front end compilation. However, for development, you will need to install a recent version of nodejs on your system.
|
||||
Maven will automatically handle front end compilation. However, for development, you will need to install a recent
|
||||
version of nodejs on your system.
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SC7M5LNWZ528Q)
|
||||
If you feel generous and want to support me, you can donate some coins, and I would be very grateful 🙏
|
||||
|
||||
I accept Bitcoin (BTC) for donations, following is my address
|
||||
|
||||
bc1q9jzzw3st49r9vmxgtylq4vrd67cl7zfclf3lsq
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>pom</packaging>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Generated
-2486
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vripper-electron",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.3",
|
||||
"description": "A ripper for vipergirls.to built using web technolgies",
|
||||
"main": "main.js",
|
||||
"author": "death-claw <53543762+death-claw@users.noreply.github.com>",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.3</version>
|
||||
</parent>
|
||||
<artifactId>vripper-electron</artifactId>
|
||||
<name>vripper-electron</name>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.3</version>
|
||||
</parent>
|
||||
<artifactId>vripper-server</artifactId>
|
||||
<name>vripper-server</name>
|
||||
|
||||
@@ -27,10 +27,7 @@ public class EventListenerBean {
|
||||
|
||||
@EventListener
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
repositorySet.forEach(IRepository::init);
|
||||
dataService.setDownloadingToStopped();
|
||||
init = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package tn.mnlr.vripper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
@Slf4j
|
||||
public class Utils {
|
||||
|
||||
public static String throwableToString(Throwable th) {
|
||||
try (StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter)) {
|
||||
th.printStackTrace(printWriter);
|
||||
printWriter.flush();
|
||||
stringWriter.flush();
|
||||
return stringWriter.toString();
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to convert throwable to string", e);
|
||||
}
|
||||
return "Cannot display error, please check the log file for details";
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class DownloadJob implements CheckedRunnable {
|
||||
private final Image image;
|
||||
@Getter
|
||||
private final Post post;
|
||||
private boolean stopped = false;
|
||||
private volatile boolean stopped = false;
|
||||
@Getter
|
||||
private boolean finished = false;
|
||||
|
||||
|
||||
@@ -3,16 +3,22 @@ package tn.mnlr.vripper.download;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.jodah.failsafe.Failsafe;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.Utils;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.enums.Status;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
import tn.mnlr.vripper.services.ConnectionService;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Slf4j
|
||||
public class DownloadRunnable implements Runnable {
|
||||
|
||||
private final DownloadService downloadService;
|
||||
private final DataService dataService;
|
||||
private final ConnectionService connectionService;
|
||||
private final IEventRepository eventRepository;
|
||||
|
||||
private final DownloadJob downloadJob;
|
||||
|
||||
@@ -20,6 +26,8 @@ public class DownloadRunnable implements Runnable {
|
||||
downloadService = SpringContext.getBean(DownloadService.class);
|
||||
dataService = SpringContext.getBean(DataService.class);
|
||||
connectionService = SpringContext.getBean(ConnectionService.class);
|
||||
eventRepository = SpringContext.getBean(IEventRepository.class);
|
||||
|
||||
this.downloadJob = downloadJob;
|
||||
}
|
||||
|
||||
@@ -27,6 +35,12 @@ public class DownloadRunnable implements Runnable {
|
||||
public void run() {
|
||||
Failsafe.with(connectionService.getRetryPolicy())
|
||||
.onFailure(e -> {
|
||||
try {
|
||||
Event event = new Event(Event.Type.DOWNLOAD, Event.Status.ERROR, LocalDateTime.now(), String.format("Failed to download %s\n %s", downloadJob.getImage().getUrl(), Utils.throwableToString(e.getFailure())));
|
||||
eventRepository.save(event);
|
||||
} catch (Exception exp) {
|
||||
log.error("Failed to save event", exp);
|
||||
}
|
||||
log.error(String.format("Failed to download %s after %d tries", downloadJob.getImage().getUrl(), e.getAttemptCount()), e.getFailure());
|
||||
downloadJob.getImage().setStatus(Status.ERROR);
|
||||
dataService.updateImageStatus(downloadJob.getImage().getStatus(), downloadJob.getImage().getId());
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package tn.mnlr.vripper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class EventRemoveEvent extends ApplicationEvent {
|
||||
|
||||
private final Long id;
|
||||
|
||||
public EventRemoveEvent(Object source, Long id) {
|
||||
super(source);
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package tn.mnlr.vripper.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@Getter
|
||||
public class EventUpdateEvent extends ApplicationEvent {
|
||||
|
||||
private final Long id;
|
||||
|
||||
public EventUpdateEvent(Object source, Long id) {
|
||||
super(source);
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,10 @@ 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) {
|
||||
public MetadataUpdateEvent(Object source, Long postIdRef) {
|
||||
super(source);
|
||||
this.id = id;
|
||||
this.postIdRef = postIdRef;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ public class ImxHost extends Host {
|
||||
try {
|
||||
log.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
|
||||
contDiv = xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH);
|
||||
if (contDiv == null) {
|
||||
throw new HostException(CONTINUE_BUTTON_XPATH + " cannot be found");
|
||||
}
|
||||
Node node = contDiv.getAttributes().getNamedItem("value");
|
||||
if (node != null) {
|
||||
value = node.getTextContent();
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package tn.mnlr.vripper.jpa.domain;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class Event {
|
||||
|
||||
private Long id;
|
||||
private Type type;
|
||||
private Status status;
|
||||
@JsonSerialize(using = DateTimeSerializer.class)
|
||||
private LocalDateTime time;
|
||||
private String message;
|
||||
|
||||
public Event(Type type, Status status, LocalDateTime time, String message) {
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.time = time;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
POST,
|
||||
QUEUED,
|
||||
THANKS,
|
||||
METADATA,
|
||||
SCAN,
|
||||
DOWNLOAD,
|
||||
|
||||
// Below are deprecated events
|
||||
METADATA_CACHE_MISS,
|
||||
QUEUED_CACHE_MISS
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
PENDING, PROCESSING, DONE, ERROR
|
||||
}
|
||||
}
|
||||
|
||||
class DateTimeSerializer extends StdSerializer<LocalDateTime> {
|
||||
|
||||
private final static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.SSS");
|
||||
|
||||
protected DateTimeSerializer() {
|
||||
super(LocalDateTime.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
gen.writeString(value.format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package tn.mnlr.vripper.jpa.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -13,12 +12,20 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
public class Metadata {
|
||||
|
||||
@JsonIgnore
|
||||
private Long id;
|
||||
private Long postIdRef;
|
||||
|
||||
private List<String> resolvedNames = Collections.emptyList();
|
||||
private String postId;
|
||||
|
||||
private String postedBy;
|
||||
|
||||
private Long postIdRef;
|
||||
private List<String> resolvedNames = Collections.emptyList();
|
||||
|
||||
public static Metadata from(Metadata metadata) {
|
||||
Metadata copy = new Metadata();
|
||||
copy.postIdRef = metadata.postIdRef;
|
||||
copy.postId = metadata.postId;
|
||||
copy.postedBy = metadata.postedBy;
|
||||
copy.resolvedNames = List.copyOf(metadata.resolvedNames);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package tn.mnlr.vripper.jpa.repositories;
|
||||
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IEventRepository extends IRepository {
|
||||
|
||||
Event save(Event event);
|
||||
|
||||
Event update(Event event);
|
||||
|
||||
List<Event> findAll();
|
||||
|
||||
Optional<Event> findById(Long id);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void deleteAll();
|
||||
}
|
||||
@@ -8,8 +8,6 @@ public interface IMetadataRepository extends IRepository {
|
||||
|
||||
Metadata save(Metadata metadata);
|
||||
|
||||
Optional<Metadata> findById(Long id);
|
||||
|
||||
Optional<Metadata> findByPostId(String postId);
|
||||
|
||||
int deleteByPostId(String postId);
|
||||
|
||||
@@ -15,4 +15,6 @@ public interface IQueuedRepository extends IRepository {
|
||||
Optional<Queued> findById(Long id);
|
||||
|
||||
int deleteByThreadId(String threadId);
|
||||
|
||||
void deleteAll();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
package tn.mnlr.vripper.jpa.repositories;
|
||||
|
||||
public interface IRepository {
|
||||
|
||||
void init();
|
||||
}
|
||||
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
package tn.mnlr.vripper.jpa.repositories.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tn.mnlr.vripper.event.EventRemoveEvent;
|
||||
import tn.mnlr.vripper.event.EventUpdateEvent;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EventRepository implements IEventRepository, ApplicationEventPublisherAware {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final SettingsService settingsService;
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
public EventRepository(JdbcTemplate jdbcTemplate, SettingsService settingsService) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.settingsService = settingsService;
|
||||
}
|
||||
|
||||
private synchronized Long nextId() {
|
||||
return jdbcTemplate.queryForObject(
|
||||
"CALL NEXT VALUE FOR SEQ_EVENT",
|
||||
Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Event save(@NonNull Event event) {
|
||||
|
||||
int maxRecords = settingsService.getSettings().getMaxEventLog() - 1;
|
||||
|
||||
Long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EVENT", Long.class);
|
||||
if (count > maxRecords) {
|
||||
List<Long> idList = jdbcTemplate.queryForList("SELECT ID FROM EVENT ORDER BY TIME ASC LIMIT ?", Long.class, count - maxRecords);
|
||||
idList.forEach(this::delete);
|
||||
}
|
||||
|
||||
long id = nextId();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO EVENT (ID, TYPE, STATUS, TIME, MESSAGE) VALUES (?,?,?,?,?)",
|
||||
id,
|
||||
event.getType().name(),
|
||||
event.getStatus().name(),
|
||||
event.getTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
|
||||
event.getMessage()
|
||||
);
|
||||
event.setId(id);
|
||||
applicationEventPublisher.publishEvent(new EventUpdateEvent(EventRepository.class, id));
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event update(@NonNull Event event) {
|
||||
if (event.getId() == null) {
|
||||
log.warn("Cannot update entity with null id");
|
||||
return event;
|
||||
}
|
||||
|
||||
jdbcTemplate.update(
|
||||
"UPDATE EVENT SET TYPE = ?, STATUS = ?, TIME = ?, MESSAGE = ? WHERE ID = ?",
|
||||
event.getType().name(),
|
||||
event.getStatus().name(),
|
||||
event.getTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
|
||||
event.getMessage(),
|
||||
event.getId()
|
||||
);
|
||||
applicationEventPublisher.publishEvent(new EventUpdateEvent(EventRepository.class, event.getId()));
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Event> findById(Long id) {
|
||||
List<Event> events = jdbcTemplate.query(
|
||||
"SELECT * FROM EVENT WHERE ID = ?",
|
||||
new EventRowMapper(),
|
||||
id);
|
||||
if (events.isEmpty()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return Optional.of(events.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Event> findAll() {
|
||||
return jdbcTemplate.query(
|
||||
"SELECT * FROM EVENT",
|
||||
new EventRowMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
jdbcTemplate.update("DELETE FROM EVENT WHERE ID = ?", id);
|
||||
applicationEventPublisher.publishEvent(new EventRemoveEvent(EventRepository.class, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll() {
|
||||
jdbcTemplate.update("DELETE FROM EVENT");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package tn.mnlr.vripper.jpa.repositories.impl;
|
||||
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class EventRowMapper implements RowMapper<Event> {
|
||||
|
||||
@Override
|
||||
public Event mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Event event = new Event();
|
||||
event.setId(rs.getLong("ID"));
|
||||
event.setType(Event.Type.valueOf(rs.getString("TYPE")));
|
||||
event.setStatus(Event.Status.valueOf(rs.getString("STATUS")));
|
||||
event.setTime(LocalDateTime.parse(rs.getString("TIME"), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||
event.setMessage(rs.getString("MESSAGE"));
|
||||
return event;
|
||||
}
|
||||
}
|
||||
+7
-14
@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tn.mnlr.vripper.event.ImageUpdateEvent;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
@@ -12,13 +13,11 @@ import tn.mnlr.vripper.jpa.repositories.IImageRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Service
|
||||
public class ImageRepository implements IImageRepository, ApplicationEventPublisherAware {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final AtomicLong counter = new AtomicLong(0);
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Autowired
|
||||
@@ -26,21 +25,15 @@ public class ImageRepository implements IImageRepository, ApplicationEventPublis
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Long maxId = jdbcTemplate.queryForObject(
|
||||
"SELECT MAX(ID) FROM IMAGE",
|
||||
Long.class
|
||||
);
|
||||
if (maxId == null) {
|
||||
maxId = 0L;
|
||||
}
|
||||
counter.set(maxId);
|
||||
private synchronized Long nextId() {
|
||||
return jdbcTemplate.queryForObject(
|
||||
"CALL NEXT VALUE FOR SEQ_IMAGE",
|
||||
Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image save(Image image) {
|
||||
long id = counter.incrementAndGet();
|
||||
long id = nextId();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO IMAGE (ID, CURRENT, HOST, INDEX, POST_ID, STATUS, TOTAL, URL, POST_ID_REF) VALUES (?,?,?,?,?,?,?,?,?)",
|
||||
id,
|
||||
@@ -147,7 +140,7 @@ public class ImageRepository implements IImageRepository, ApplicationEventPublis
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-39
@@ -11,13 +11,11 @@ import tn.mnlr.vripper.jpa.repositories.IMetadataRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Service
|
||||
public class MetadataRepository implements IMetadataRepository, ApplicationEventPublisherAware {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final AtomicLong counter = new AtomicLong(0);
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Autowired
|
||||
@@ -25,53 +23,25 @@ public class MetadataRepository implements IMetadataRepository, ApplicationEvent
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Long maxId = jdbcTemplate.queryForObject(
|
||||
"SELECT MAX(ID) FROM IMAGE",
|
||||
Long.class
|
||||
);
|
||||
if (maxId == null) {
|
||||
maxId = 0L;
|
||||
}
|
||||
counter.set(maxId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metadata save(Metadata metadata) {
|
||||
long id = counter.incrementAndGet();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO METADATA (ID, POSTED_BY, RESOLVED_NAMES, POST_ID_REF) VALUES (?,?,?,?)",
|
||||
id,
|
||||
"INSERT INTO METADATA (POST_ID_REF, POST_ID, POSTED_BY, RESOLVED_NAMES) VALUES (?,?,?,?)",
|
||||
metadata.getPostIdRef(),
|
||||
metadata.getPostId(),
|
||||
metadata.getPostedBy(),
|
||||
String.join("%sep%", metadata.getResolvedNames()),
|
||||
metadata.getPostIdRef()
|
||||
String.join("%sep%", metadata.getResolvedNames())
|
||||
);
|
||||
metadata.setId(id);
|
||||
applicationEventPublisher.publishEvent(new MetadataUpdateEvent(MetadataRepository.class, id, metadata.getPostIdRef()));
|
||||
applicationEventPublisher.publishEvent(new MetadataUpdateEvent(MetadataRepository.class, metadata.getPostIdRef()));
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Metadata> findById(Long id) {
|
||||
List<Metadata> metadata = jdbcTemplate.query(
|
||||
"SELECT * FROM METADATA AS metadata WHERE metadata.ID = ?",
|
||||
new Object[]{id},
|
||||
new MetadataRowMapper()
|
||||
);
|
||||
if (metadata.isEmpty()) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return Optional.of(metadata.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Metadata> findByPostId(String postId) {
|
||||
List<Metadata> metadata = jdbcTemplate.query(
|
||||
"SELECT metadata.* FROM METADATA AS metadata INNER JOIN POST post ON post.ID = metadata.POST_ID_REF WHERE post.POST_ID = ?",
|
||||
new Object[]{postId},
|
||||
new MetadataRowMapper()
|
||||
"SELECT metadata.* FROM METADATA AS metadata WHERE metadata.POST_ID = ?",
|
||||
new MetadataRowMapper(),
|
||||
postId
|
||||
);
|
||||
if (metadata.isEmpty()) {
|
||||
return Optional.empty();
|
||||
@@ -83,7 +53,7 @@ public class MetadataRepository implements IMetadataRepository, ApplicationEvent
|
||||
@Override
|
||||
public int deleteByPostId(String postId) {
|
||||
return jdbcTemplate.update(
|
||||
"DELETE FROM METADATA AS metadata WHERE metadata.ID = (SELECT inner_metadata.ID FROM POST AS post INNER JOIN METADATA inner_metadata ON post.ID = inner_metadata.POST_ID_REF WHERE post.POST_ID = ?)",
|
||||
"DELETE FROM METADATA AS metadata WHERE metadata.POST_ID = ?",
|
||||
postId
|
||||
);
|
||||
}
|
||||
|
||||
+2
-2
@@ -12,13 +12,13 @@ public class MetadataRowMapper implements RowMapper<Metadata> {
|
||||
@Override
|
||||
public Metadata mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Metadata metadata = new Metadata();
|
||||
metadata.setId(rs.getLong("ID"));
|
||||
metadata.setPostIdRef(rs.getLong("POST_ID_REF"));
|
||||
metadata.setPostId(rs.getString("POST_ID"));
|
||||
metadata.setPostedBy(rs.getString("POSTED_BY"));
|
||||
String resolvedNames = rs.getString("RESOLVED_NAMES");
|
||||
if (resolvedNames != null && !resolvedNames.isBlank()) {
|
||||
metadata.setResolvedNames(List.of(resolvedNames.split("%sep%")));
|
||||
}
|
||||
metadata.setPostIdRef(rs.getLong("POST_ID_REF"));
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-16
@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tn.mnlr.vripper.event.PostRemoveEvent;
|
||||
import tn.mnlr.vripper.event.PostUpdateEvent;
|
||||
@@ -13,13 +14,11 @@ import tn.mnlr.vripper.jpa.repositories.IPostRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Service
|
||||
public class PostRepository implements IPostRepository, ApplicationEventPublisherAware {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final AtomicLong counter = new AtomicLong(0);
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Autowired
|
||||
@@ -28,21 +27,15 @@ public class PostRepository implements IPostRepository, ApplicationEventPublishe
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Long maxId = jdbcTemplate.queryForObject(
|
||||
"SELECT MAX(ID) FROM POST",
|
||||
Long.class
|
||||
);
|
||||
if (maxId == null) {
|
||||
maxId = 0L;
|
||||
}
|
||||
counter.set(maxId);
|
||||
private synchronized Long nextId() {
|
||||
return jdbcTemplate.queryForObject(
|
||||
"CALL NEXT VALUE FOR SEQ_POST",
|
||||
Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Post save(Post post) {
|
||||
long id = counter.incrementAndGet();
|
||||
long id = nextId();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO POST (ID, DONE, FORUM, HOSTS, POST_FOLDER_NAME, POST_ID, PREVIEWS, SECURITY_TOKEN, STATUS, THANKED, THREAD_ID, THREAD_TITLE, TITLE, TOTAL, URL) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
||||
id,
|
||||
@@ -69,7 +62,7 @@ public class PostRepository implements IPostRepository, ApplicationEventPublishe
|
||||
@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 = ?",
|
||||
"SELECT metadata.*,post.* FROM METADATA metadata FULL JOIN POST post ON metadata.POST_ID_REF = post.ID WHERE post.POST_ID = ?",
|
||||
new PostRowMapper(),
|
||||
postId);
|
||||
if (posts.isEmpty()) {
|
||||
@@ -82,7 +75,7 @@ public class PostRepository implements IPostRepository, ApplicationEventPublishe
|
||||
@Override
|
||||
public List<String> findCompleted() {
|
||||
return jdbcTemplate.query(
|
||||
"SELECT POST_ID FROM POST WHERE status = 'COMPLETE' AND done >= total",
|
||||
"SELECT POST_ID FROM POST AS post WHERE status = 'COMPLETE' AND done >= total",
|
||||
((rs, rowNum) -> rs.getString("POST_ID"))
|
||||
);
|
||||
}
|
||||
@@ -189,7 +182,7 @@ public class PostRepository implements IPostRepository, ApplicationEventPublishe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
public void setApplicationEventPublisher(@NonNull ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -19,34 +19,34 @@ public class PostRowMapper implements RowMapper<Post> {
|
||||
|
||||
Post post = new Post();
|
||||
post.setId(rs.getLong("post.ID"));
|
||||
post.setStatus(Status.valueOf(rs.getString("STATUS")));
|
||||
post.setPostId(rs.getString("POST_ID"));
|
||||
post.setThreadTitle(rs.getString("THREAD_TITLE"));
|
||||
post.setThreadId(rs.getString("THREAD_ID"));
|
||||
post.setTitle(rs.getString("TITLE"));
|
||||
post.setUrl(rs.getString("URL"));
|
||||
post.setDone(rs.getInt("DONE"));
|
||||
post.setTotal(rs.getInt("TOTAL"));
|
||||
post.setHosts(Set.of(rs.getString("HOSTS").split(DELIMITER)));
|
||||
post.setForum(rs.getString("FORUM"));
|
||||
post.setSecurityToken(rs.getString("SECURITY_TOKEN"));
|
||||
post.setDownloadDirectory(rs.getString("POST_FOLDER_NAME"));
|
||||
post.setThanked(rs.getBoolean("THANKED"));
|
||||
post.setStatus(Status.valueOf(rs.getString("post.STATUS")));
|
||||
post.setPostId(rs.getString("post.POST_ID"));
|
||||
post.setThreadTitle(rs.getString("post.THREAD_TITLE"));
|
||||
post.setThreadId(rs.getString("post.THREAD_ID"));
|
||||
post.setTitle(rs.getString("post.TITLE"));
|
||||
post.setUrl(rs.getString("post.URL"));
|
||||
post.setDone(rs.getInt("post.DONE"));
|
||||
post.setTotal(rs.getInt("post.TOTAL"));
|
||||
post.setHosts(Set.of(rs.getString("post.HOSTS").split(DELIMITER)));
|
||||
post.setForum(rs.getString("post.FORUM"));
|
||||
post.setSecurityToken(rs.getString("post.SECURITY_TOKEN"));
|
||||
post.setDownloadDirectory(rs.getString("post.POST_FOLDER_NAME"));
|
||||
post.setThanked(rs.getBoolean("post.THANKED"));
|
||||
String previews;
|
||||
if ((previews = rs.getString("PREVIEWS")) != null) {
|
||||
if ((previews = rs.getString("post.PREVIEWS")) != null) {
|
||||
post.setPreviews(Set.of(previews.split(DELIMITER)));
|
||||
}
|
||||
|
||||
Long metadataId = rs.getLong("metadata.ID");
|
||||
Long metadataId = rs.getLong("metadata.POST_ID_REF");
|
||||
if (!rs.wasNull()) {
|
||||
Metadata metadata = new Metadata();
|
||||
metadata.setId(metadataId);
|
||||
metadata.setPostIdRef(rs.getLong("POST_ID_REF"));
|
||||
String resolvedNames = rs.getString("RESOLVED_NAMES");
|
||||
metadata.setPostIdRef(metadataId);
|
||||
metadata.setPostId(rs.getString("metadata.POST_ID"));
|
||||
String resolvedNames = rs.getString("metadata.RESOLVED_NAMES");
|
||||
if (resolvedNames != null && !resolvedNames.isBlank()) {
|
||||
metadata.setResolvedNames(List.of(resolvedNames.split("%sep%")));
|
||||
}
|
||||
metadata.setPostedBy(rs.getString("POSTED_BY"));
|
||||
metadata.setPostedBy(rs.getString("metadata.POSTED_BY"));
|
||||
post.setMetadata(metadata);
|
||||
}
|
||||
|
||||
|
||||
+10
-13
@@ -12,13 +12,11 @@ import tn.mnlr.vripper.jpa.repositories.IQueuedRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Service
|
||||
public class QueuedRepository implements IQueuedRepository, ApplicationEventPublisherAware {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final AtomicLong counter = new AtomicLong(0);
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Autowired
|
||||
@@ -26,21 +24,15 @@ public class QueuedRepository implements IQueuedRepository, ApplicationEventPubl
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
Long maxId = jdbcTemplate.queryForObject(
|
||||
"SELECT MAX(ID) FROM QUEUED",
|
||||
Long.class
|
||||
);
|
||||
if (maxId == null) {
|
||||
maxId = 0L;
|
||||
}
|
||||
counter.set(maxId);
|
||||
private synchronized Long nextId() {
|
||||
return jdbcTemplate.queryForObject(
|
||||
"CALL NEXT VALUE FOR SEQ_QUEUED",
|
||||
Long.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queued save(Queued queued) {
|
||||
long id = counter.incrementAndGet();
|
||||
long id = nextId();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO QUEUED (ID, TOTAL, LINK, LOADING, POST_ID, THREAD_ID) values (?,?,?,?,?,?)",
|
||||
id,
|
||||
@@ -101,6 +93,11 @@ public class QueuedRepository implements IQueuedRepository, ApplicationEventPubl
|
||||
return mutationCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll() {
|
||||
jdbcTemplate.update("DELETE FROM QUEUED");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package tn.mnlr.vripper.listener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Sinks;
|
||||
import tn.mnlr.vripper.event.EventRemoveEvent;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EventRemoveEventListener implements ApplicationListener<EventRemoveEvent>, DataEventListener<EventRemoveEvent> {
|
||||
|
||||
private final Sinks.Many<EventRemoveEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EventRemoveEvent event) {
|
||||
sink.emitNext(event, EmitHandler.RETRY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<EventRemoveEvent> getDataFlux() {
|
||||
return sink.asFlux();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
private void destroy() {
|
||||
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package tn.mnlr.vripper.listener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Sinks;
|
||||
import tn.mnlr.vripper.event.EventUpdateEvent;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EventUpdateEventListener implements ApplicationListener<EventUpdateEvent>, DataEventListener<EventUpdateEvent> {
|
||||
|
||||
private final Sinks.Many<EventUpdateEvent> sink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(@NonNull EventUpdateEvent event) {
|
||||
sink.emitNext(event, EmitHandler.RETRY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<EventUpdateEvent> getDataFlux() {
|
||||
return sink.asFlux();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
private void destroy() {
|
||||
sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,8 @@ public class ConnectionService {
|
||||
|
||||
private void buildConnectionPool() {
|
||||
pcm = new PoolingHttpClientConnectionManager();
|
||||
pcm.setMaxTotal(Integer.MAX_VALUE);
|
||||
pcm.setDefaultMaxPerRoute(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
private void buildRequestConfig() {
|
||||
|
||||
@@ -5,15 +5,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.jpa.domain.Metadata;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
import tn.mnlr.vripper.jpa.domain.*;
|
||||
import tn.mnlr.vripper.jpa.domain.enums.Status;
|
||||
import tn.mnlr.vripper.jpa.repositories.IImageRepository;
|
||||
import tn.mnlr.vripper.jpa.repositories.IMetadataRepository;
|
||||
import tn.mnlr.vripper.jpa.repositories.IPostRepository;
|
||||
import tn.mnlr.vripper.jpa.repositories.IQueuedRepository;
|
||||
import tn.mnlr.vripper.jpa.repositories.impl.EventRepository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -29,14 +27,16 @@ public class DataService {
|
||||
private final IQueuedRepository queuedRepository;
|
||||
private final IMetadataRepository metadataRepository;
|
||||
private final SettingsService settingsService;
|
||||
private final EventRepository eventRepository;
|
||||
|
||||
@Autowired
|
||||
public DataService(IPostRepository postRepository, IImageRepository imageRepository, IQueuedRepository queuedRepository, IMetadataRepository metadataRepository, SettingsService settingsService) {
|
||||
public DataService(IPostRepository postRepository, IImageRepository imageRepository, IQueuedRepository queuedRepository, IMetadataRepository metadataRepository, SettingsService settingsService, EventRepository eventRepository) {
|
||||
this.postRepository = postRepository;
|
||||
this.imageRepository = imageRepository;
|
||||
this.queuedRepository = queuedRepository;
|
||||
this.metadataRepository = metadataRepository;
|
||||
this.settingsService = settingsService;
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
|
||||
private void save(Post post) {
|
||||
@@ -142,7 +142,7 @@ public class DataService {
|
||||
return imageRepository.findByPostId(postId);
|
||||
}
|
||||
|
||||
public Iterable<Post> findAllPosts() {
|
||||
public List<Post> findAllPosts() {
|
||||
return postRepository.findAll();
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class DataService {
|
||||
return queuedRepository.findByThreadId(threadId);
|
||||
}
|
||||
|
||||
public Iterable<Queued> findAllQueued() {
|
||||
public List<Queued> findAllQueued() {
|
||||
return queuedRepository.findAll();
|
||||
}
|
||||
|
||||
@@ -174,9 +174,11 @@ public class DataService {
|
||||
return queuedRepository.findById(aLong);
|
||||
}
|
||||
|
||||
public void setMetadata(Post post, Metadata metadata) {
|
||||
metadata.setPostIdRef(post.getId());
|
||||
metadataRepository.save(metadata);
|
||||
public synchronized void setMetadata(Post post, Metadata metadata) {
|
||||
if (metadataRepository.findByPostId(post.getPostId()).isEmpty()) {
|
||||
metadata.setPostIdRef(post.getId());
|
||||
metadataRepository.save(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Metadata> findMetadataByPostId(String postId) {
|
||||
@@ -210,4 +212,16 @@ public class DataService {
|
||||
public void updatePostThanked(boolean thanked, Long id) {
|
||||
postRepository.updateThanked(thanked, id);
|
||||
}
|
||||
|
||||
public Optional<Event> findEventById(Long id) {
|
||||
return eventRepository.findById(id);
|
||||
}
|
||||
|
||||
public List<Event> findAllEvents() {
|
||||
return eventRepository.findAll();
|
||||
}
|
||||
|
||||
public void clearQueueLinks() {
|
||||
queuedRepository.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.jodah.failsafe.Failsafe;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -19,11 +18,10 @@ import tn.mnlr.vripper.exception.DownloadException;
|
||||
import tn.mnlr.vripper.exception.PostParseException;
|
||||
import tn.mnlr.vripper.jpa.domain.Metadata;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.services.domain.tasks.MetadataRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -39,12 +37,15 @@ public class MetadataService {
|
||||
private final VGAuthService VGAuthService;
|
||||
private final HtmlProcessorService htmlProcessorService;
|
||||
private final XpathService xpathService;
|
||||
@Autowired
|
||||
public MetadataService(ConnectionService cm, VGAuthService VGAuthService, HtmlProcessorService htmlProcessorService, XpathService xpathService) {
|
||||
private final Map<String, MetadataRunnable> fetchingMetadata = new ConcurrentHashMap<>();
|
||||
private final ThreadPoolService threadPoolService;
|
||||
|
||||
public MetadataService(ConnectionService cm, VGAuthService VGAuthService, HtmlProcessorService htmlProcessorService, XpathService xpathService, ThreadPoolService threadPoolService) {
|
||||
this.cm = cm;
|
||||
this.VGAuthService = VGAuthService;
|
||||
this.htmlProcessorService = htmlProcessorService;
|
||||
this.xpathService = xpathService;
|
||||
this.threadPoolService = threadPoolService;
|
||||
|
||||
CacheLoader<Key, Metadata> loader = new CacheLoader<>() {
|
||||
@Override
|
||||
@@ -58,11 +59,23 @@ public class MetadataService {
|
||||
}
|
||||
|
||||
public Metadata get(Post post) throws ExecutionException {
|
||||
Metadata metadata = new Metadata();
|
||||
Metadata cachedMetadata = cache.get(new Key(post.getPostId(), post.getThreadId(), post.getUrl()));
|
||||
metadata.setPostedBy(cachedMetadata.getPostedBy());
|
||||
metadata.setResolvedNames(List.copyOf(cachedMetadata.getResolvedNames()));
|
||||
return metadata;
|
||||
Key key = new Key(post.getPostId(), post.getThreadId(), post.getUrl());
|
||||
return Metadata.from(cache.get(key));
|
||||
}
|
||||
|
||||
public void startFetchingMetadata(Post post) {
|
||||
MetadataRunnable runnable = new MetadataRunnable(post);
|
||||
threadPoolService.getGeneralExecutor().submit(runnable);
|
||||
fetchingMetadata.put(post.getPostId(), runnable);
|
||||
}
|
||||
|
||||
public void stopFetchingMetadata(Post post) {
|
||||
this.fetchingMetadata.forEach((k, v) -> {
|
||||
if (k.equals(post.getPostId())) {
|
||||
v.setInterrupted(true);
|
||||
}
|
||||
});
|
||||
fetchingMetadata.remove(post.getPostId());
|
||||
}
|
||||
|
||||
private Metadata fetchMetadata(Key key) {
|
||||
@@ -93,6 +106,8 @@ public class MetadataService {
|
||||
|
||||
Node node = xpathService.getAsNode(document, String.format("//div[@id='post_message_%s']", key.getPostId()));
|
||||
metadata.setResolvedNames(findTitleInContent(node));
|
||||
|
||||
metadata.setPostId(key.getPostId());
|
||||
} catch (Exception e) {
|
||||
throw new PostParseException(String.format("Failed to parse thread %s, post %s", key.getThreadId(), key.getPostId()), e);
|
||||
} finally {
|
||||
|
||||
@@ -3,54 +3,40 @@ package tn.mnlr.vripper.services;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Service;
|
||||
import tn.mnlr.vripper.download.PendingQueue;
|
||||
import tn.mnlr.vripper.exception.PostParseException;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
import tn.mnlr.vripper.jpa.domain.enums.Status;
|
||||
import tn.mnlr.vripper.services.domain.*;
|
||||
import tn.mnlr.vripper.services.domain.MultiPostScanParser;
|
||||
import tn.mnlr.vripper.services.domain.MultiPostScanResult;
|
||||
import tn.mnlr.vripper.services.domain.tasks.AddPostRunnable;
|
||||
import tn.mnlr.vripper.services.domain.tasks.AddQueuedRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PostService {
|
||||
|
||||
private final SettingsService settingsService;
|
||||
private final PendingQueue pendingQueue;
|
||||
private final DataService dataService;
|
||||
private final ThreadPoolService threadPoolService;
|
||||
private final Map<String, Future<?>> fetchingMetadata = new ConcurrentHashMap<>();
|
||||
private final VGAuthService VGAuthService;
|
||||
|
||||
@Getter
|
||||
private final LoadingCache<Queued, List<MultiPostItem>> cache;
|
||||
private final MetadataService metadataService;
|
||||
private final LoadingCache<Queued, MultiPostScanResult> cache;
|
||||
|
||||
@Autowired
|
||||
public PostService(SettingsService settingsService, PendingQueue pendingQueue, DataService dataService, ThreadPoolService threadPoolService, VGAuthService VGAuthService) {
|
||||
this.settingsService = settingsService;
|
||||
this.pendingQueue = pendingQueue;
|
||||
public PostService(DataService dataService, ThreadPoolService threadPoolService, MetadataService metadataService) {
|
||||
this.dataService = dataService;
|
||||
this.threadPoolService = threadPoolService;
|
||||
this.VGAuthService = VGAuthService;
|
||||
this.metadataService = metadataService;
|
||||
|
||||
CacheLoader<Queued, List<MultiPostItem>> loader = new CacheLoader<>() {
|
||||
CacheLoader<Queued, MultiPostScanResult> loader = new CacheLoader<>() {
|
||||
@Override
|
||||
public List<MultiPostItem> load(@NonNull Queued multiPostItem) throws Exception {
|
||||
ApiThreadParser apiThreadParser = new ApiThreadParser(multiPostItem);
|
||||
return apiThreadParser.parse();
|
||||
public MultiPostScanResult load(@NonNull Queued multiPostItem) throws Exception {
|
||||
return new MultiPostScanParser(multiPostItem).parse();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,95 +45,22 @@ public class PostService {
|
||||
.build(loader);
|
||||
}
|
||||
|
||||
public void addPost(String postId, String threadId) throws PostParseException {
|
||||
|
||||
if (dataService.exists(postId)) {
|
||||
log.warn(String.format("skipping %s, already loaded", postId));
|
||||
return;
|
||||
}
|
||||
|
||||
ApiPostParser apiPostParser = new ApiPostParser(threadId, postId);
|
||||
ApiPost apiPost = apiPostParser.parse();
|
||||
if (apiPost.getPost().isEmpty()) {
|
||||
throw new PostParseException(String.format("parsing failed for thread %s, post %s", threadId, postId));
|
||||
}
|
||||
|
||||
Post post = apiPost.getPost().get();
|
||||
Set<Image> images = apiPost.getImages();
|
||||
|
||||
dataService.newPost(post, images);
|
||||
|
||||
// Metadata thread
|
||||
fetchingMetadata.put(post.getPostId(), threadPoolService.getGeneralExecutor().submit(new MetadataRunnable(post)));
|
||||
|
||||
if (settingsService.getSettings().getAutoStart()) {
|
||||
log.debug("Auto start downloads option is enabled");
|
||||
post.setStatus(Status.PENDING);
|
||||
try {
|
||||
pendingQueue.enqueue(post, images);
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Interruption was caught");
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
log.debug(String.format("Done enqueuing jobs for %s", post.getUrl()));
|
||||
} else {
|
||||
post.setStatus(Status.STOPPED);
|
||||
log.debug("Auto start downloads option is disabled");
|
||||
}
|
||||
if (!settingsService.getSettings().getLeaveThanksOnStart()) {
|
||||
VGAuthService.leaveThanks(post);
|
||||
}
|
||||
dataService.updatePostStatus(post.getStatus(), post.getId());
|
||||
}
|
||||
|
||||
public void stopFetchingMetadata(Post post) {
|
||||
this.fetchingMetadata.forEach((k, v) -> {
|
||||
if (k.equals(post.getPostId())) {
|
||||
v.cancel(true);
|
||||
}
|
||||
});
|
||||
fetchingMetadata.remove(post.getPostId());
|
||||
metadataService.stopFetchingMetadata(post);
|
||||
}
|
||||
|
||||
public void processMultiPost(List<Queued> queuedList) throws Exception {
|
||||
public void processMultiPost(List<Queued> queuedList) {
|
||||
for (Queued queued : queuedList) {
|
||||
if (queued.getPostId() != null) {
|
||||
addPost(queued.getPostId(), queued.getThreadId());
|
||||
threadPoolService.getGeneralExecutor().submit(new AddPostRunnable(queued.getPostId(), queued.getThreadId()));
|
||||
} else {
|
||||
threadPoolService.getGeneralExecutor().submit(() -> this.multiPost(queued));
|
||||
threadPoolService.getGeneralExecutor().submit(new AddQueuedRunnable(queued));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void multiPost(Queued queued) {
|
||||
|
||||
List<MultiPostItem> multiPostItems;
|
||||
try {
|
||||
multiPostItems = cache.get(queued);
|
||||
} catch (ExecutionException e) {
|
||||
log.error(String.format("Failed to add post with thread id %s, postId %s", queued.getThreadId(), queued.getPostId()), e);
|
||||
return;
|
||||
}
|
||||
queued.setTotal(multiPostItems.size());
|
||||
queued.done();
|
||||
log.debug(String.format("%d found for %s", multiPostItems.size(), queued.getLink()));
|
||||
if (multiPostItems.size() == 1) {
|
||||
try {
|
||||
addPost(multiPostItems.get(0).getPostId(), multiPostItems.get(0).getThreadId());
|
||||
} catch (PostParseException e) {
|
||||
log.error(String.format("Failed to add post with postId %s", multiPostItems.get(0).getPostId()), e);
|
||||
return;
|
||||
}
|
||||
log.debug(String.format("threadId %s, postId %s is added automatically for download", queued.getThreadId(), queued.getPostId()));
|
||||
} else {
|
||||
if (dataService.findQueuedByThreadId(queued.getThreadId()).isEmpty()) {
|
||||
dataService.newQueueLink(queued);
|
||||
} else {
|
||||
log.info(String.format("Thread with id = %s is already loaded", queued.getThreadId()));
|
||||
}
|
||||
}
|
||||
|
||||
public MultiPostScanResult get(Queued queued) throws ExecutionException {
|
||||
return cache.get(queued);
|
||||
}
|
||||
|
||||
public void remove(String threadId) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package tn.mnlr.vripper.services;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Getter;
|
||||
@@ -10,6 +11,7 @@ import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Sinks;
|
||||
@@ -19,11 +21,17 @@ import tn.mnlr.vripper.listener.EmitHandler;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.nio.file.StandardOpenOption.*;
|
||||
|
||||
@@ -33,28 +41,67 @@ import static java.nio.file.StandardOpenOption.*;
|
||||
public class SettingsService {
|
||||
|
||||
private final Path configPath;
|
||||
private final Path customProxiesPath;
|
||||
private final ObjectMapper om = new ObjectMapper();
|
||||
|
||||
private final Set<String> proxies = new HashSet<>();
|
||||
|
||||
private Sinks.Many<Settings> sink = Sinks.many().multicast().onBackpressureBuffer();
|
||||
|
||||
@Getter
|
||||
private Settings settings = new Settings();
|
||||
@Value("classpath:proxies.json")
|
||||
private Resource defaultProxies;
|
||||
|
||||
public SettingsService(@Value("${base.dir}") String baseDir, @Value("${base.dir.name}") String baseDirName) {
|
||||
this.configPath = Paths.get(baseDir, baseDirName, "config.json");
|
||||
this.customProxiesPath = Paths.get(baseDir, baseDirName, "proxies.json");
|
||||
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
loadViperProxies();
|
||||
restore();
|
||||
sink.emitNext(settings, EmitHandler.RETRY);
|
||||
}
|
||||
|
||||
private void loadViperProxies() {
|
||||
try (InputStream defaultProxiesIs = defaultProxies.getInputStream()) {
|
||||
List<String> defaultProxies = om.readValue(defaultProxiesIs, new TypeReference<>() {
|
||||
});
|
||||
List<String> customProxies = new ArrayList<>();
|
||||
if (customProxiesPath.toFile().exists() && customProxiesPath.toFile().isFile()) {
|
||||
customProxies = om.readValue(customProxiesPath.toFile(), new TypeReference<>() {
|
||||
});
|
||||
} else {
|
||||
if (!customProxiesPath.toFile().createNewFile()) {
|
||||
log.warn("Unable to create " + customProxiesPath.toFile().getAbsolutePath());
|
||||
} else {
|
||||
try (FileWriter fw = new FileWriter(customProxiesPath.toFile())) {
|
||||
fw.append("[]").append(System.lineSeparator());
|
||||
fw.flush();
|
||||
} catch (IOException e) {
|
||||
log.warn("Unable to create " + customProxiesPath.toFile().getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
proxies.addAll(customProxies);
|
||||
proxies.addAll(defaultProxies);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to load vipergirls proxies list", e);
|
||||
}
|
||||
proxies.add("https://vipergirls.to");
|
||||
}
|
||||
|
||||
Flux<Settings> getSettingsFlux() {
|
||||
return sink.asFlux();
|
||||
}
|
||||
|
||||
public List<String> getProxies() {
|
||||
return new ArrayList<>(proxies);
|
||||
}
|
||||
|
||||
public void newSettings(Settings settings) {
|
||||
|
||||
if (settings.getVLogin() != null && settings.getVLogin()) {
|
||||
@@ -75,7 +122,9 @@ public class SettingsService {
|
||||
|
||||
public void restore() {
|
||||
try {
|
||||
settings = om.readValue(configPath.toFile(), Settings.class);
|
||||
if (configPath.toFile().exists()) {
|
||||
settings = om.readValue(configPath.toFile(), Settings.class);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Failed restore user settings", e);
|
||||
settings = new Settings();
|
||||
@@ -153,6 +202,14 @@ public class SettingsService {
|
||||
settings.setMaxAttempts(5);
|
||||
}
|
||||
|
||||
if (settings.getVProxy() == null || !proxies.contains(settings.getVProxy())) {
|
||||
settings.setVProxy("https://vipergirls.to");
|
||||
}
|
||||
|
||||
if (settings.getMaxEventLog() == null) {
|
||||
settings.setMaxEventLog(1000);
|
||||
}
|
||||
|
||||
try {
|
||||
check(this.settings);
|
||||
} catch (ValidationException e) {
|
||||
@@ -207,6 +264,14 @@ public class SettingsService {
|
||||
if (settings.getMaxAttempts() < 1 || settings.getMaxAttempts() > 10) {
|
||||
throw new ValidationException(String.format("Invalid maximum attempts settings, values must be in [%d,%d]", 1, 10));
|
||||
}
|
||||
|
||||
if (settings.getMaxEventLog() < 100 || settings.getMaxEventLog() > 10_000) {
|
||||
throw new ValidationException(String.format("Invalid maximum event log record settings, values must be in [%d,%d]", 100, 10_000));
|
||||
}
|
||||
|
||||
if (!settings.getVThanks() && settings.getLeaveThanksOnStart()) {
|
||||
throw new ValidationException("Invalid value, leave thanks must be checked");
|
||||
}
|
||||
}
|
||||
|
||||
public Theme getTheme() {
|
||||
@@ -289,5 +354,12 @@ public class SettingsService {
|
||||
|
||||
@JsonProperty("maxAttempts")
|
||||
private Integer maxAttempts;
|
||||
|
||||
@JsonProperty("vProxy")
|
||||
private String vProxy;
|
||||
|
||||
@JsonProperty("maxEventLog")
|
||||
private Integer maxEventLog;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import reactor.core.publisher.Sinks;
|
||||
import tn.mnlr.vripper.exception.VripperException;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.listener.EmitHandler;
|
||||
import tn.mnlr.vripper.services.domain.tasks.LeaveThanksRunnable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
@@ -33,7 +34,6 @@ public class VGAuthService {
|
||||
private final ConnectionService cm;
|
||||
private final SettingsService settingsService;
|
||||
private final ThreadPoolService threadPoolService;
|
||||
private final DataService dataService;
|
||||
|
||||
private final Disposable disposable;
|
||||
|
||||
@@ -46,11 +46,10 @@ public class VGAuthService {
|
||||
private String loggedUser = "";
|
||||
|
||||
@Autowired
|
||||
public VGAuthService(ConnectionService cm, SettingsService settingsService, ThreadPoolService threadPoolService, DataService dataService) {
|
||||
public VGAuthService(ConnectionService cm, SettingsService settingsService, ThreadPoolService threadPoolService) {
|
||||
this.cm = cm;
|
||||
this.settingsService = settingsService;
|
||||
this.threadPoolService = threadPoolService;
|
||||
this.dataService = dataService;
|
||||
disposable = settingsService.getSettingsFlux().subscribe(settings -> this.authenticate());
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ public class VGAuthService {
|
||||
return;
|
||||
}
|
||||
|
||||
HttpPost postAuth = cm.buildHttpPost("https://vipergirls.to/login.php?do=login", null);
|
||||
HttpPost postAuth = cm.buildHttpPost(settingsService.getSettings().getVProxy() + "/login.php?do=login", null);
|
||||
List<NameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("vb_login_username", username));
|
||||
|
||||
@@ -107,12 +106,12 @@ public class VGAuthService {
|
||||
context.getCookieStore().clear();
|
||||
loggedUser = "";
|
||||
sink.emitNext(loggedUser, EmitHandler.RETRY);
|
||||
log.error("Failed to authenticate user with vipergirls.to", e);
|
||||
log.error("Failed to authenticate user with " + settingsService.getSettings().getVProxy(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
postAuth.addHeader("Referer", "https://vipergirls.to/");
|
||||
postAuth.addHeader("Host", "vipergirls.to");
|
||||
postAuth.addHeader("Referer", settingsService.getSettings().getVProxy());
|
||||
postAuth.addHeader("Host", settingsService.getSettings().getVProxy().replace("https://", "").replace("http://", ""));
|
||||
|
||||
CloseableHttpClient client = cm.getClient().build();
|
||||
|
||||
@@ -125,14 +124,14 @@ 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"))) {
|
||||
log.error("Failed to authenticate user with vipergirls.to, missing vg_userid cookie");
|
||||
log.error(String.format("Failed to authenticate user with %s, missing vg_userid cookie", settingsService.getSettings().getVProxy()));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
context.getCookieStore().clear();
|
||||
loggedUser = "";
|
||||
sink.emitNext(loggedUser, EmitHandler.RETRY);
|
||||
log.error("Failed to authenticate user with vipergirls.to", e);
|
||||
log.error("Failed to authenticate user with " + settingsService.getSettings().getVProxy(), e);
|
||||
return;
|
||||
}
|
||||
authenticated = true;
|
||||
@@ -142,62 +141,6 @@ public class VGAuthService {
|
||||
}
|
||||
|
||||
public void leaveThanks(Post post) {
|
||||
if (!settingsService.getSettings().getVLogin()) {
|
||||
log.debug("Authentication with ViperGirls option is disabled");
|
||||
return;
|
||||
}
|
||||
if (!settingsService.getSettings().getVThanks()) {
|
||||
log.debug("Leave thanks option is disabled");
|
||||
return;
|
||||
}
|
||||
if (!authenticated) {
|
||||
log.error("You are not authenticated");
|
||||
return;
|
||||
}
|
||||
if (post.isThanked()) {
|
||||
log.debug("Already left a thanks");
|
||||
return;
|
||||
}
|
||||
threadPoolService.getGeneralExecutor().submit(() -> {
|
||||
try {
|
||||
postThanks(post);
|
||||
} catch (Exception e) {
|
||||
log.error(String.format("Failed to leave a thanks for url %s, post id %s", post.getUrl(), post.getPostId()), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void postThanks(Post post) throws VripperException {
|
||||
|
||||
HttpPost postThanks = cm.buildHttpPost("https://vipergirls.to/post_thanks.php", null);
|
||||
List<NameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("do", "post_thanks_add"));
|
||||
params.add(new BasicNameValuePair("using_ajax", "1"));
|
||||
params.add(new BasicNameValuePair("p", post.getPostId()));
|
||||
params.add(new BasicNameValuePair("securitytoken", post.getSecurityToken()));
|
||||
try {
|
||||
postThanks.setEntity(new UrlEncodedFormEntity(params));
|
||||
} catch (Exception e) {
|
||||
throw new VripperException(e);
|
||||
}
|
||||
|
||||
postThanks.addHeader("Referer", "https://vipergirls.to/");
|
||||
postThanks.addHeader("Host", "vipergirls.to");
|
||||
|
||||
CloseableHttpClient client = cm.getClient().build();
|
||||
|
||||
try (CloseableHttpResponse response = client.execute(postThanks, context)) {
|
||||
if (response.getStatusLine().getStatusCode() / 100 == 2) {
|
||||
post.setThanked(true);
|
||||
dataService.updatePostThanked(post.isThanked(), post.getId());
|
||||
}
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
} catch (Exception e) {
|
||||
throw new VripperException(e);
|
||||
}
|
||||
|
||||
if (!post.isThanked()) {
|
||||
throw new VripperException("Failed to leave");
|
||||
}
|
||||
threadPoolService.getGeneralExecutor().submit(new LeaveThanksRunnable(post, authenticated, context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package tn.mnlr.vripper.services.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.jodah.failsafe.FailsafeException;
|
||||
import org.apache.http.impl.execchain.RequestAbortedException;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.jpa.domain.Metadata;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.services.MetadataService;
|
||||
|
||||
@Slf4j
|
||||
public class MetadataRunnable implements Runnable {
|
||||
|
||||
@Getter
|
||||
private final Post post;
|
||||
|
||||
private final MetadataService metadataService;
|
||||
private final DataService dataService;
|
||||
|
||||
public MetadataRunnable(@NonNull Post post) {
|
||||
this.post = post;
|
||||
this.metadataService = SpringContext.getBean(MetadataService.class);
|
||||
this.dataService = SpringContext.getBean(DataService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (Thread.interrupted()) {
|
||||
log.debug(String.format("Metadata fetching for postId=%s, threadId=%s interrupted", post.getPostId(), post.getThreadId()));
|
||||
return;
|
||||
}
|
||||
Metadata metadata = metadataService.get(post);
|
||||
dataService.setMetadata(post, metadata);
|
||||
} catch (Exception e) {
|
||||
if (e.getCause() instanceof InterruptedException || (e.getCause() instanceof FailsafeException && (e.getCause().getCause() instanceof InterruptedException || e.getCause().getCause() instanceof RequestAbortedException))) {
|
||||
return;
|
||||
}
|
||||
log.error(String.format("Failed to get metadata for postId %s", post.getPostId()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-6
@@ -1,23 +1,24 @@
|
||||
package tn.mnlr.vripper.services.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.host.Host;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ApiThreadHandler extends DefaultHandler {
|
||||
public class MultiPostScanHandler extends DefaultHandler {
|
||||
|
||||
private final Queued queued;
|
||||
private final Collection<Host> supportedHosts;
|
||||
private final SettingsService settingsService;
|
||||
private final Map<Host, AtomicInteger> hostMap = new HashMap<>();
|
||||
@Getter
|
||||
private final List<MultiPostItem> posts = new ArrayList<>();
|
||||
private String error;
|
||||
private List<String> previews = new ArrayList<>();
|
||||
private String threadTitle;
|
||||
private String postId;
|
||||
@@ -26,9 +27,14 @@ public class ApiThreadHandler extends DefaultHandler {
|
||||
private int postCounter;
|
||||
private int previewCounter = 0;
|
||||
|
||||
public ApiThreadHandler(Queued queued) {
|
||||
public MultiPostScanHandler(Queued queued) {
|
||||
this.queued = queued;
|
||||
this.supportedHosts = SpringContext.getBeansOfType(Host.class).values();
|
||||
supportedHosts = SpringContext.getBeansOfType(Host.class).values();
|
||||
settingsService = SpringContext.getBean(SettingsService.class);
|
||||
}
|
||||
|
||||
public MultiPostScanResult getScanResult() {
|
||||
return new MultiPostScanResult(posts, error);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,6 +45,9 @@ public class ApiThreadHandler extends DefaultHandler {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName.toLowerCase()) {
|
||||
case "error":
|
||||
error = attributes.getValue("details");
|
||||
break;
|
||||
case "thread":
|
||||
threadTitle = attributes.getValue("title").trim();
|
||||
break;
|
||||
@@ -70,7 +79,7 @@ public class ApiThreadHandler extends DefaultHandler {
|
||||
postCounter,
|
||||
postTitle,
|
||||
imageCount,
|
||||
String.format("https://vipergirls.to/threads/?p=%s&viewfull=1#post%s", postId, postId),
|
||||
String.format("%s/threads/?p=%s&viewfull=1#post%s", settingsService.getSettings().getVProxy(), postId, postId),
|
||||
previews,
|
||||
hostMap.entrySet().stream().filter(v -> v.getValue().get() > 0).map(e -> e.getKey().getHost() + " (" + e.getValue().get() + ")").collect(Collectors.joining(", "))
|
||||
));
|
||||
+15
-14
@@ -12,46 +12,46 @@ import tn.mnlr.vripper.exception.DownloadException;
|
||||
import tn.mnlr.vripper.exception.PostParseException;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
import tn.mnlr.vripper.services.ConnectionService;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
import tn.mnlr.vripper.services.VGAuthService;
|
||||
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Slf4j
|
||||
public class ApiThreadParser {
|
||||
|
||||
private static final String VR_API = "https://vipergirls.to/vr.php";
|
||||
public class MultiPostScanParser {
|
||||
|
||||
private static final SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
private final Queued queued;
|
||||
private final ConnectionService cm;
|
||||
private final VGAuthService VGAuthService;
|
||||
private final SettingsService settingsService;
|
||||
|
||||
public ApiThreadParser(Queued queued) {
|
||||
public MultiPostScanParser(Queued queued) {
|
||||
this.queued = queued;
|
||||
this.cm = SpringContext.getBean(ConnectionService.class);
|
||||
this.VGAuthService = SpringContext.getBean(VGAuthService.class);
|
||||
cm = SpringContext.getBean(ConnectionService.class);
|
||||
VGAuthService = SpringContext.getBean(VGAuthService.class);
|
||||
settingsService = SpringContext.getBean(SettingsService.class);
|
||||
}
|
||||
|
||||
public List<MultiPostItem> parse() throws PostParseException {
|
||||
public MultiPostScanResult parse() throws PostParseException {
|
||||
|
||||
log.debug(String.format("Parsing thread %s", queued));
|
||||
HttpGet httpGet;
|
||||
try {
|
||||
URIBuilder uriBuilder = new URIBuilder(VR_API);
|
||||
URIBuilder uriBuilder = new URIBuilder(settingsService.getSettings().getVProxy() + "/vr.php");
|
||||
uriBuilder.setParameter("t", queued.getThreadId());
|
||||
httpGet = cm.buildHttpGet(uriBuilder.build(), null);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new PostParseException(e);
|
||||
}
|
||||
|
||||
ApiThreadHandler apiThreadHandler = new ApiThreadHandler(queued);
|
||||
MultiPostScanHandler multiPostScanHandler = new MultiPostScanHandler(queued);
|
||||
AtomicReference<Throwable> thr = new AtomicReference<>();
|
||||
log.debug(String.format("Requesting %s", httpGet));
|
||||
List<MultiPostItem> posts = Failsafe.with(cm.getRetryPolicy())
|
||||
MultiPostScanResult multiPostScanResult = Failsafe.with(cm.getRetryPolicy())
|
||||
.onFailure(e -> thr.set(e.getFailure()))
|
||||
.get(() -> {
|
||||
HttpClient connection = cm.getClient().build();
|
||||
@@ -61,8 +61,9 @@ public class ApiThreadParser {
|
||||
}
|
||||
|
||||
try {
|
||||
factory.newSAXParser().parse(new BufferedInputStream(response.getEntity().getContent()), apiThreadHandler);
|
||||
return apiThreadHandler.getPosts();
|
||||
// System.out.println(EntityUtils.toString(response.getEntity()));
|
||||
factory.newSAXParser().parse(new BufferedInputStream(response.getEntity().getContent()), multiPostScanHandler);
|
||||
return multiPostScanHandler.getScanResult();
|
||||
} catch (Exception e) {
|
||||
throw new PostParseException(String.format("Failed to parse thread %s", queued), e);
|
||||
} finally {
|
||||
@@ -74,6 +75,6 @@ public class ApiThreadParser {
|
||||
log.error(String.format("parsing failed for thread %s", queued), thr.get());
|
||||
throw new PostParseException(thr.get());
|
||||
}
|
||||
return posts;
|
||||
return multiPostScanResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package tn.mnlr.vripper.services.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class MultiPostScanResult {
|
||||
private final List<MultiPostItem> posts;
|
||||
private final String error;
|
||||
|
||||
public MultiPostScanResult(List<MultiPostItem> posts, String error) {
|
||||
this.posts = posts;
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -7,6 +7,7 @@ import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.host.Host;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -15,7 +16,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
class ApiPostHandler extends DefaultHandler {
|
||||
class PostScanHandler extends DefaultHandler {
|
||||
|
||||
private final Collection<Host> supportedHosts;
|
||||
|
||||
@@ -25,23 +26,23 @@ class ApiPostHandler extends DefaultHandler {
|
||||
private final Set<Image> images = new HashSet<>();
|
||||
private Set<String> previews = new HashSet<>();
|
||||
private String threadTitle;
|
||||
private String postTitle;
|
||||
private String forum;
|
||||
private String userHash;
|
||||
private int index = 0;
|
||||
|
||||
private Post parsedPost;
|
||||
|
||||
ApiPostHandler(String threadId, String postId) {
|
||||
PostScanHandler(String threadId, String postId) {
|
||||
this.threadId = threadId;
|
||||
this.postId = postId;
|
||||
this.postUrl = String.format("https://vipergirls.to/threads/%s/?p=%s&viewfull=1#post%s", this.threadId, this.postId, this.postId);
|
||||
this.supportedHosts = SpringContext.getBeansOfType(Host.class).values();
|
||||
supportedHosts = SpringContext.getBeansOfType(Host.class).values();
|
||||
SettingsService settingsService = SpringContext.getBean(SettingsService.class);
|
||||
postUrl = String.format("%s/threads/%s/?p=%s&viewfull=1#post%s", settingsService.getSettings().getVProxy(), this.threadId, this.postId, this.postId);
|
||||
}
|
||||
|
||||
|
||||
public ApiPost getParsedPost() {
|
||||
return new ApiPost(parsedPost, images);
|
||||
public PostScanResult getParsedPost() {
|
||||
return new PostScanResult(parsedPost, images);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +63,7 @@ class ApiPostHandler extends DefaultHandler {
|
||||
threadTitle = attributes.getValue("title").trim();
|
||||
break;
|
||||
case "post":
|
||||
postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
|
||||
String postTitle = Optional.ofNullable(attributes.getValue("title")).map(e -> e.trim().isEmpty() ? null : e.trim()).orElse(threadTitle);
|
||||
parsedPost = new Post(
|
||||
postTitle,
|
||||
postUrl,
|
||||
+14
-13
@@ -11,6 +11,7 @@ import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.exception.DownloadException;
|
||||
import tn.mnlr.vripper.exception.PostParseException;
|
||||
import tn.mnlr.vripper.services.ConnectionService;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
import tn.mnlr.vripper.services.VGAuthService;
|
||||
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
@@ -18,9 +19,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Slf4j
|
||||
public class ApiPostParser {
|
||||
|
||||
private static final String VR_API = "https://vipergirls.to/vr.php";
|
||||
public class PostScanParser {
|
||||
|
||||
private static final SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
|
||||
@@ -28,20 +27,22 @@ public class ApiPostParser {
|
||||
private final String postId;
|
||||
private final ConnectionService cm;
|
||||
private final VGAuthService VGAuthService;
|
||||
private final SettingsService settingsService;
|
||||
|
||||
public ApiPostParser(String threadId, String postId) {
|
||||
public PostScanParser(String threadId, String postId) {
|
||||
this.threadId = threadId;
|
||||
this.postId = postId;
|
||||
this.cm = SpringContext.getBean(ConnectionService.class);
|
||||
this.VGAuthService = SpringContext.getBean(VGAuthService.class);
|
||||
cm = SpringContext.getBean(ConnectionService.class);
|
||||
VGAuthService = SpringContext.getBean(VGAuthService.class);
|
||||
settingsService = SpringContext.getBean(SettingsService.class);
|
||||
}
|
||||
|
||||
public ApiPost parse() throws PostParseException {
|
||||
public PostScanResult parse() throws PostParseException {
|
||||
|
||||
log.debug(String.format("Parsing post %s", postId));
|
||||
HttpGet httpGet;
|
||||
try {
|
||||
URIBuilder uriBuilder = new URIBuilder(VR_API);
|
||||
URIBuilder uriBuilder = new URIBuilder(settingsService.getSettings().getVProxy() + "/vr.php");
|
||||
uriBuilder.setParameter("p", postId);
|
||||
httpGet = cm.buildHttpGet(uriBuilder.build(), null);
|
||||
} catch (URISyntaxException e) {
|
||||
@@ -49,9 +50,9 @@ public class ApiPostParser {
|
||||
}
|
||||
|
||||
AtomicReference<Throwable> thr = new AtomicReference<>();
|
||||
ApiPostHandler apiPostHandler = new ApiPostHandler(threadId, postId);
|
||||
PostScanHandler postScanHandler = new PostScanHandler(threadId, postId);
|
||||
log.debug(String.format("Requesting %s", httpGet));
|
||||
ApiPost post = getPost(httpGet, apiPostHandler, thr);
|
||||
PostScanResult post = getPost(httpGet, postScanHandler, thr);
|
||||
if (thr.get() != null) {
|
||||
log.error(String.format("parsing failed for thread %s, post %s", threadId, postId), thr.get());
|
||||
throw new PostParseException(thr.get());
|
||||
@@ -59,7 +60,7 @@ public class ApiPostParser {
|
||||
return post;
|
||||
}
|
||||
|
||||
private ApiPost getPost(HttpGet httpGet, ApiPostHandler apiPostHandler, AtomicReference<Throwable> thr) {
|
||||
private PostScanResult getPost(HttpGet httpGet, PostScanHandler postScanHandler, AtomicReference<Throwable> thr) {
|
||||
return Failsafe.with(cm.getRetryPolicy())
|
||||
.onFailure(e -> thr.set(e.getFailure()))
|
||||
.get(() -> {
|
||||
@@ -69,9 +70,9 @@ public class ApiPostParser {
|
||||
throw new DownloadException(String.format("Unexpected response code '%d' for %s", response.getStatusLine().getStatusCode(), httpGet));
|
||||
}
|
||||
|
||||
factory.newSAXParser().parse(response.getEntity().getContent(), apiPostHandler);
|
||||
factory.newSAXParser().parse(response.getEntity().getContent(), postScanHandler);
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
return apiPostHandler.getParsedPost();
|
||||
return postScanHandler.getParsedPost();
|
||||
}
|
||||
});
|
||||
}
|
||||
+2
-2
@@ -7,14 +7,14 @@ import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class ApiPost {
|
||||
public class PostScanResult {
|
||||
|
||||
private final Post post;
|
||||
|
||||
@Getter
|
||||
private final Set<Image> images;
|
||||
|
||||
public ApiPost(Post post, Set<Image> images) {
|
||||
public PostScanResult(Post post, Set<Image> images) {
|
||||
this.post = post;
|
||||
this.images = images;
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package tn.mnlr.vripper.services.domain.tasks;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.Utils;
|
||||
import tn.mnlr.vripper.download.PendingQueue;
|
||||
import tn.mnlr.vripper.exception.PostParseException;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.domain.enums.Status;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.services.MetadataService;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
import tn.mnlr.vripper.services.VGAuthService;
|
||||
import tn.mnlr.vripper.services.domain.PostScanParser;
|
||||
import tn.mnlr.vripper.services.domain.PostScanResult;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Set;
|
||||
|
||||
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
|
||||
import static tn.mnlr.vripper.jpa.domain.Event.Status.PROCESSING;
|
||||
|
||||
@Slf4j
|
||||
public class AddPostRunnable implements Runnable {
|
||||
|
||||
private final String postId;
|
||||
private final String threadId;
|
||||
private final DataService dataService;
|
||||
private final MetadataService metadataService;
|
||||
private final SettingsService settingsService;
|
||||
private final PendingQueue pendingQueue;
|
||||
private final VGAuthService VGAuthService;
|
||||
private final Event event;
|
||||
private final IEventRepository eventRepository;
|
||||
private final String link;
|
||||
|
||||
public AddPostRunnable(String postId, String threadId) {
|
||||
this.postId = postId;
|
||||
this.threadId = threadId;
|
||||
this.dataService = SpringContext.getBean(DataService.class);
|
||||
this.metadataService = SpringContext.getBean(MetadataService.class);
|
||||
this.settingsService = SpringContext.getBean(SettingsService.class);
|
||||
this.pendingQueue = SpringContext.getBean(PendingQueue.class);
|
||||
this.VGAuthService = SpringContext.getBean(VGAuthService.class);
|
||||
this.eventRepository = SpringContext.getBean(IEventRepository.class);
|
||||
link = settingsService.getSettings().getVProxy() + String.format("/%s?%s", threadId, (postId != null ? "p=" + postId : ""));
|
||||
event = new Event(Event.Type.POST, Event.Status.PENDING, LocalDateTime.now(), String.format("Processing %s", link));
|
||||
eventRepository.save(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
event.setStatus(PROCESSING);
|
||||
eventRepository.update(event);
|
||||
if (dataService.exists(postId)) {
|
||||
log.warn(String.format("skipping %s, already loaded", postId));
|
||||
event.setMessage(String.format("Gallery %s is already loaded", link));
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
|
||||
PostScanParser postScanParser = new PostScanParser(threadId, postId);
|
||||
|
||||
PostScanResult postScanResult;
|
||||
try {
|
||||
postScanResult = postScanParser.parse();
|
||||
} catch (PostParseException e) {
|
||||
String error = String.format("parsing failed for gallery %s", link);
|
||||
log.error(error, e);
|
||||
event.setMessage(error + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
if (postScanResult.getPost().isEmpty()) {
|
||||
String error = String.format("Gallery %s contains no galleries", link);
|
||||
log.error(error);
|
||||
event.setMessage(error);
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
if (postScanResult.getImages().isEmpty()) {
|
||||
String error = String.format("Gallery %s contains no images to download", link);
|
||||
log.error(error);
|
||||
event.setMessage(error);
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
|
||||
Post post = postScanResult.getPost().get();
|
||||
Set<Image> images = postScanResult.getImages();
|
||||
|
||||
dataService.newPost(post, images);
|
||||
|
||||
metadataService.startFetchingMetadata(post);
|
||||
|
||||
if (settingsService.getSettings().getAutoStart()) {
|
||||
log.debug("Auto start downloads option is enabled");
|
||||
post.setStatus(Status.PENDING);
|
||||
try {
|
||||
pendingQueue.enqueue(post, images);
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Interruption was caught");
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
log.debug(String.format("Done enqueuing jobs for %s", post.getUrl()));
|
||||
} else {
|
||||
post.setStatus(Status.STOPPED);
|
||||
log.debug("Auto start downloads option is disabled");
|
||||
}
|
||||
if (!settingsService.getSettings().getLeaveThanksOnStart()) {
|
||||
VGAuthService.leaveThanks(post);
|
||||
}
|
||||
dataService.updatePostStatus(post.getStatus(), post.getId());
|
||||
event.setMessage(String.format("Gallery %s is successfully added to download queue", link));
|
||||
event.setStatus(Event.Status.DONE);
|
||||
eventRepository.update(event);
|
||||
} catch (Exception e) {
|
||||
String error = String.format("Error when adding gallery %s", link);
|
||||
log.error(error, e);
|
||||
event.setMessage(error + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package tn.mnlr.vripper.services.domain.tasks;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.Utils;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.services.PostService;
|
||||
import tn.mnlr.vripper.services.ThreadPoolService;
|
||||
import tn.mnlr.vripper.services.domain.MultiPostScanResult;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
|
||||
import static tn.mnlr.vripper.jpa.domain.Event.Status.PROCESSING;
|
||||
|
||||
@Slf4j
|
||||
public class AddQueuedRunnable implements Runnable {
|
||||
|
||||
private final Queued queued;
|
||||
private final ThreadPoolService threadPoolService;
|
||||
private final DataService dataService;
|
||||
private final IEventRepository eventRepository;
|
||||
private final PostService postService;
|
||||
private final Event event;
|
||||
|
||||
public AddQueuedRunnable(Queued queued) {
|
||||
this.queued = queued;
|
||||
threadPoolService = SpringContext.getBean(ThreadPoolService.class);
|
||||
dataService = SpringContext.getBean(DataService.class);
|
||||
eventRepository = SpringContext.getBean(IEventRepository.class);
|
||||
postService = SpringContext.getBean(PostService.class);
|
||||
event = new Event(Event.Type.QUEUED, Event.Status.PENDING, LocalDateTime.now(), String.format("Processing multi-post link %s", queued.getLink()));
|
||||
eventRepository.save(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
event.setStatus(PROCESSING);
|
||||
eventRepository.update(event);
|
||||
MultiPostScanResult multiPostScanResult = postService.get(queued);
|
||||
if (multiPostScanResult == null) {
|
||||
String message = String.format("Fetching multi-post link %s failed", queued.getLink());
|
||||
event.setStatus(ERROR);
|
||||
event.setMessage(message);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
} else if (multiPostScanResult.getError() != null) {
|
||||
String message = "Nothing found for " + queued.getLink() + "\n" + multiPostScanResult.getError();
|
||||
event.setStatus(ERROR);
|
||||
event.setMessage(message);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
} else if (multiPostScanResult.getPosts().isEmpty()) {
|
||||
String message = "Nothing found for " + queued.getLink();
|
||||
event.setStatus(ERROR);
|
||||
event.setMessage(message);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
queued.setTotal(multiPostScanResult.getPosts().size());
|
||||
queued.done();
|
||||
if (multiPostScanResult.getPosts().size() == 1) {
|
||||
threadPoolService.getGeneralExecutor().submit(new AddPostRunnable(multiPostScanResult.getPosts().get(0).getPostId(), multiPostScanResult.getPosts().get(0).getThreadId()));
|
||||
event.setStatus(Event.Status.DONE);
|
||||
event.setMessage(String.format("Link %s is added to download queue", queued.getLink()));
|
||||
} else {
|
||||
if (dataService.findQueuedByThreadId(queued.getThreadId()).isEmpty()) {
|
||||
dataService.newQueueLink(queued);
|
||||
event.setStatus(Event.Status.DONE);
|
||||
event.setMessage(String.format("Link %s is added to multi-post links", queued.getLink()));
|
||||
} else {
|
||||
log.info(String.format("Link %s is already loaded", queued.getLink()));
|
||||
event.setStatus(Event.Status.ERROR);
|
||||
event.setMessage(String.format("%s has already been added to multi-post links", queued.getLink()));
|
||||
}
|
||||
}
|
||||
eventRepository.update(event);
|
||||
} catch (Exception e) {
|
||||
String error = String.format("Error when adding multi-post link %s", queued.getLink());
|
||||
log.error(error, e);
|
||||
event.setMessage(error + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package tn.mnlr.vripper.services.domain.tasks;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.Utils;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
import tn.mnlr.vripper.services.ConnectionService;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class LeaveThanksRunnable implements Runnable {
|
||||
|
||||
private final ConnectionService cm;
|
||||
private final DataService dataService;
|
||||
private final HttpClientContext context;
|
||||
private final SettingsService settingsService;
|
||||
private final IEventRepository eventRepository;
|
||||
private final boolean authenticated;
|
||||
private final Post post;
|
||||
private final Event event;
|
||||
|
||||
public LeaveThanksRunnable(Post post, boolean authenticated, HttpClientContext context) {
|
||||
this.post = post;
|
||||
this.authenticated = authenticated;
|
||||
this.context = context;
|
||||
cm = SpringContext.getBean(ConnectionService.class);
|
||||
dataService = SpringContext.getBean(DataService.class);
|
||||
eventRepository = SpringContext.getBean(IEventRepository.class);
|
||||
settingsService = SpringContext.getBean(SettingsService.class);
|
||||
event = new Event(Event.Type.THANKS, Event.Status.PENDING, LocalDateTime.now(), String.format("Leaving thanks for %s", post.getUrl()));
|
||||
eventRepository.save(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
event.setStatus(Event.Status.PROCESSING);
|
||||
eventRepository.update(event);
|
||||
if (!settingsService.getSettings().getVLogin()) {
|
||||
event.setMessage(String.format("Will not send a like for %s\nAuthentication with ViperGirls option is disabled", post.getUrl()));
|
||||
event.setStatus(Event.Status.DONE);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
if (!settingsService.getSettings().getVThanks()) {
|
||||
event.setMessage(String.format("Will not send a like for %s\nLeave thanks option is disabled", post.getUrl()));
|
||||
event.setStatus(Event.Status.DONE);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
if (!authenticated) {
|
||||
event.setMessage(String.format("Will not send a like for %s\nYou are not authenticated", post.getUrl()));
|
||||
event.setStatus(Event.Status.ERROR);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
if (post.isThanked()) {
|
||||
event.setMessage(String.format("Will not send a like for %s\nAlready left a thanks", post.getUrl()));
|
||||
event.setStatus(Event.Status.DONE);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
|
||||
HttpPost postThanks = cm.buildHttpPost(settingsService.getSettings().getVProxy() + "/post_thanks.php", null);
|
||||
List<NameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("do", "post_thanks_add"));
|
||||
params.add(new BasicNameValuePair("using_ajax", "1"));
|
||||
params.add(new BasicNameValuePair("p", post.getPostId()));
|
||||
params.add(new BasicNameValuePair("securitytoken", post.getSecurityToken()));
|
||||
try {
|
||||
postThanks.setEntity(new UrlEncodedFormEntity(params));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
String error = String.format("Request error for %s", post.getUrl());
|
||||
log.error(error, e);
|
||||
event.setMessage(error + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(Event.Status.ERROR);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
|
||||
postThanks.addHeader("Referer", settingsService.getSettings().getVProxy());
|
||||
postThanks.addHeader("Host", settingsService.getSettings().getVProxy().replace("https://", "").replace("http://", ""));
|
||||
|
||||
CloseableHttpClient client = cm.getClient().build();
|
||||
|
||||
try (CloseableHttpResponse response = client.execute(postThanks, context)) {
|
||||
if (response.getStatusLine().getStatusCode() / 100 == 2) {
|
||||
post.setThanked(true);
|
||||
dataService.updatePostThanked(post.isThanked(), post.getId());
|
||||
}
|
||||
EntityUtils.consumeQuietly(response.getEntity());
|
||||
}
|
||||
event.setStatus(Event.Status.DONE);
|
||||
eventRepository.update(event);
|
||||
} catch (Exception e) {
|
||||
String error = String.format("Failed to leave a thanks for %s", post.getUrl());
|
||||
log.error(error, e);
|
||||
event.setMessage(error + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(Event.Status.ERROR);
|
||||
eventRepository.update(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package tn.mnlr.vripper.services.domain.tasks;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.lang.NonNull;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.Utils;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
import tn.mnlr.vripper.jpa.repositories.impl.EventRepository;
|
||||
import tn.mnlr.vripper.services.PostService;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
|
||||
|
||||
@Slf4j
|
||||
public class LinkScanRunnable implements Runnable {
|
||||
|
||||
private final static Object LOCK = new Object();
|
||||
private final List<String> urlList;
|
||||
private final SettingsService settingsService;
|
||||
private final PostService postService;
|
||||
private final EventRepository eventRepository;
|
||||
private final Event event;
|
||||
|
||||
|
||||
public LinkScanRunnable(@NonNull List<String> urlList) {
|
||||
this.urlList = urlList;
|
||||
settingsService = SpringContext.getBean(SettingsService.class);
|
||||
postService = SpringContext.getBean(PostService.class);
|
||||
eventRepository = SpringContext.getBean(EventRepository.class);
|
||||
event = new Event(Event.Type.SCAN, Event.Status.PENDING, LocalDateTime.now(), "Links to scan:\n\t" + String.join("\n\t", urlList));
|
||||
eventRepository.save(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (LOCK) {
|
||||
try {
|
||||
event.setStatus(Event.Status.PROCESSING);
|
||||
eventRepository.update(event);
|
||||
ArrayList<Queued> queuedList = new ArrayList<>();
|
||||
List<String> unsupported = new ArrayList<>();
|
||||
List<String> unrecognized = new ArrayList<>();
|
||||
for (String url : urlList) {
|
||||
log.debug(String.format("Starting to process thread: %s", url));
|
||||
if (!url.startsWith(settingsService.getSettings().getVProxy())) {
|
||||
log.error(String.format("Unsupported link %s", url));
|
||||
unsupported.add(url);
|
||||
continue;
|
||||
}
|
||||
|
||||
String threadId, postId;
|
||||
Matcher m = Pattern.compile(Pattern.quote(settingsService.getSettings().getVProxy()) + "/threads/(\\d+)((.*p=)(\\d+))?").matcher(url);
|
||||
if (m.find()) {
|
||||
threadId = m.group(1);
|
||||
postId = m.group(4);
|
||||
} else {
|
||||
log.error(String.format("Cannot retrieve thread id from URL %s", url));
|
||||
unrecognized.add(url);
|
||||
continue;
|
||||
}
|
||||
queuedList.add(new Queued(url, threadId, postId));
|
||||
}
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
if (!unsupported.isEmpty()) {
|
||||
errorMessage.append("Unsupported links:\n\t").append(String.join("\n\t", unsupported)).append("\n\n");
|
||||
}
|
||||
if (!unrecognized.isEmpty()) {
|
||||
errorMessage.append("Unrecognized links:\n\t").append(String.join("\n\t", unrecognized)).append("\n\n");
|
||||
}
|
||||
|
||||
postService.processMultiPost(queuedList);
|
||||
if (!unsupported.isEmpty() || !unrecognized.isEmpty()) {
|
||||
event.setStatus(Event.Status.ERROR);
|
||||
event.setMessage("Some links failed to be scanned: \n" + errorMessage.toString());
|
||||
} else {
|
||||
event.setStatus(Event.Status.DONE);
|
||||
}
|
||||
eventRepository.update(event);
|
||||
} catch (Exception e) {
|
||||
String error = "Error when scanning links";
|
||||
log.error(error, e);
|
||||
event.setMessage(error + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package tn.mnlr.vripper.services.domain.tasks;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tn.mnlr.vripper.SpringContext;
|
||||
import tn.mnlr.vripper.Utils;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.Metadata;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
import tn.mnlr.vripper.services.MetadataService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static tn.mnlr.vripper.jpa.domain.Event.Status.ERROR;
|
||||
|
||||
@Slf4j
|
||||
public class MetadataRunnable implements Runnable {
|
||||
|
||||
@Getter
|
||||
private final Post post;
|
||||
|
||||
private final MetadataService metadataService;
|
||||
private final DataService dataService;
|
||||
private final IEventRepository eventRepository;
|
||||
|
||||
private final Event event;
|
||||
|
||||
@Setter
|
||||
private volatile boolean interrupted = false;
|
||||
|
||||
public MetadataRunnable(@NonNull Post post) {
|
||||
this.post = post;
|
||||
metadataService = SpringContext.getBean(MetadataService.class);
|
||||
dataService = SpringContext.getBean(DataService.class);
|
||||
eventRepository = SpringContext.getBean(IEventRepository.class);
|
||||
event = new Event(Event.Type.METADATA, Event.Status.PENDING, LocalDateTime.now(), "Fetching metadata for " + post.getUrl());
|
||||
eventRepository.save(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
event.setStatus(Event.Status.PROCESSING);
|
||||
eventRepository.update(event);
|
||||
if (interrupted) {
|
||||
String message = String.format("Fetching metadata for %s interrupted", post.getUrl());
|
||||
event.setStatus(Event.Status.DONE);
|
||||
event.setMessage(message);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
|
||||
Metadata metadata = metadataService.get(post);
|
||||
if (metadata == null) {
|
||||
String message = String.format("Fetching metadata for %s failed", post.getUrl());
|
||||
event.setStatus(ERROR);
|
||||
event.setMessage(message);
|
||||
eventRepository.update(event);
|
||||
return;
|
||||
}
|
||||
dataService.setMetadata(post, metadata);
|
||||
|
||||
event.setStatus(Event.Status.DONE);
|
||||
eventRepository.update(event);
|
||||
} catch (Exception e) {
|
||||
String message = String.format("Failed to fetch metadata for %s", post.getUrl());
|
||||
log.error(message, e);
|
||||
event.setMessage(message + "\n" + Utils.throwableToString(e));
|
||||
event.setStatus(ERROR);
|
||||
eventRepository.update(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package tn.mnlr.vripper.web.restendpoints;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import tn.mnlr.vripper.jpa.repositories.IEventRepository;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@CrossOrigin(value = "*")
|
||||
public class EventLogRestEndpoint {
|
||||
|
||||
private final IEventRepository eventRepository;
|
||||
|
||||
public EventLogRestEndpoint(IEventRepository eventRepository) {
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/events/clear")
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public void clear() {
|
||||
eventRepository.deleteAll();
|
||||
}
|
||||
}
|
||||
+23
-42
@@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tn.mnlr.vripper.download.DownloadService;
|
||||
import tn.mnlr.vripper.exception.PostParseException;
|
||||
import tn.mnlr.vripper.jpa.domain.Metadata;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
@@ -15,6 +14,9 @@ import tn.mnlr.vripper.services.PathService;
|
||||
import tn.mnlr.vripper.services.PostService;
|
||||
import tn.mnlr.vripper.services.ThreadPoolService;
|
||||
import tn.mnlr.vripper.services.domain.MultiPostItem;
|
||||
import tn.mnlr.vripper.services.domain.MultiPostScanResult;
|
||||
import tn.mnlr.vripper.services.domain.tasks.AddPostRunnable;
|
||||
import tn.mnlr.vripper.services.domain.tasks.LinkScanRunnable;
|
||||
import tn.mnlr.vripper.web.restendpoints.domain.*;
|
||||
import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
|
||||
import tn.mnlr.vripper.web.restendpoints.exceptions.NotFoundException;
|
||||
@@ -24,9 +26,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -34,7 +33,6 @@ import java.util.stream.Collectors;
|
||||
@CrossOrigin(value = "*")
|
||||
public class PostRestEndpoint {
|
||||
|
||||
private static final Pattern VG_URL_PATTERN = Pattern.compile("https://vipergirls\\.to/threads/(\\d+)((.*p=)(\\d+))?");
|
||||
private static final Object LOCK = new Object();
|
||||
private final DataService dataService;
|
||||
private final PathService pathService;
|
||||
@@ -60,30 +58,7 @@ public class PostRestEndpoint {
|
||||
throw new BadRequestException("Cannot process empty requests");
|
||||
}
|
||||
List<String> urlList = Arrays.stream(_url.getUrl().split("\\r?\\n")).map(String::trim).filter(e -> !e.isEmpty()).collect(Collectors.toList());
|
||||
ArrayList<Queued> queuedList = new ArrayList<>();
|
||||
for (String url : urlList) {
|
||||
log.debug(String.format("Starting to process thread: %s", url));
|
||||
if (!url.startsWith("https://vipergirls.to")) {
|
||||
log.error(String.format("Unsupported link %s", url));
|
||||
continue;
|
||||
}
|
||||
|
||||
String threadId, postId;
|
||||
Matcher m = VG_URL_PATTERN.matcher(url);
|
||||
if (m.find()) {
|
||||
threadId = m.group(1);
|
||||
postId = m.group(4);
|
||||
} else {
|
||||
throw new BadRequestException(String.format("Cannot retrieve thread id from URL %s", url));
|
||||
}
|
||||
queuedList.add(new Queued(url, threadId, postId));
|
||||
}
|
||||
try {
|
||||
postService.processMultiPost(queuedList);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to parse links", e);
|
||||
throw new ServerErrorException(e.getMessage());
|
||||
}
|
||||
threadPoolService.getGeneralExecutor().submit(new LinkScanRunnable(urlList));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,14 +75,7 @@ public class PostRestEndpoint {
|
||||
public void addPost(@RequestBody List<PostToAdd> posts) {
|
||||
synchronized (LOCK) {
|
||||
for (PostToAdd post : posts) {
|
||||
threadPoolService.getGeneralExecutor().submit(() -> {
|
||||
try {
|
||||
postService.addPost(post.getPostId(), post.getThreadId());
|
||||
} catch (PostParseException e) {
|
||||
log.error(String.format("Failed to add post %s", post.getPostId()), e);
|
||||
throw new ServerErrorException(String.format("Failed to add post %s", post.getPostId()));
|
||||
}
|
||||
});
|
||||
threadPoolService.getGeneralExecutor().submit(new AddPostRunnable(post.getPostId(), post.getThreadId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,12 +206,17 @@ public class PostRestEndpoint {
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public List<MultiPostItem> grab(@PathVariable("threadId") @NonNull String 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));
|
||||
Queued queued = dataService.findQueuedByThreadId(threadId).orElseThrow(() -> new NotFoundException(String.format("Unable to find links for threadId = %s", threadId)));
|
||||
MultiPostScanResult multiPostScanResult = postService.get(queued);
|
||||
if (multiPostScanResult == null) {
|
||||
log.error(String.format("Failed to get links for threadId = %s", threadId));
|
||||
throw new ServerErrorException(String.format("Failed to get links for threadId = %s", threadId));
|
||||
} else {
|
||||
return multiPostScanResult.getPosts();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServerErrorException(String.format("Failed to get links for threadId = %s, %s", threadId, e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,4 +229,12 @@ public class PostRestEndpoint {
|
||||
return threadId;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/grab/clear")
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public void grabClear() {
|
||||
synchronized (LOCK) {
|
||||
dataService.clearQueueLinks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -8,6 +8,8 @@ import tn.mnlr.vripper.exception.ValidationException;
|
||||
import tn.mnlr.vripper.services.SettingsService;
|
||||
import tn.mnlr.vripper.web.restendpoints.exceptions.BadRequestException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@CrossOrigin(value = "*")
|
||||
@@ -35,7 +37,7 @@ public class SettingsRestEndpoint {
|
||||
|
||||
@PostMapping("/settings")
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public SettingsService.Settings postSettings(@RequestBody SettingsService.Settings settings) throws Exception {
|
||||
public SettingsService.Settings postSettings(@RequestBody SettingsService.Settings settings) {
|
||||
|
||||
try {
|
||||
this.settingsService.check(settings);
|
||||
@@ -54,4 +56,10 @@ public class SettingsRestEndpoint {
|
||||
|
||||
return settingsService.getSettings();
|
||||
}
|
||||
|
||||
@GetMapping("/settings/proxies")
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
public List<String> mirrors() {
|
||||
return settingsService.getProxies();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,7 @@ 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.ImageUpdateEvent;
|
||||
import tn.mnlr.vripper.event.MetadataUpdateEvent;
|
||||
import tn.mnlr.vripper.event.PostUpdateEvent;
|
||||
import tn.mnlr.vripper.event.QueuedUpdateEvent;
|
||||
import tn.mnlr.vripper.event.*;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.listener.*;
|
||||
import tn.mnlr.vripper.services.DataService;
|
||||
@@ -41,14 +38,16 @@ public class DataBroadcast {
|
||||
private final MetadataUpdateEventListener metadataUpdateEventListener;
|
||||
private final ImageUpdateEventListener imageUpdateEventListener;
|
||||
private final QueuedUpdateEventListener queuedUpdateEventListener;
|
||||
private final EventUpdateEventListener eventUpdateEventListener;
|
||||
|
||||
private final QueuedRemoveEventListener queuedRemoveEventListener;
|
||||
private final PostRemoveEventListener postRemoveEventListener;
|
||||
private final EventRemoveEventListener eventRemoveEventListener;
|
||||
|
||||
private final List<Disposable> disposables = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
public DataBroadcast(SimpMessagingTemplate template, VGAuthService VGAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService, PostUpdateEventListener postUpdateEventListener, MetadataUpdateEventListener metadataUpdateEventListener, ImageUpdateEventListener imageUpdateEventListener, QueuedUpdateEventListener queuedUpdateEventListener, QueuedRemoveEventListener queuedRemoveEventListener, PostRemoveEventListener postRemoveEventListener) {
|
||||
public DataBroadcast(SimpMessagingTemplate template, VGAuthService VGAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService, PostUpdateEventListener postUpdateEventListener, MetadataUpdateEventListener metadataUpdateEventListener, ImageUpdateEventListener imageUpdateEventListener, QueuedUpdateEventListener queuedUpdateEventListener, EventUpdateEventListener eventUpdateEventListener, QueuedRemoveEventListener queuedRemoveEventListener, PostRemoveEventListener postRemoveEventListener, EventRemoveEventListener eventRemoveEventListener) {
|
||||
this.template = template;
|
||||
this.VGAuthService = VGAuthService;
|
||||
this.globalStateService = globalStateService;
|
||||
@@ -58,8 +57,10 @@ public class DataBroadcast {
|
||||
this.metadataUpdateEventListener = metadataUpdateEventListener;
|
||||
this.imageUpdateEventListener = imageUpdateEventListener;
|
||||
this.queuedUpdateEventListener = queuedUpdateEventListener;
|
||||
this.eventUpdateEventListener = eventUpdateEventListener;
|
||||
this.queuedRemoveEventListener = queuedRemoveEventListener;
|
||||
this.postRemoveEventListener = postRemoveEventListener;
|
||||
this.eventRemoveEventListener = eventRemoveEventListener;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@@ -89,6 +90,13 @@ public class DataBroadcast {
|
||||
.filter(e -> !e.isEmpty())
|
||||
.subscribe(ids -> template.convertAndSend("/topic/posts", ids.stream().map(dataService::findById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e)));
|
||||
|
||||
disposables.add(eventUpdateEventListener.getDataFlux()
|
||||
.map(EventUpdateEvent::getId)
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
.map(HashSet::new)
|
||||
.filter(e -> !e.isEmpty())
|
||||
.subscribe(ids -> template.convertAndSend("/topic/events", ids.stream().map(dataService::findEventById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList())), e -> log.error("Failed to send data to client", e)));
|
||||
|
||||
disposables.add(imageUpdateEventListener.getDataFlux()
|
||||
.map(ImageUpdateEvent::getId)
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
@@ -113,6 +121,7 @@ public class DataBroadcast {
|
||||
);
|
||||
|
||||
disposables.add(queuedRemoveEventListener.getDataFlux()
|
||||
.map(QueuedRemoveEvent::getThreadId)
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
.map(HashSet::new)
|
||||
.filter(e -> !e.isEmpty())
|
||||
@@ -120,11 +129,20 @@ public class DataBroadcast {
|
||||
);
|
||||
|
||||
disposables.add(postRemoveEventListener.getDataFlux()
|
||||
.map(PostRemoveEvent::getPostId)
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
.map(HashSet::new)
|
||||
.filter(e -> !e.isEmpty())
|
||||
.subscribe(postIds -> template.convertAndSend("/topic/posts/deleted", postIds), e -> log.error("Failed to send data to client", e))
|
||||
);
|
||||
|
||||
disposables.add(eventRemoveEventListener.getDataFlux()
|
||||
.map(EventRemoveEvent::getId)
|
||||
.buffer(Duration.of(500, ChronoUnit.MILLIS))
|
||||
.map(HashSet::new)
|
||||
.filter(e -> !e.isEmpty())
|
||||
.subscribe(postIds -> template.convertAndSend("/topic/events/deleted", postIds), e -> log.error("Failed to send data to client", e))
|
||||
);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.handler.annotation.DestinationVariable;
|
||||
import org.springframework.messaging.simp.annotation.SubscribeMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import tn.mnlr.vripper.jpa.domain.Event;
|
||||
import tn.mnlr.vripper.jpa.domain.Image;
|
||||
import tn.mnlr.vripper.jpa.domain.Post;
|
||||
import tn.mnlr.vripper.jpa.domain.Queued;
|
||||
@@ -17,8 +18,6 @@ import tn.mnlr.vripper.services.domain.GlobalState;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Controller
|
||||
public class DataController {
|
||||
@@ -53,7 +52,7 @@ public class DataController {
|
||||
|
||||
@SubscribeMapping("/posts")
|
||||
public Collection<Post> posts() {
|
||||
return StreamSupport.stream(dataService.findAllPosts().spliterator(), false).collect(Collectors.toList());
|
||||
return dataService.findAllPosts();
|
||||
}
|
||||
|
||||
@SubscribeMapping("/images/{postId}")
|
||||
@@ -63,7 +62,12 @@ public class DataController {
|
||||
|
||||
@SubscribeMapping("/queued")
|
||||
public Collection<Queued> queued() {
|
||||
return StreamSupport.stream(dataService.findAllQueued().spliterator(), false).collect(Collectors.toList());
|
||||
return dataService.findAllQueued();
|
||||
}
|
||||
|
||||
@SubscribeMapping("/events")
|
||||
public Collection<Event> events() {
|
||||
return dataService.findAllEvents();
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
||||
@@ -8,7 +8,7 @@ management.endpoints.web.exposure.include=shutdown
|
||||
management.endpoint.shutdown.enabled=true
|
||||
server.error.include-message=always
|
||||
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml
|
||||
spring.datasource.url=jdbc:hsqldb:file:${base.dir}/${base.dir.name}/db/xparty;hsqldb.lock_file=false
|
||||
spring.datasource.url=jdbc:hsqldb:file:${base.dir}/${base.dir.name}/db/vripper;hsqldb.lock_file=false
|
||||
spring.datasource.username=SA
|
||||
spring.datasource.password=lEtmEIn
|
||||
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
|
||||
|
||||
@@ -2,10 +2,60 @@
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
|
||||
<changeSet author="sysgen" id="1595764509827-1">
|
||||
<createSequence sequenceName="HIBERNATE_SEQUENCE"/>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-2">
|
||||
<changeSet author="death-claw" id="1613151442-1">
|
||||
<createTable tableName="POST">
|
||||
<column name="ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="DONE" type="INT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="FORUM" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="HOSTS" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="POST_FOLDER_NAME" type="VARCHAR(500)"/>
|
||||
<column name="POST_ID" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="PREVIEWS" type="VARCHAR(16777216)"/>
|
||||
<column name="SECURITY_TOKEN" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="STATUS" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="THANKED" type="BOOLEAN">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="THREAD_ID" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="THREAD_TITLE" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="TITLE" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="TOTAL" type="INT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="URL" type="VARCHAR(3000)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<createTable tableName="METADATA">
|
||||
<column name="POST_ID_REF" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="POST_ID" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="POSTED_BY" type="VARCHAR(255)"/>
|
||||
<column name="RESOLVED_NAMES" type="VARCHAR(16777216)"/>
|
||||
</createTable>
|
||||
<createTable tableName="IMAGE">
|
||||
<column name="ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
@@ -31,61 +81,10 @@
|
||||
<column name="URL" type="VARCHAR(3000)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="POST_ID_REF" type="BIGINT"/>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-3">
|
||||
<createTable tableName="METADATA">
|
||||
<column name="ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="POSTED_BY" type="VARCHAR(255)"/>
|
||||
<column name="RESOLVED_NAMES" type="VARCHAR(16777216)"/>
|
||||
<column name="POST_ID_REF" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-4">
|
||||
<createTable tableName="POST">
|
||||
<column name="ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="DONE" type="INT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="FORUM" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="HOSTS" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="POST_FOLDER_NAME" type="VARCHAR(500)"/>
|
||||
<column name="POST_ID" type="VARCHAR(255)"/>
|
||||
<column name="PREVIEWS" type="VARCHAR(16777216)"/>
|
||||
<column name="SECURITY_TOKEN" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="STATUS" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="THANKED" type="BOOLEAN"/>
|
||||
<column name="THREAD_ID" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="THREAD_TITLE" type="VARCHAR(500)"/>
|
||||
<column name="TITLE" type="VARCHAR(500)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="TOTAL" type="INT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="URL" type="VARCHAR(3000)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-5">
|
||||
<createTable tableName="QUEUED">
|
||||
<column name="ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
@@ -104,69 +103,62 @@
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<createTable tableName="EVENT">
|
||||
<column name="ID" type="BIGINT">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="TYPE" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="STATUS" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="TIME" type="VARCHAR(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="MESSAGE" type="VARCHAR(16777216)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-6">
|
||||
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10092" tableName="IMAGE"/>
|
||||
<changeSet author="death-claw" id="1613151442-2">
|
||||
<createSequence sequenceName="SEQ_IMAGE" incrementBy="1" startValue="1"/>
|
||||
<createSequence sequenceName="SEQ_POST" incrementBy="1" startValue="1"/>
|
||||
<createSequence sequenceName="SEQ_QUEUED" incrementBy="1" startValue="1"/>
|
||||
<createSequence sequenceName="SEQ_EVENT" incrementBy="1" startValue="1"/>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-7">
|
||||
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10110" tableName="METADATA"/>
|
||||
<changeSet author="death-claw" id="1613151442-3">
|
||||
<addPrimaryKey columnNames="ID" constraintName="EVENT_PK" tableName="EVENT"/>
|
||||
<addPrimaryKey columnNames="ID" constraintName="IMAGE_PK" tableName="IMAGE"/>
|
||||
<addPrimaryKey columnNames="POST_ID_REF" constraintName="METADATA_PK" tableName="METADATA"/>
|
||||
<addPrimaryKey columnNames="ID" constraintName="POST_PK" tableName="POST"/>
|
||||
<addPrimaryKey columnNames="ID" constraintName="QUEUED_PK" tableName="QUEUED"/>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-8">
|
||||
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10116" tableName="POST"/>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-9">
|
||||
<addPrimaryKey columnNames="ID" constraintName="SYS_PK_10138" tableName="QUEUED"/>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-10">
|
||||
<changeSet author="death-claw" id="1613151442-4">
|
||||
<createIndex indexName="IMAGE_POST_ID_IDX" tableName="IMAGE">
|
||||
<column name="POST_ID"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-11">
|
||||
<createIndex indexName="IMAGE_STATUS_IDX" tableName="IMAGE">
|
||||
<column name="STATUS"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-12">
|
||||
<createIndex indexName="POST_POST_ID_IDX" tableName="POST">
|
||||
<column name="POST_ID"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-13">
|
||||
<createIndex indexName="POST_STATUS_IDX" tableName="POST">
|
||||
<column name="STATUS"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-14">
|
||||
<createIndex indexName="QUEUED_THREAD_ID_IDX" tableName="QUEUED">
|
||||
<column name="THREAD_ID"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-15">
|
||||
<createIndex indexName="SYS_IDX_IMAGE_POST_ID_REF_POST_ID_FK_10150" tableName="IMAGE">
|
||||
<column name="POST_ID_REF"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-16">
|
||||
<createIndex indexName="SYS_IDX_METADATA_POST_ID_REF_POST_ID_FK_10160" tableName="METADATA">
|
||||
<column name="POST_ID_REF"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-17">
|
||||
<changeSet author="death-claw" id="1613151442-5">
|
||||
<addForeignKeyConstraint baseColumnNames="POST_ID_REF" baseTableName="IMAGE"
|
||||
constraintName="IMAGE_POST_ID_REF_POST_ID_FK" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
|
||||
referencedColumnNames="ID" referencedTableName="POST"/>
|
||||
</changeSet>
|
||||
<changeSet author="sysgen" id="1595764509827-18">
|
||||
<addForeignKeyConstraint baseColumnNames="POST_ID_REF" baseTableName="METADATA"
|
||||
constraintName="METADATA_POST_ID_REF_POST_ID_FK" deferrable="false"
|
||||
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
|
||||
referencedColumnNames="ID" referencedTableName="POST"/>
|
||||
</changeSet>
|
||||
<changeSet id="1600798657000-01" author="sysgen">
|
||||
<createIndex tableName="POST" indexName="POST_UQ_POST_ID_IDX">
|
||||
<column name="POST_ID"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,8 @@
|
||||
[
|
||||
"https://planetviper.club",
|
||||
"https://viperbb.rocks",
|
||||
"https://viperkats.eu",
|
||||
"https://viperohilia.art",
|
||||
"https://viperproxy.org",
|
||||
"https://vipervault.link"
|
||||
]
|
||||
@@ -26,10 +26,17 @@
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets",
|
||||
{ "glob": "mdi.svg", "input": "./node_modules/@mdi/angular-material", "output": "./assets" }
|
||||
{
|
||||
"glob": "mdi.svg",
|
||||
"input": "./node_modules/@mdi/angular-material",
|
||||
"output": "./assets"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.scss"
|
||||
],
|
||||
"allowedCommonJsDependencies": [
|
||||
"@stomp/rx-stomp"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
|
||||
Generated
-13960
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vripper-ui",
|
||||
"version": "3.2.1",
|
||||
"version": "3.3.3",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>tn.mnlr</groupId>
|
||||
<artifactId>vripper</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.3</version>
|
||||
</parent>
|
||||
<artifactId>vripper-ui</artifactId>
|
||||
<name>vripper-ui</name>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
@import '~@angular/material/theming';
|
||||
|
||||
@mixin about-component-theme($theme) {
|
||||
$foreground: map-get($theme, foreground);
|
||||
$background: map-get($theme, background);
|
||||
|
||||
.about-link, .about-icon {
|
||||
color: mat-color($foreground, text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<div class="dialog-container" fxLayout="column" style="height: 100%;">
|
||||
<div fxFlex="nogrow" fxLayout="row" fxLayoutAlign="space-between center">
|
||||
<h2 class="no-wrap" mat-dialog-title>About</h2>
|
||||
</div>
|
||||
<mat-dialog-content class="content" fxFlex="grow">
|
||||
<mat-card class="mat-elevation-z4">
|
||||
<mat-card-header class="header" fxLayout="row" fxLayoutAlign="flex-start center" fxLayoutGap="10px">
|
||||
<div class="header-image" mat-card-avatar></div>
|
||||
<mat-card-title>VRipper</mat-card-title>
|
||||
<mat-card-subtitle>{{version}}</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<section class="section">
|
||||
Due to the lack of cross platform Ripper for vipergirls.to and the official one being no longer maintained,
|
||||
this application was created as a personal project of mine to fulfill the old one's tasks.<br/>
|
||||
Soon after, people were interested in it and i released it to the public.<br/>
|
||||
This project is built to be a robust and clean replacement of the old one, using modern technologies to
|
||||
conveniently download photo galleries from the forum.<br/>
|
||||
I aim to provide you with a software that is easy to use have a nice and intuitive design and interface.<br/>
|
||||
The project is currently maintained by me 'theghooost', a member of the vipergirls.to forum, feel free to PM
|
||||
if you need anything.<br/>
|
||||
</section>
|
||||
<mat-divider></mat-divider>
|
||||
<section class="section">
|
||||
<span fxLayout="row" fxLayoutAlign="flex-start center">
|
||||
<svg class="about-icon" style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M11 6H14L17.29 2.7A1 1 0 0 1 18.71 2.7L21.29 5.29A1 1 0 0 1 21.29 6.7L19 9H11V11A1 1 0 0 1 10 12A1 1 0 0 1 9 11V8A2 2 0 0 1 11 6M5 11V15L2.71 17.29A1 1 0 0 0 2.71 18.7L5.29 21.29A1 1 0 0 0 6.71 21.29L11 17H15A1 1 0 0 0 16 16V15H17A1 1 0 0 0 18 14V13H19A1 1 0 0 0 20 12V11H13V12A2 2 0 0 1 11 14H9A2 2 0 0 1 7 12V9Z"
|
||||
fill="currentColor"/>
|
||||
</svg><h2 class="margin-left no-bottom-margin no-top-margin inline-block">Contribution</h2>
|
||||
</span>
|
||||
You can contribute to the project by testing new releases, raising bug reports or coding.<br/>
|
||||
The project is open source and is hosted in github.com.<br/>
|
||||
<h4 class="no-bottom-margin">Github: </h4><a (click)="goTo('https://github.com/death-claw/vripper-project')"
|
||||
class="about-link" href="javascript:void(0)">https://github.com/death-claw/vripper-project</a>
|
||||
<h4 class="no-bottom-margin">Issues: </h4><a
|
||||
(click)="goTo('https://github.com/death-claw/vripper-project/issues')" class="about-link"
|
||||
href="javascript:void(0)">https://github.com/death-claw/vripper-project/issues</a>
|
||||
<h4 class="no-bottom-margin">PM: </h4><a (click)="goTo('https://vipergirls.to/members/244439-theghooost')"
|
||||
class="about-link" href="javascript:void(0)">https://vipergirls.to/members/244439-theghooost</a>
|
||||
</section>
|
||||
<mat-divider></mat-divider>
|
||||
<section class="section">
|
||||
<span fxLayout="row" fxLayoutAlign="flex-start center">
|
||||
<svg class="about-icon" style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M9.06,1.93C7.17,1.92 5.33,3.74 6.17,6H3A2,2 0 0,0 1,8V10A1,1 0 0,0 2,11H11V8H13V11H22A1,1 0 0,0 23,10V8A2,2 0 0,0 21,6H17.83C19,2.73 14.6,0.42 12.57,3.24L12,4L11.43,3.22C10.8,2.33 9.93,1.94 9.06,1.93M9,4C9.89,4 10.34,5.08 9.71,5.71C9.08,6.34 8,5.89 8,5A1,1 0 0,1 9,4M15,4C15.89,4 16.34,5.08 15.71,5.71C15.08,6.34 14,5.89 14,5A1,1 0 0,1 15,4M2,12V20A2,2 0 0,0 4,22H20A2,2 0 0,0 22,20V12H13V20H11V12H2Z"
|
||||
fill="currentColor"/>
|
||||
</svg><h2 class="margin-left no-bottom-margin no-top-margin inline-block">Donation</h2>
|
||||
</span>
|
||||
If you feel generous and want to support me, you can donate some coins, and I would be very grateful <span
|
||||
style="font-size: 20px">🙏</span><br/>
|
||||
I accept Bitcoin (BTC) for donations, following is my address
|
||||
<h3>bc1q9jzzw3st49r9vmxgtylq4vrd67cl7zfclf3lsq</h3>
|
||||
</section>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end" fxFlex="nogrow">
|
||||
<button mat-dialog-close mat-raised-button>Close</button>
|
||||
</mat-dialog-actions>
|
||||
</div>
|
||||
@@ -0,0 +1,39 @@
|
||||
.header-image {
|
||||
background-size: cover;
|
||||
background-image: url('../../assets/v.svg');
|
||||
}
|
||||
|
||||
.section {
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.header {
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.mat-card-avatar {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.no-bottom-margin {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.no-top-margin {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.inline-block {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.margin-left {
|
||||
margin-left: 5px;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import {ChangeDetectionStrategy, Component} from '@angular/core';
|
||||
import {environment} from '../../environments/environment';
|
||||
import {ElectronService} from 'ngx-electron';
|
||||
|
||||
@Component({
|
||||
selector: 'app-about',
|
||||
templateUrl: './about-component.html',
|
||||
styleUrls: ['./about-component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class AboutComponent {
|
||||
|
||||
version = environment.version;
|
||||
|
||||
constructor(
|
||||
public electronService: ElectronService
|
||||
) {
|
||||
}
|
||||
|
||||
goTo(url: string) {
|
||||
if (this.electronService.isElectronApp) {
|
||||
this.electronService.shell.openExternal(url);
|
||||
} else {
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,9 @@ import {AlternativeTitleComponent} from './posts/alternative-title/alternative-t
|
||||
import {NgxElectronModule} from 'ngx-electron';
|
||||
import {MatIconRegistry} from '@angular/material/icon';
|
||||
import {DomSanitizer} from '@angular/platform-browser';
|
||||
import {EventLogComponent} from './event-log/event-log.component';
|
||||
import {EventLogMessageDialogComponent} from './event-log/message-dialog/event-log-message-dialog.component';
|
||||
import {AboutComponent} from './about/about-component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -45,6 +48,9 @@ import {DomSanitizer} from '@angular/platform-browser';
|
||||
MultiPostGridComponent,
|
||||
PostContextMenuComponent,
|
||||
AlternativeTitleComponent,
|
||||
EventLogComponent,
|
||||
EventLogMessageDialogComponent,
|
||||
AboutComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserAnimationsModule,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
export class EventLog {
|
||||
constructor(
|
||||
public id: number,
|
||||
public type: string,
|
||||
public status: string,
|
||||
public time: string,
|
||||
public message: string
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,6 @@ export interface Settings {
|
||||
resolveTitle: boolean;
|
||||
connectionTimeout: number;
|
||||
maxAttempts: number;
|
||||
vProxy: string;
|
||||
maxEventLog: number;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<div style="width: 100%; height: 100%">
|
||||
<ag-grid-angular [gridOptions]="gridOptions" class="ag-theme-alpine" style="width: 100%; height: 100%">
|
||||
</ag-grid-angular>
|
||||
</div>
|
||||
@@ -0,0 +1,104 @@
|
||||
import {ChangeDetectionStrategy, Component, NgZone, OnDestroy} from '@angular/core';
|
||||
import {GridOptions} from 'ag-grid-community';
|
||||
import {WsConnectionService} from '../services/ws-connection.service';
|
||||
import {EventLogDatasource} from './event-log.datasource';
|
||||
import {StatusRendererNative} from '../grid-custom-cells/status-renderer.native';
|
||||
import {EventLogService} from '../services/event-log.service';
|
||||
import {EventMessageRendererNative} from '../grid-custom-cells/event-message-renderer.native';
|
||||
|
||||
@Component({
|
||||
selector: 'app-event-log',
|
||||
templateUrl: './event-log.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class EventLogComponent implements OnDestroy {
|
||||
gridOptions: GridOptions;
|
||||
dataSource: EventLogDatasource;
|
||||
|
||||
constructor(
|
||||
private wsConnection: WsConnectionService,
|
||||
private zone: NgZone,
|
||||
private eventLogService: EventLogService
|
||||
) {
|
||||
this.gridOptions = <GridOptions>{
|
||||
columnDefs: [
|
||||
{
|
||||
headerName: 'Time',
|
||||
field: 'time',
|
||||
sort: 'desc',
|
||||
width: 250,
|
||||
maxWidth: 250
|
||||
}, {
|
||||
headerName: 'Type',
|
||||
field: 'type',
|
||||
valueGetter: (params => {
|
||||
switch (params.data.type) {
|
||||
case 'POST':
|
||||
return '🖼️ New gallery';
|
||||
case 'THANKS':
|
||||
return '👍 Sending a like ';
|
||||
case 'SCAN':
|
||||
return '🔍 Links scan';
|
||||
case 'METADATA':
|
||||
case 'METADATA_CACHE_MISS':
|
||||
return '🗄️ Loading post metadata';
|
||||
case 'QUEUED':
|
||||
case 'QUEUED_CACHE_MISS':
|
||||
return '📋 Loading multi-post link';
|
||||
case 'DOWNLOAD':
|
||||
return '📥 Download';
|
||||
default:
|
||||
return params.data.type;
|
||||
}
|
||||
}),
|
||||
width: 250,
|
||||
maxWidth: 250
|
||||
}, {
|
||||
headerName: 'Status',
|
||||
field: 'status',
|
||||
cellRenderer: 'nativeStatusCellRenderer',
|
||||
width: 150,
|
||||
maxWidth: 150
|
||||
}, {
|
||||
headerName: 'Message',
|
||||
field: 'message',
|
||||
flex: 1,
|
||||
cellRenderer: 'messageCellRenderer',
|
||||
cellRendererParams: {
|
||||
eventLogService: this.eventLogService
|
||||
},
|
||||
}
|
||||
],
|
||||
defaultColDef: {
|
||||
sortable: true,
|
||||
resizable: true
|
||||
},
|
||||
rowHeight: 26,
|
||||
headerHeight: 35,
|
||||
animateRows: true,
|
||||
rowSelection: 'single',
|
||||
rowDeselection: true,
|
||||
rowData: [],
|
||||
components: {
|
||||
nativeStatusCellRenderer: StatusRendererNative,
|
||||
messageCellRenderer: EventMessageRendererNative,
|
||||
},
|
||||
overlayLoadingTemplate: '<span></span>',
|
||||
overlayNoRowsTemplate: '<span></span>',
|
||||
getRowNodeId: data => data['id'],
|
||||
onGridReady: () => {
|
||||
this.eventLogService.setGridApi(this.gridOptions.api);
|
||||
this.dataSource = new EventLogDatasource(this.wsConnection, this.gridOptions, this.zone);
|
||||
this.dataSource.connect();
|
||||
},
|
||||
onRowDataUpdated: () => this.eventLogService.setCount(this.gridOptions.api.getDisplayedRowCount()),
|
||||
onRowDataChanged: () => this.eventLogService.setCount(this.gridOptions.api.getDisplayedRowCount()),
|
||||
};
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.dataSource) {
|
||||
this.dataSource.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import {Subscription} from 'rxjs';
|
||||
import {WsConnectionService} from '../services/ws-connection.service';
|
||||
import {GridOptions, RowNode} from 'ag-grid-community';
|
||||
import {NgZone} from '@angular/core';
|
||||
import {EventLog} from '../domain/event.model';
|
||||
|
||||
export class EventLogDatasource {
|
||||
subscriptions: Subscription[] = [];
|
||||
|
||||
constructor(private ws: WsConnectionService, private gridOptions: GridOptions, private zone: NgZone) {
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.subscriptions.push(this.ws.events$.subscribe((e: EventLog[]) => {
|
||||
this.zone.run(() => {
|
||||
const toAdd = [];
|
||||
const toUpdate = [];
|
||||
e.forEach(v => {
|
||||
if (this.gridOptions.api.getRowNode(v.id.toString(10)) == null) {
|
||||
toAdd.push(v);
|
||||
} else {
|
||||
toUpdate.push(v);
|
||||
}
|
||||
});
|
||||
this.gridOptions.api.applyTransaction({update: toUpdate, add: toAdd});
|
||||
});
|
||||
}));
|
||||
|
||||
this.subscriptions.push(this.ws.eventsRemove$.subscribe((e: number[]) => {
|
||||
this.zone.run(() => {
|
||||
const toRemove = [];
|
||||
e.forEach(v => {
|
||||
const rowNode: RowNode = this.gridOptions.api.getRowNode(v.toString(10));
|
||||
if (rowNode != null) {
|
||||
toRemove.push(rowNode.data);
|
||||
}
|
||||
return;
|
||||
});
|
||||
this.gridOptions.api.applyTransaction({remove: toRemove});
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
console.log('Disconnecting from events datasource');
|
||||
this.subscriptions.forEach(e => e.unsubscribe());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<div class="dialog-container" fxLayout="column" style="height: 100%;">
|
||||
<h2 class="no-wrap" mat-dialog-title>Message</h2>
|
||||
<mat-dialog-content fxFlex="grow">
|
||||
<pre>{{data}}</pre>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end" fxFlex="nogrow">
|
||||
<button (click)="close()" color="primary" mat-raised-button>Close</button>
|
||||
</mat-dialog-actions>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import {ChangeDetectionStrategy, Component, Inject, NgZone} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-event-log-message-dialog',
|
||||
templateUrl: './event-log-message-dialog.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class EventLogMessageDialogComponent {
|
||||
|
||||
constructor(public dialogRef: MatDialogRef<EventLogMessageDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: string,
|
||||
private ngZone: NgZone) {
|
||||
}
|
||||
|
||||
close() {
|
||||
this.ngZone.run(() => this.dialogRef.close());
|
||||
}
|
||||
}
|
||||
@@ -32,14 +32,14 @@ export class CollectorActionsRendererNative implements ICellRendererComp {
|
||||
this.selectButton = document.createElement('button');
|
||||
this.selectButton.classList.add('mat-icon-button', 'mat-button-base', 'cell-icon');
|
||||
this.selectButton.setAttribute('style', 'width: auto; height: 24px; display: flex; align-items: center');
|
||||
this.selectButton.innerHTML = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M20,2H8A2,2 0 0,0 6,4V16A2,2 0 0,0 8,18H20A2,2 0 0,0 22,16V4A2,2 0 0,0 20,2M20,16H8V4H20V16M16,20V22H4A2,2 0 0,1 2,20V7H4V20H16M18.53,8.06L17.47,7L12.59,11.88L10.47,9.76L9.41,10.82L12.59,14L18.53,8.06Z" /></svg><span>Select</span>`;
|
||||
this.selectButton.innerHTML = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M20,2H8A2,2 0 0,0 6,4V16A2,2 0 0,0 8,18H20A2,2 0 0,0 22,16V4A2,2 0 0,0 20,2M20,16H8V4H20V16M16,20V22H4A2,2 0 0,1 2,20V7H4V20H16M18.53,8.06L17.47,7L12.59,11.88L10.47,9.76L9.41,10.82L12.59,14L18.53,8.06Z" /></svg><span style="margin-left: 5px">Select</span>`;
|
||||
this.selectSpan.append(this.selectButton);
|
||||
|
||||
this.deleteSpan = document.createElement('span');
|
||||
this.deleteButton = document.createElement('button');
|
||||
this.deleteButton.classList.add('mat-icon-button', 'mat-button-base', 'cell-icon');
|
||||
this.deleteButton.setAttribute('style', 'width: auto; height: 24px; display: flex; align-items: center');
|
||||
this.deleteButton.innerHTML = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" /></svg><span>Remove</span>`;
|
||||
this.deleteButton.innerHTML = `<svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z" /></svg><span style="margin-left: 5px">Remove</span>`;
|
||||
this.deleteSpan.append(this.deleteButton);
|
||||
|
||||
this.gui.append(this.selectSpan, this.deleteSpan);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import {GridApi, ICellRendererComp, ICellRendererParams} from 'ag-grid-community';
|
||||
import {EventLog} from '../domain/event.model';
|
||||
import {EventLogService} from '../services/event-log.service';
|
||||
|
||||
export class EventMessageRendererNative implements ICellRendererComp {
|
||||
private gui: HTMLElement;
|
||||
private viewSpan: HTMLSpanElement;
|
||||
private viewButton: HTMLButtonElement;
|
||||
private eventLogService: EventLogService;
|
||||
private eventLog: EventLog;
|
||||
private gridApi: GridApi;
|
||||
private text: HTMLSpanElement;
|
||||
|
||||
destroy(): void {
|
||||
this.viewButton.removeEventListener('click', () => this.eventLogService.openDialog(this.eventLog.message));
|
||||
}
|
||||
|
||||
getGui(): HTMLElement {
|
||||
return this.gui;
|
||||
}
|
||||
|
||||
init(params: ICellRendererParams): void {
|
||||
// @ts-ignore
|
||||
this.eventLogService = params.eventLogService;
|
||||
this.eventLog = params.node.data;
|
||||
this.gridApi = params.api;
|
||||
this.gui = document.createElement('div');
|
||||
this.gui.setAttribute('style', 'display: flex; justify-content: space-between;');
|
||||
this.text = document.createElement('span');
|
||||
this.text.classList.add('no-wrap');
|
||||
this.text.textContent = this.eventLog.message;
|
||||
this.viewSpan = document.createElement('span');
|
||||
this.viewButton = document.createElement('button');
|
||||
this.viewButton.classList.add('mat-icon-button', 'mat-button-base', 'cell-icon');
|
||||
this.viewButton.setAttribute('style', 'width: auto; height: 24px; display: flex; align-items: center');
|
||||
this.viewButton.innerHTML = `<svg style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z" /></svg><span style="margin-left: 5px">View</span>`;
|
||||
this.viewSpan.append(this.viewButton);
|
||||
|
||||
this.gui.append(this.text, this.viewSpan);
|
||||
|
||||
this.viewButton.addEventListener('click', () => this.eventLogService.openDialog(this.eventLog.message));
|
||||
}
|
||||
|
||||
refresh(params: ICellRendererParams): boolean {
|
||||
this.eventLog = params.node.data;
|
||||
this.text.textContent = this.eventLog.message;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,13 @@ export class StatusRendererNative implements ICellRendererComp {
|
||||
case 'DOWNLOADING':
|
||||
return `<svg style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z" />
|
||||
</svg>`;
|
||||
case 'PROCESSING':
|
||||
return `<svg style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M15.9,18.45C17.25,18.45 18.35,17.35 18.35,16C18.35,14.65 17.25,13.55 15.9,13.55C14.54,13.55 13.45,14.65 13.45,16C13.45,17.35 14.54,18.45 15.9,18.45M21.1,16.68L22.58,17.84C22.71,17.95 22.75,18.13 22.66,18.29L21.26,20.71C21.17,20.86 21,20.92 20.83,20.86L19.09,20.16C18.73,20.44 18.33,20.67 17.91,20.85L17.64,22.7C17.62,22.87 17.47,23 17.3,23H14.5C14.32,23 14.18,22.87 14.15,22.7L13.89,20.85C13.46,20.67 13.07,20.44 12.71,20.16L10.96,20.86C10.81,20.92 10.62,20.86 10.54,20.71L9.14,18.29C9.05,18.13 9.09,17.95 9.22,17.84L10.7,16.68L10.65,16L10.7,15.31L9.22,14.16C9.09,14.05 9.05,13.86 9.14,13.71L10.54,11.29C10.62,11.13 10.81,11.07 10.96,11.13L12.71,11.84C13.07,11.56 13.46,11.32 13.89,11.15L14.15,9.29C14.18,9.13 14.32,9 14.5,9H17.3C17.47,9 17.62,9.13 17.64,9.29L17.91,11.15C18.33,11.32 18.73,11.56 19.09,11.84L20.83,11.13C21,11.07 21.17,11.13 21.26,11.29L22.66,13.71C22.75,13.86 22.71,14.05 22.58,14.16L21.1,15.31L21.15,16L21.1,16.68M6.69,8.07C7.56,8.07 8.26,7.37 8.26,6.5C8.26,5.63 7.56,4.92 6.69,4.92A1.58,1.58 0 0,0 5.11,6.5C5.11,7.37 5.82,8.07 6.69,8.07M10.03,6.94L11,7.68C11.07,7.75 11.09,7.87 11.03,7.97L10.13,9.53C10.08,9.63 9.96,9.67 9.86,9.63L8.74,9.18L8,9.62L7.81,10.81C7.79,10.92 7.7,11 7.59,11H5.79C5.67,11 5.58,10.92 5.56,10.81L5.4,9.62L4.64,9.18L3.5,9.63C3.41,9.67 3.3,9.63 3.24,9.53L2.34,7.97C2.28,7.87 2.31,7.75 2.39,7.68L3.34,6.94L3.31,6.5L3.34,6.06L2.39,5.32C2.31,5.25 2.28,5.13 2.34,5.03L3.24,3.47C3.3,3.37 3.41,3.33 3.5,3.37L4.63,3.82L5.4,3.38L5.56,2.19C5.58,2.08 5.67,2 5.79,2H7.59C7.7,2 7.79,2.08 7.81,2.19L8,3.38L8.74,3.82L9.86,3.37C9.96,3.33 10.08,3.37 10.13,3.47L11.03,5.03C11.09,5.13 11.07,5.25 11,5.32L10.03,6.06L10.06,6.5L10.03,6.94Z" />
|
||||
</svg>`;
|
||||
case 'COMPLETE':
|
||||
case 'DONE':
|
||||
return `<svg style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
|
||||
</svg>`;
|
||||
@@ -86,8 +91,10 @@ export class StatusRendererNative implements ICellRendererComp {
|
||||
case 'PENDING':
|
||||
return 'pending';
|
||||
case 'DOWNLOADING':
|
||||
case 'PROCESSING':
|
||||
return 'downloading';
|
||||
case 'COMPLETE':
|
||||
case 'DONE':
|
||||
return 'complete';
|
||||
case 'ERROR':
|
||||
return 'error';
|
||||
|
||||
@@ -1,15 +1,31 @@
|
||||
<mat-tab-group animationDuration="0" dynamicHeight style="height: 100%; margin-bottom: 20px;">
|
||||
<mat-tab label="Downloads">
|
||||
<mat-tab-group (selectedTabChange)="onTabChange($event)" animationDuration="0" dynamicHeight
|
||||
style="height: 100%; margin-bottom: 20px;">
|
||||
<mat-tab>
|
||||
<ng-template mat-tab-label>
|
||||
<span>Downloads</span>
|
||||
<ng-container *ngIf="postsService.count | async as count">
|
||||
<mat-icon [matBadgeHidden]="count < 1" [matBadge]="count" class="icon">photo_album</mat-icon>
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
<app-posts></app-posts>
|
||||
</mat-tab>
|
||||
<mat-tab>
|
||||
<ng-template mat-tab-label>
|
||||
<span>Multi-post links</span>
|
||||
<ng-container *ngIf="linkCollectorService.count | async as count">
|
||||
<mat-icon [matBadgeHidden]="count < 1" [matBadge]="count">link</mat-icon>
|
||||
<mat-icon [matBadgeHidden]="count < 1" [matBadge]="count" class="icon">link</mat-icon>
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
<app-grab-queue></app-grab-queue>
|
||||
</mat-tab>
|
||||
<mat-tab>
|
||||
<ng-template mat-tab-label>
|
||||
<span>Event Log</span>
|
||||
<ng-container *ngIf="eventLogService.count | async as count">
|
||||
<mat-icon [matBadgeHidden]="count < 1" [matBadge]="count" class="icon">grid_on</mat-icon>
|
||||
</ng-container>
|
||||
</ng-template>
|
||||
<app-event-log></app-event-log>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
|
||||
|
||||
@@ -47,3 +47,7 @@ table {
|
||||
align-self: start;
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ import {ChangeDetectionStrategy, Component, NgZone, OnDestroy, OnInit} from '@an
|
||||
import {MatDialog} from '@angular/material/dialog';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {EventLogService} from '../services/event-log.service';
|
||||
import {PostsService} from '../services/posts.service';
|
||||
import {MatTabChangeEvent} from '@angular/material/tabs';
|
||||
import {HomeTabsService} from '../services/home-tabs.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -23,7 +27,10 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
private serverService: ServerService,
|
||||
private _snackBar: MatSnackBar,
|
||||
private ngZone: NgZone,
|
||||
public linkCollectorService: LinkCollectorService
|
||||
public linkCollectorService: LinkCollectorService,
|
||||
public eventLogService: EventLogService,
|
||||
public postsService: PostsService,
|
||||
public homeTabsService: HomeTabsService
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -53,4 +60,8 @@ export class HomeComponent implements OnInit, OnDestroy {
|
||||
this.clipboardSub.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
onTabChange($event: MatTabChangeEvent) {
|
||||
this.homeTabsService.setIndex($event.index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ export class MultiPostGridDataSource {
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
console.log('Disconnecting from link collector datasource');
|
||||
this.subscriptions.forEach(e => e.unsubscribe());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,14 +67,18 @@ export class MultiPostGridComponent implements OnDestroy {
|
||||
overlayNoRowsTemplate: '<span></span>',
|
||||
getRowNodeId: data => data['threadId'],
|
||||
onGridReady: () => {
|
||||
this.linkCollectorService.setGridApi(this.gridOptions.api);
|
||||
this.dataSource = new MultiPostGridDataSource(this.wsConnection, this.gridOptions, this.zone);
|
||||
this.dataSource.connect();
|
||||
},
|
||||
onRowDataUpdated: () => this.linkCollectorService.setCount(this.gridOptions.api.getDisplayedRowCount()),
|
||||
onRowDataChanged: () => this.linkCollectorService.setCount(this.gridOptions.api.getDisplayedRowCount()),
|
||||
};
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.dataSource.disconnect();
|
||||
if (this.dataSource) {
|
||||
this.dataSource.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import {ChangeDetectionStrategy, Component, NgZone, OnDestroy} from '@angular/co
|
||||
import {PostsDataSource} from './posts.datasource';
|
||||
import {WsConnectionService} from '../services/ws-connection.service';
|
||||
import {GridOptions} from 'ag-grid-community';
|
||||
import {Subject} from 'rxjs';
|
||||
import {PostContextMenuService} from '../services/post-context-menu.service';
|
||||
import {PostProgressRendererNative} from '../grid-custom-cells/post-progress-renderer.native';
|
||||
import {PostStatusRendererNative} from '../grid-custom-cells/post-status-renderer.native';
|
||||
@@ -19,7 +18,6 @@ import {PostsService} from '../services/posts.service';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class PostsComponent implements OnDestroy {
|
||||
dialogOpen: Subject<boolean> = new Subject();
|
||||
gridOptions: GridOptions;
|
||||
dataSource: PostsDataSource;
|
||||
|
||||
@@ -30,7 +28,8 @@ export class PostsComponent implements OnDestroy {
|
||||
private postsDataService: PostsService,
|
||||
private contextMenuService: PostContextMenuService,
|
||||
private overlayPositionBuilder: OverlayPositionBuilder,
|
||||
private overlay: Overlay
|
||||
private overlay: Overlay,
|
||||
private postsService: PostsService
|
||||
) {
|
||||
this.gridOptions = <GridOptions>{
|
||||
columnDefs: [
|
||||
@@ -110,11 +109,15 @@ export class PostsComponent implements OnDestroy {
|
||||
this.dataSource.connect();
|
||||
},
|
||||
onSelectionChanged: () => this.selectionService.onSelectionChanged(this.gridOptions.api.getSelectedNodes()),
|
||||
onBodyScroll: () => this.contextMenuService.closePostContextMenu()
|
||||
onBodyScroll: () => this.contextMenuService.closePostContextMenu(),
|
||||
onRowDataUpdated: () => this.postsService.setCount(this.gridOptions.api.getDisplayedRowCount()),
|
||||
onRowDataChanged: () => this.postsService.setCount(this.gridOptions.api.getDisplayedRowCount()),
|
||||
};
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.dataSource.disconnect();
|
||||
if (this.dataSource) {
|
||||
this.dataSource.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
||||
import {GridApi} from 'ag-grid-community';
|
||||
import {MatDialog, MatDialogConfig} from '@angular/material/dialog';
|
||||
import {EventLogMessageDialogComponent} from '../event-log/message-dialog/event-log-message-dialog.component';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EventLogService {
|
||||
private api: GridApi;
|
||||
|
||||
private _count$: Subject<number> = new BehaviorSubject(0);
|
||||
|
||||
constructor(public dialog: MatDialog) {
|
||||
}
|
||||
|
||||
get count(): Observable<number> {
|
||||
return this._count$.asObservable();
|
||||
}
|
||||
|
||||
setCount(count: number) {
|
||||
this._count$.next(count);
|
||||
}
|
||||
|
||||
public setGridApi(api: GridApi) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
search(event) {
|
||||
if (this.api) {
|
||||
this.api.setQuickFilter(event);
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
if (this.api) {
|
||||
this.api.setRowData([]);
|
||||
}
|
||||
}
|
||||
|
||||
openDialog(message: string) {
|
||||
console.log(message);
|
||||
const config: MatDialogConfig<string> = {
|
||||
width: '70%',
|
||||
height: '70%',
|
||||
maxWidth: '100vw',
|
||||
maxHeight: '100vh',
|
||||
data: message
|
||||
};
|
||||
this.dialog.open(EventLogMessageDialogComponent, config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HomeTabsService {
|
||||
|
||||
private _index$: Subject<number> = new BehaviorSubject(0);
|
||||
|
||||
get index(): Observable<number> {
|
||||
return this._index$.asObservable();
|
||||
}
|
||||
|
||||
setIndex(count: number) {
|
||||
this._index$.next(count);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
||||
import {GridApi} from 'ag-grid-community';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LinkCollectorService {
|
||||
private api: GridApi;
|
||||
|
||||
private _count$: Subject<number> = new BehaviorSubject(0);
|
||||
|
||||
@@ -12,7 +14,23 @@ export class LinkCollectorService {
|
||||
return this._count$.asObservable();
|
||||
}
|
||||
|
||||
public setGridApi(api: GridApi) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
search(event) {
|
||||
if (this.api) {
|
||||
this.api.setQuickFilter(event);
|
||||
}
|
||||
}
|
||||
|
||||
setCount(count: number) {
|
||||
this._count$.next(count);
|
||||
}
|
||||
|
||||
clear() {
|
||||
if (this.api) {
|
||||
this.api.setRowData([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {GridApi} from 'ag-grid-community';
|
||||
import {BehaviorSubject, Observable, Subject} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -7,6 +8,16 @@ import {GridApi} from 'ag-grid-community';
|
||||
export class PostsService {
|
||||
private api: GridApi;
|
||||
|
||||
private _count$: Subject<number> = new BehaviorSubject(0);
|
||||
|
||||
get count(): Observable<number> {
|
||||
return this._count$.asObservable();
|
||||
}
|
||||
|
||||
setCount(count: number) {
|
||||
this._count$.next(count);
|
||||
}
|
||||
|
||||
public setGridApi(api: GridApi) {
|
||||
this.api = api;
|
||||
}
|
||||
@@ -23,6 +34,8 @@ export class PostsService {
|
||||
}
|
||||
|
||||
search(event) {
|
||||
this.api.setQuickFilter(event);
|
||||
if (this.api) {
|
||||
this.api.setQuickFilter(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {GlobalState} from '../domain/global-state.model';
|
||||
import {map, share} from 'rxjs/operators';
|
||||
import {RxStomp, RxStompConfig, RxStompState} from '@stomp/rx-stomp';
|
||||
import {ElectronService} from 'ngx-electron';
|
||||
import {EventLog} from '../domain/event.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -22,10 +23,12 @@ export class WsConnectionService {
|
||||
private speed: Observable<DownloadSpeed>;
|
||||
private user: Observable<LoggedUser>;
|
||||
private posts: Observable<Array<Post>>;
|
||||
private events: Observable<Array<EventLog>>;
|
||||
private postDetails: Observable<Array<Photo>>;
|
||||
private multiPostModels: Observable<Array<MultiPostModel>>;
|
||||
private queuedRemove: Observable<Array<string>>;
|
||||
private postsRemove: Observable<Array<string>>;
|
||||
private eventsRemove: Observable<Array<number>>;
|
||||
private postIdDetails: string;
|
||||
|
||||
private connectionState$: Subject<RxStompState> = new BehaviorSubject(RxStompState.CLOSED);
|
||||
@@ -59,6 +62,14 @@ export class WsConnectionService {
|
||||
return this.postsRemove;
|
||||
}
|
||||
|
||||
get events$(): Observable<EventLog[]> {
|
||||
return this.events;
|
||||
}
|
||||
|
||||
get eventsRemove$(): Observable<number[]> {
|
||||
return this.eventsRemove;
|
||||
}
|
||||
|
||||
get queuedRemove$(): Observable<string[]> {
|
||||
return this.queuedRemove;
|
||||
}
|
||||
@@ -121,6 +132,13 @@ export class WsConnectionService {
|
||||
share()
|
||||
);
|
||||
|
||||
this.eventsRemove = this.rxStomp.watch('/topic/events/deleted').pipe(
|
||||
map(e => {
|
||||
return JSON.parse(e.body);
|
||||
}),
|
||||
share()
|
||||
);
|
||||
|
||||
this.queuedRemove = this.rxStomp.watch('/topic/queued/deleted').pipe(
|
||||
map(e => {
|
||||
return JSON.parse(e.body);
|
||||
@@ -176,6 +194,25 @@ export class WsConnectionService {
|
||||
share()
|
||||
);
|
||||
|
||||
this.events = this.rxStomp.watch('/topic/events').pipe(
|
||||
map(e => {
|
||||
const events: Array<EventLog> = [];
|
||||
(<Array<any>>JSON.parse(e.body)).forEach(element => {
|
||||
events.push(
|
||||
new EventLog(
|
||||
element.id,
|
||||
element.type,
|
||||
element.status,
|
||||
element.time,
|
||||
element.message
|
||||
)
|
||||
);
|
||||
});
|
||||
return events;
|
||||
}),
|
||||
share()
|
||||
);
|
||||
|
||||
this.multiPostModels = this.rxStomp.watch('/topic/queued').pipe(
|
||||
map(e => {
|
||||
const multiPostModels: Array<MultiPostModel> = [];
|
||||
|
||||
@@ -134,6 +134,13 @@
|
||||
</mat-tab>
|
||||
<mat-tab label="ViperGirls">
|
||||
<form [formGroup]="viperGirlsSettingsForm" autocomplete="off" fxLayout="column">
|
||||
<mat-form-field>
|
||||
<mat-label>Select a proxy</mat-label>
|
||||
<mat-select formControlName="vProxy" name="vProxy">
|
||||
<mat-option *ngFor="let mirror of mirrors | async" [value]="mirror">{{mirror}}</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-slide-toggle color="primary" formControlName="vLogin" name="vLogin">
|
||||
Enable ViperGirls Authentication
|
||||
</mat-slide-toggle>
|
||||
@@ -154,21 +161,44 @@
|
||||
</mat-form-field>
|
||||
|
||||
<section class="input">
|
||||
<mat-checkbox color="primary" formControlName="vThanks" name="vThanks">Leave thanks</mat-checkbox>
|
||||
<mat-icon matTooltip="Automatically leave a thanks to the poster"
|
||||
<mat-checkbox color="primary" formControlName="vThanks" name="vThanks">Send a like to poster
|
||||
</mat-checkbox>
|
||||
<mat-icon matTooltip="Automatically send a like to the poster"
|
||||
svgIcon="help-circle-outline"></mat-icon>
|
||||
</section>
|
||||
<section class="input">
|
||||
<mat-checkbox color="primary" formControlName="leaveThanksOnStart" name="leaveThanksOnStart">Leave
|
||||
thanks when download starts
|
||||
<mat-checkbox color="primary" formControlName="leaveThanksOnStart" name="leaveThanksOnStart">Send a like
|
||||
when download starts
|
||||
</mat-checkbox>
|
||||
<mat-icon
|
||||
matTooltip="Leave a thanks only when the download starts, if unchecked, leave a thanks once a gallery is added to the download queue"
|
||||
matTooltip="Send a like only when the download starts, if unchecked, send a like once a gallery is added to the download queue"
|
||||
svgIcon="help-circle-outline"></mat-icon>
|
||||
</section>
|
||||
</section>
|
||||
</form>
|
||||
</mat-tab>
|
||||
<mat-tab label="Event Log">
|
||||
<form [formGroup]="eventLogSettingsForm" autocomplete="off" fxLayout="column">
|
||||
<section class="full-width" fxLayout="row" fxLayoutAlign="space-between center" fxLayoutGap="5px">
|
||||
<mat-form-field fxFlex="grow">
|
||||
<input
|
||||
formControlName="maxEventLog"
|
||||
matInput
|
||||
max="10000"
|
||||
min="100"
|
||||
name="maxEventLog"
|
||||
placeholder="Maximum records"
|
||||
required
|
||||
type="number"
|
||||
/>
|
||||
</mat-form-field>
|
||||
<mat-icon
|
||||
matTooltip="Oldest records will be removed once the maximum amount is reached"
|
||||
svgIcon="help-circle-outline">
|
||||
</mat-icon>
|
||||
</section>
|
||||
</form>
|
||||
</mat-tab>
|
||||
<mat-tab *ngIf="electronService.isElectronApp" label="Desktop Integration">
|
||||
<form [formGroup]="desktopSettingsForm" autocomplete="off">
|
||||
<section class="input">
|
||||
@@ -188,11 +218,12 @@
|
||||
<button
|
||||
(click)="onSubmit()"
|
||||
[disabled]="
|
||||
(desktopSettingsForm.pristine && connectionSettingsForm.pristine && downloadSettingsForm.pristine && viperGirlsSettingsForm.pristine) ||
|
||||
(desktopSettingsForm.pristine && connectionSettingsForm.pristine && downloadSettingsForm.pristine && viperGirlsSettingsForm.pristine && eventLogSettingsForm.pristine) ||
|
||||
viperGirlsSettingsForm.invalid ||
|
||||
downloadSettingsForm.invalid ||
|
||||
connectionSettingsForm.invalid ||
|
||||
desktopSettingsForm.invalid ||
|
||||
eventLogSettingsForm.invalid ||
|
||||
loading
|
||||
"
|
||||
color="primary"
|
||||
|
||||
@@ -13,3 +13,7 @@ form {
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import {finalize} from 'rxjs/operators';
|
||||
import {AppService} from '../services/app.service';
|
||||
import {ClipboardService} from '../services/clipboard.service';
|
||||
import {ChangeDetectionStrategy, Component, NgZone, OnInit} from '@angular/core';
|
||||
import {ChangeDetectionStrategy, Component, NgZone, OnDestroy, OnInit} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {FormControl, FormGroup} from '@angular/forms';
|
||||
import {MatSnackBar} from '@angular/material/snack-bar';
|
||||
import {ServerService} from '../services/server-service';
|
||||
import {ElectronService} from 'ngx-electron';
|
||||
import {Settings} from '../domain/settings.model';
|
||||
import {EMPTY, Observable, Subscription} from 'rxjs';
|
||||
import OpenDialogReturnValue = Electron.OpenDialogReturnValue;
|
||||
|
||||
@Component({
|
||||
@@ -16,16 +17,21 @@ import OpenDialogReturnValue = Electron.OpenDialogReturnValue;
|
||||
styleUrls: ['./settings.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class SettingsComponent implements OnInit {
|
||||
export class SettingsComponent implements OnInit, OnDestroy {
|
||||
loading = false;
|
||||
darkTheme = false;
|
||||
|
||||
mirrors: Observable<string[]> = EMPTY;
|
||||
|
||||
subscriptions: Subscription[] = [];
|
||||
|
||||
viperGirlsSettingsForm = new FormGroup({
|
||||
vLogin: new FormControl(false),
|
||||
vUsername: new FormControl(''),
|
||||
vPassword: new FormControl(''),
|
||||
vThanks: new FormControl(false),
|
||||
leaveThanksOnStart: new FormControl(false)
|
||||
leaveThanksOnStart: new FormControl(false),
|
||||
vProxy: new FormControl('')
|
||||
});
|
||||
|
||||
downloadSettingsForm = new FormGroup({
|
||||
@@ -49,6 +55,10 @@ export class SettingsComponent implements OnInit {
|
||||
desktopClipboard: new FormControl(false)
|
||||
});
|
||||
|
||||
eventLogSettingsForm = new FormGroup({
|
||||
maxEventLog: new FormControl('')
|
||||
});
|
||||
|
||||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
private _snackBar: MatSnackBar,
|
||||
@@ -58,6 +68,15 @@ export class SettingsComponent implements OnInit {
|
||||
private appService: AppService,
|
||||
private zone: NgZone
|
||||
) {
|
||||
this.subscriptions.push(this.viperGirlsSettingsForm.get('vThanks').valueChanges.subscribe(c => {
|
||||
const formControl: FormControl = this.viperGirlsSettingsForm.get('leaveThanksOnStart') as FormControl;
|
||||
if (!c) {
|
||||
formControl.setValue(false);
|
||||
formControl.disable();
|
||||
} else {
|
||||
formControl.enable();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
updateTheme() {
|
||||
@@ -70,12 +89,14 @@ export class SettingsComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.darkTheme = this.appService.darkTheme;
|
||||
this.mirrors = this.httpClient.get<string[]>(this.serverService.baseUrl + '/settings/proxies');
|
||||
this.httpClient.get<Settings>(this.serverService.baseUrl + '/settings')
|
||||
.subscribe(data => {
|
||||
this.viperGirlsSettingsForm.reset(data);
|
||||
this.downloadSettingsForm.reset(data);
|
||||
this.connectionSettingsForm.reset(data);
|
||||
this.desktopSettingsForm.reset(data);
|
||||
this.eventLogSettingsForm.reset(data);
|
||||
}, error => {
|
||||
this._snackBar.open(error?.error?.message || 'Unexpected error, check log file', null, {
|
||||
duration: 5000
|
||||
@@ -83,6 +104,10 @@ export class SettingsComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscriptions.forEach(s => s.unsubscribe());
|
||||
}
|
||||
|
||||
browse() {
|
||||
this.electronService.remote.dialog
|
||||
.showOpenDialog(this.electronService.remote.getCurrentWindow(), {
|
||||
@@ -107,7 +132,8 @@ export class SettingsComponent implements OnInit {
|
||||
...this.downloadSettingsForm.value,
|
||||
...this.connectionSettingsForm.value,
|
||||
darkTheme: this.darkTheme,
|
||||
...this.desktopSettingsForm.value
|
||||
...this.desktopSettingsForm.value,
|
||||
...this.eventLogSettingsForm.value
|
||||
})
|
||||
.pipe(finalize(() => (this.loading = false)))
|
||||
.subscribe(
|
||||
@@ -119,6 +145,7 @@ export class SettingsComponent implements OnInit {
|
||||
this.downloadSettingsForm.reset(data);
|
||||
this.connectionSettingsForm.reset(data);
|
||||
this.desktopSettingsForm.reset(data);
|
||||
this.eventLogSettingsForm.reset(data);
|
||||
this.clipboardService.init(data);
|
||||
this.updateSettings(data);
|
||||
},
|
||||
|
||||
@@ -4,37 +4,50 @@
|
||||
<button (click)="scan()" class="add-button" color="primary" mat-icon-button matTooltip="Add links">
|
||||
<mat-icon>add</mat-icon>
|
||||
</button>
|
||||
<button (click)="remove()" [disabled]="disableSelection$ | async" mat-icon-button
|
||||
matTooltip="Remove selected">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
<button (click)="restart()" [disabled]="disableSelection$ | async" mat-icon-button
|
||||
matTooltip="Start selected">
|
||||
<mat-icon>play_arrow</mat-icon>
|
||||
</button>
|
||||
<button (click)="stop()" [disabled]="disableSelection$ | async" mat-icon-button
|
||||
matTooltip="Stop selected">
|
||||
<mat-icon>pause</mat-icon>
|
||||
</button>
|
||||
<button (click)="rename()" [disabled]="disableSelection$ | async"
|
||||
mat-icon-button
|
||||
matTooltip="Rename selected to first alternative title">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<div class="or-spacer-vertical left">
|
||||
<div class="mask"></div>
|
||||
</div>
|
||||
<button (click)="clear()" mat-icon-button matTooltip="Clear completed">
|
||||
<mat-icon>clear_all</mat-icon>
|
||||
</button>
|
||||
<button (click)="stopAll()" mat-icon-button matTooltip="Stop All">
|
||||
<mat-icon>stop</mat-icon>
|
||||
</button>
|
||||
<ng-container *ngIf="(homeTabsService.index | async) === 0" id="download-actions">
|
||||
<button (click)="remove()" [disabled]="disableSelection$ | async" mat-icon-button
|
||||
matTooltip="Remove selected">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
<button (click)="restart()" [disabled]="disableSelection$ | async" mat-icon-button
|
||||
matTooltip="Start selected">
|
||||
<mat-icon>play_arrow</mat-icon>
|
||||
</button>
|
||||
<button (click)="stop()" [disabled]="disableSelection$ | async" mat-icon-button
|
||||
matTooltip="Stop selected">
|
||||
<mat-icon>pause</mat-icon>
|
||||
</button>
|
||||
<button (click)="rename()" [disabled]="disableSelection$ | async"
|
||||
mat-icon-button
|
||||
matTooltip="Rename selected to first alternative title">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<div class="or-spacer-vertical left">
|
||||
<div class="mask"></div>
|
||||
</div>
|
||||
<button (click)="clear()" mat-icon-button matTooltip="Clear completed">
|
||||
<mat-icon>clear_all</mat-icon>
|
||||
</button>
|
||||
<button (click)="stopAll()" mat-icon-button matTooltip="Stop All">
|
||||
<mat-icon>stop</mat-icon>
|
||||
</button>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="(homeTabsService.index | async) === 1" id="link-collector-actions">
|
||||
<button (click)="clearLinkCollector()" mat-icon-button matTooltip="Remove all">
|
||||
<mat-icon>clear_all</mat-icon>
|
||||
</button>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="(homeTabsService.index | async) === 2" id="event-logs-actions">
|
||||
<button (click)="clearEventLogs()" mat-icon-button matTooltip="Clear all">
|
||||
<mat-icon>clear_all</mat-icon>
|
||||
</button>
|
||||
</ng-container>
|
||||
</div>
|
||||
<div fxFlex="grow" fxHide.lt-md id="global-search">
|
||||
<form autocomplete="off">
|
||||
<mat-form-field class="search-field">
|
||||
<input (ngModelChange)="search($event)" matInput name="search" ngModel placeholder="Search"/>
|
||||
<input (ngModelChange)="search($event)" [(ngModel)]="searchModel" matInput name="search" ngModel
|
||||
placeholder="Search"/>
|
||||
<mat-icon matSuffix>search</mat-icon>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
@@ -46,6 +59,9 @@
|
||||
<button (click)="openSettings()" mat-icon-button matTooltip="Preferences">
|
||||
<mat-icon>settings</mat-icon>
|
||||
</button>
|
||||
<button (click)="openAbout()" mat-icon-button matTooltip="About">
|
||||
<mat-icon>info</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-toolbar-row>
|
||||
</mat-toolbar>
|
||||
|
||||
@@ -17,6 +17,10 @@ import {RowNode} from 'ag-grid-community';
|
||||
import {RemoveResponse} from '../domain/remove-response.model';
|
||||
import {PostId} from '../domain/post-id.model';
|
||||
import {PostsService} from '../services/posts.service';
|
||||
import {HomeTabsService} from '../services/home-tabs.service';
|
||||
import {LinkCollectorService} from '../services/link-collector.service';
|
||||
import {EventLogService} from '../services/event-log.service';
|
||||
import {AboutComponent} from '../about/about-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-toolbar',
|
||||
@@ -30,6 +34,8 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
||||
isExtraSmall: Observable<BreakpointState> = this.breakpointObserver.observe(Breakpoints.XSmall);
|
||||
selected: RowNode[] = [];
|
||||
subscriptions: Subscription[] = [];
|
||||
tabIndex: number;
|
||||
searchModel: string;
|
||||
|
||||
constructor(
|
||||
private serverService: ServerService,
|
||||
@@ -41,8 +47,15 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
||||
private breakpointObserver: BreakpointObserver,
|
||||
private ws: WsConnectionService,
|
||||
private selectionService: SelectionService,
|
||||
private postsDataService: PostsService
|
||||
private postsDataService: PostsService,
|
||||
public homeTabsService: HomeTabsService,
|
||||
public linkCollectorService: LinkCollectorService,
|
||||
public eventLogService: EventLogService,
|
||||
) {
|
||||
this.homeTabsService.index.subscribe(e => {
|
||||
this.tabIndex = e;
|
||||
this.search(this.searchModel);
|
||||
});
|
||||
}
|
||||
|
||||
openSettings(): void {
|
||||
@@ -71,7 +84,17 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
search(event) {
|
||||
this.postsDataService.search(event);
|
||||
switch (this.tabIndex) {
|
||||
case 0:
|
||||
this.postsDataService.search(event);
|
||||
break;
|
||||
case 1:
|
||||
this.linkCollectorService.search(event);
|
||||
break;
|
||||
case 2:
|
||||
this.eventLogService.search(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
remove() {
|
||||
@@ -158,6 +181,36 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
clearLinkCollector() {
|
||||
this.ngZone.run(() => {
|
||||
this.httpClient.get<void>(this.serverService.baseUrl + '/grab/clear', {}).subscribe(
|
||||
() => {
|
||||
this.linkCollectorService.clear();
|
||||
},
|
||||
error => {
|
||||
this._snackBar.open(error?.error?.message || 'Unexpected error, check log file', null, {
|
||||
duration: 5000
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
clearEventLogs() {
|
||||
this.ngZone.run(() => {
|
||||
this.httpClient.get<void>(this.serverService.baseUrl + '/events/clear', {}).subscribe(
|
||||
() => {
|
||||
this.eventLogService.clear();
|
||||
},
|
||||
error => {
|
||||
this._snackBar.open(error?.error?.message || 'Unexpected error, check log file', null, {
|
||||
duration: 5000
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
stopAll() {
|
||||
this.ngZone.run(() => {
|
||||
this.httpClient.post(this.serverService.baseUrl + '/post/stop/all', {}).subscribe(
|
||||
@@ -185,4 +238,25 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(e => e.unsubscribe());
|
||||
}
|
||||
|
||||
openAbout(): void {
|
||||
const dialogRef = this.dialog.open(AboutComponent, {
|
||||
width: '70%',
|
||||
height: '70%',
|
||||
maxWidth: '100vw',
|
||||
maxHeight: '100vh'
|
||||
});
|
||||
|
||||
const smallDialogSubscription = this.isExtraSmall.subscribe(result => {
|
||||
if (result.matches) {
|
||||
dialogRef.updateSize('100%', '100%');
|
||||
} else {
|
||||
dialogRef.updateSize('70%', '70%');
|
||||
}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
smallDialogSubscription.unsubscribe();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+30
-31
@@ -1,39 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
height="1024"
|
||||
id="svg8"
|
||||
inkscape:export-filename="C:\Users\Marwen\IdeaProjects\vripper-project\vripper-electron\build\icons\1024x1024.png"
|
||||
inkscape:export-xdpi="96.00956"
|
||||
inkscape:export-ydpi="96.00956"
|
||||
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||
sodipodi:docname="v.svg"
|
||||
version="1.1"
|
||||
viewBox="0 0 270.93333 270.93334"
|
||||
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
|
||||
width="1024"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
height="1024"
|
||||
id="svg8"
|
||||
inkscape:export-filename="C:\Users\Marwen\IdeaProjects\vripper-project\vripper-electron\build\icons\1024x1024.png"
|
||||
inkscape:export-xdpi="96.00956"
|
||||
inkscape:export-ydpi="96.00956"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
sodipodi:docname="v.svg"
|
||||
version="1.1"
|
||||
viewBox="0 0 270.93333 270.93334"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd">
|
||||
<defs
|
||||
id="defs2"/>
|
||||
id="defs2">
|
||||
<rect
|
||||
height="57.580088"
|
||||
id="rect32"
|
||||
width="31.592941"
|
||||
x="46.113095"
|
||||
y="71.423793"/>
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
id="base"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:cx="-200.49762"
|
||||
inkscape:cy="299.73785"
|
||||
inkscape:cx="504.85714"
|
||||
inkscape:cy="512"
|
||||
inkscape:document-rotation="0"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-height="1017"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-x="1912"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:zoom="0.35"
|
||||
pagecolor="#ffffff"
|
||||
@@ -61,21 +67,14 @@
|
||||
cy="161.53331"
|
||||
id="path3715"
|
||||
r="135.45317"
|
||||
style="fill:#aa0000;fill-opacity:1;stroke-width:0.35248032"/>
|
||||
<flowRoot
|
||||
id="flowRoot4522"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40.00005341px;line-height:1.25;font-family:'Fira Code';-inkscape-font-specification:'Fira Code, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
transform="matrix(5.7825687,0,0,5.7825687,-859.25089,-2020.8769)"
|
||||
xml:space="preserve"><flowRegion
|
||||
id="flowRegion4524"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40.00005341px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1"><rect
|
||||
height="380"
|
||||
id="rect4526"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:40.00005341px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff;fill-opacity:1"
|
||||
width="514.28571"
|
||||
x="160"
|
||||
y="356.80539" /></flowRegion>
|
||||
<flowPara
|
||||
id="flowPara4534">V</flowPara></flowRoot>
|
||||
style="fill:#aa0000;fill-opacity:1;stroke-width:0.35248"/>
|
||||
<text
|
||||
id="text30"
|
||||
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect32);fill:#000000;fill-opacity:1;stroke:none;"
|
||||
transform="matrix(4.1259458,0,0,4.1259458,-117.77844,-239.46004)"
|
||||
xml:space="preserve"><tspan
|
||||
x="46.113281"
|
||||
y="117.35549"><tspan
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:50.8px;font-family:'Fira Mono';-inkscape-font-specification:'Fira Mono Bold';fill:#ffffff">V</tspan></tspan></text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 2.5 KiB |
@@ -2,5 +2,5 @@ export const environment = {
|
||||
production: true,
|
||||
localhost: `${window.location.protocol}//${window.location.host}`,
|
||||
ws: `${window.location.protocol === 'http:' ? 'ws:' : 'wss:'}//${window.location.host}`,
|
||||
version: '3.2.1'
|
||||
version: '3.3.3'
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ export const environment = {
|
||||
production: false,
|
||||
localhost: 'http://localhost:8080',
|
||||
ws: 'ws://localhost:8080',
|
||||
version: '3.2.1'
|
||||
version: '3.3.3'
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -32,12 +32,14 @@
|
||||
@import 'src/app/status-bar/status-bar.component.scss-theme';
|
||||
@import 'app/app.component.scss-theme.scss';
|
||||
@import 'src/app/toolbar/toolbar.component.scss-theme';
|
||||
@import 'src/app/about/about-component.component-scss-theme';
|
||||
@import 'grid-theme.scss';
|
||||
|
||||
@mixin custom-components-theme($theme, $dark: false) {
|
||||
@include status-bar-component-theme($theme);
|
||||
@include app-component-theme($theme);
|
||||
@include toolbar-theme($theme, $dark);
|
||||
@include about-component-theme($theme)
|
||||
}
|
||||
|
||||
.dark-theme {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user