This commit is contained in:
@@ -90,10 +90,10 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
allUniqueImages = searchImageService.removeDuplicateUrls(allYandexImages, allGoogleImages);
|
||||
log.info("allUniqueImages OK: {} images", allUniqueImages.size());
|
||||
|
||||
if (!allUniqueImages.isEmpty()) {
|
||||
tariffInfoService.writeOffTokens(fileEntity.getUserId(), TariffConstants.TOKEN_VALUE_FOR_SEARCH);
|
||||
checkCounterService.incrementCheckCount(fileEntity.getUserId(), fileEntity.getMimeType());
|
||||
}
|
||||
// if (!allUniqueImages.isEmpty()) {
|
||||
tariffInfoService.writeOffTokens(fileEntity.getUserId(), TariffConstants.TOKEN_VALUE_FOR_SEARCH);
|
||||
checkCounterService.incrementCheckCount(fileEntity.getUserId(), fileEntity.getMimeType());
|
||||
// }
|
||||
|
||||
int page = imageSearchRequest.getPage() != null ? imageSearchRequest.getPage() : 1;
|
||||
int pageSize = 5;
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
|
||||
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
||||
import ru.soune.nocopy.service.monitoring.MonitoringSearchService;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -47,20 +48,34 @@ public class EmailService {
|
||||
@Value("${server.front.port}")
|
||||
private String frontPort;
|
||||
|
||||
public void sendVerificationEmail(User user, String code) throws MessagingException, IOException {
|
||||
public void sendEmail(String from, String sendTo, String subject, String body) throws MessagingException {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
|
||||
helper.setFrom("noreply@no-copy.ru");
|
||||
helper.setTo(user.getEmail());
|
||||
helper.setSubject(standartSubject);
|
||||
String htmlContent = loadAndProcessTemplate(user.getFullName(), code,
|
||||
"templates/email-verification.html");
|
||||
helper.setText(htmlContent, true);
|
||||
helper.setFrom(from);
|
||||
helper.setTo(sendTo);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(body, true);
|
||||
|
||||
mailSender.send(message);
|
||||
}
|
||||
|
||||
public void sendVerificationEmail(User user, String code) throws MessagingException, IOException {
|
||||
String htmlContent = loadAndProcessTemplate(Map.of("username", user.getFullName(), "code", code),
|
||||
"templates/email-verification.html");
|
||||
sendEmail("noreply@no-copy.ru", user.getEmail(), standartAdressFrom, htmlContent);
|
||||
}
|
||||
|
||||
public void sendTokensNotFoundEmail(User user, Integer currentTokens, Integer missingTokens)
|
||||
throws MessagingException, IOException {
|
||||
String htmlContent = loadAndProcessTemplate(Map.of("username", user.getFullName(),
|
||||
"current_tokens", String.valueOf(currentTokens), "missing_tokens",
|
||||
String.valueOf(missingTokens), "link_to_token_board", baseUrl + "/pages/payment"),
|
||||
"templates/token-not-found.html");
|
||||
|
||||
sendEmail("noreply@no-copy.ru", user.getEmail(), standartAdressFrom, htmlContent);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public EmailVerificationToken createEmailVerificationToken(AuthToken authToken) {
|
||||
EmailVerificationToken existingToken = emailVerificationTokenRepository
|
||||
@@ -96,6 +111,18 @@ public class EmailService {
|
||||
.replace("{{code}}", safeCode);
|
||||
}
|
||||
|
||||
private String loadAndProcessTemplate(Map<String, String> fieldsForTemplate, String templatePath) throws IOException {
|
||||
ClassPathResource resource = new ClassPathResource(templatePath);
|
||||
String template = new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
|
||||
|
||||
for (Map.Entry<String, String> entry : fieldsForTemplate.entrySet()) {
|
||||
template = template.replace("{{" + entry.getKey() + "}}", escapeHtml(entry.getValue()));
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
private String escapeHtml(String text) {
|
||||
if (text == null) return "";
|
||||
return text
|
||||
|
||||
@@ -1,19 +1,30 @@
|
||||
package ru.soune.nocopy.service.monitoring;
|
||||
|
||||
import jakarta.mail.MessagingException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.nocopy.dto.file.YandexSearchResponse;
|
||||
import ru.soune.nocopy.dto.tarriff.TariffDTO;
|
||||
import ru.soune.nocopy.entity.file.*;
|
||||
import ru.soune.nocopy.entity.monitoring.FileMonitoringEntity;
|
||||
import ru.soune.nocopy.entity.monitoring.FoundViolationEntity;
|
||||
import ru.soune.nocopy.entity.monitoring.MonitoringType;
|
||||
import ru.soune.nocopy.entity.monitoring.SearchEngine;
|
||||
import ru.soune.nocopy.entity.tarif.TariffInfo;
|
||||
import ru.soune.nocopy.entity.tarif.TariffType;
|
||||
import ru.soune.nocopy.entity.user.User;
|
||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
||||
import ru.soune.nocopy.repository.FoundViolationRepository;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.mail.EmailService;
|
||||
import ru.soune.nocopy.service.search.SearchImageService;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
import ru.soune.nocopy.service.tariff.TariffService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -30,8 +41,16 @@ public class MonitoringSearchService {
|
||||
|
||||
private final FileMonitoringRepository monitoringRepository;
|
||||
|
||||
private final TariffInfoService tariffInfoService;
|
||||
|
||||
private final TariffService tariffService;
|
||||
|
||||
private final EmailService emailService;
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Transactional
|
||||
public void processFileSearch(FileMonitoringEntity monitoring) {
|
||||
public void processFileSearch(FileMonitoringEntity monitoring) throws MessagingException, IOException {
|
||||
String searchSessionId = UUID.randomUUID().toString();
|
||||
log.info("Starting search session: {} for file: {}", searchSessionId, monitoring.getFile().getId());
|
||||
|
||||
@@ -39,7 +58,12 @@ public class MonitoringSearchService {
|
||||
monitoring.setLastRunStatus("IN_PROGRESS");
|
||||
monitoringRepository.save(monitoring);
|
||||
|
||||
MonitoringType monitoringType = monitoring.getMonitoringType();
|
||||
TariffDTO tariffMonitoring = tariffService.getTariffByType(TariffType.valueOf(monitoringType.name()));
|
||||
|
||||
try {
|
||||
tariffInfoService.writeOffTokens(monitoring.getUserId(), tariffMonitoring.getTokens());
|
||||
|
||||
String yandexResponse = searchImageService.searchReverseByPublicUrl(
|
||||
monitoring.getFile(), "yandex_reverse_image", "visual_matches");
|
||||
|
||||
@@ -62,7 +86,16 @@ public class MonitoringSearchService {
|
||||
}
|
||||
|
||||
monitoring.setLastRunStatus("SUCCESS - Found " + savedCount + " violations");
|
||||
} catch (TariffNotFoundException e) {
|
||||
User user = userRepository.findById(monitoring.getUserId()).orElseThrow();
|
||||
TariffInfo activeTariffInfo = user.getActiveTariffInfo();
|
||||
int currentTokens = activeTariffInfo.getTokens() + activeTariffInfo.getBoughtTokens();
|
||||
|
||||
emailService.sendTokensNotFoundEmail(user, currentTokens, tariffMonitoring.getTokens());
|
||||
monitoring.setLastRunStatus("ERROR: " + e.getMessage());
|
||||
updateNextRun(monitoring);
|
||||
|
||||
monitoringRepository.save(monitoring);
|
||||
} catch (Exception e) {
|
||||
log.error("Search failed for session: {}", searchSessionId, e);
|
||||
monitoring.setLastRunStatus("ERROR: " + e.getMessage());
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package ru.soune.nocopy.service.notification;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class NotificationService {
|
||||
|
||||
}
|
||||
@@ -52,6 +52,10 @@ public class TariffInfoService {
|
||||
activeTariffInfo = user.getCompany().getTariffInfo();
|
||||
}
|
||||
|
||||
writeOffTokensForTariff(activeTariffInfo, value);
|
||||
}
|
||||
|
||||
public void writeOffTokensForTariff(TariffInfo activeTariffInfo, Integer value) {
|
||||
Integer tokens = activeTariffInfo.getTokens();
|
||||
Integer boughtTokens = activeTariffInfo.getBoughtTokens();
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ yandex:
|
||||
search-url: ${YANDEX_SEARCH_URL:https://searchapi.api.cloud.yandex.net/v2/image/search_by_image}
|
||||
|
||||
searchapi:
|
||||
api-key: ${SEARCHAPI_API_KEY:qQ19qn3JeRtqm9aasEgUFvGc}
|
||||
api-key: ${SEARCHAPI_API_KEY:5jyYZC8jSaxhZTwjMUhwtAXi}
|
||||
reverse-image-url: "https://searchapi.io/api/v1/search"
|
||||
|
||||
app:
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Недостаточно токенов</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 6px 20px rgba(0,0,0,0.1);
|
||||
}
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 40px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.logo {
|
||||
font-size: 32px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.content {
|
||||
padding: 40px 30px;
|
||||
}
|
||||
.greeting {
|
||||
font-size: 18px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.username {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
.warning-container {
|
||||
background: #fff3cd;
|
||||
border: 2px solid #ffc107;
|
||||
border-radius: 10px;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
margin: 30px 0;
|
||||
}
|
||||
.warning-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.warning-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #856404;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.token-info {
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 25px 0;
|
||||
}
|
||||
.token-amount {
|
||||
font-size: 36px;
|
||||
font-weight: 800;
|
||||
color: #764ba2;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.token-required {
|
||||
color: #dc3545;
|
||||
font-weight: 600;
|
||||
}
|
||||
.action-button {
|
||||
display: inline-block;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 14px 40px;
|
||||
border-radius: 50px;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
margin: 20px 0;
|
||||
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
.info-text {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.features {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
margin: 30px 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.feature-item {
|
||||
flex: 1 1 45%;
|
||||
background: #f8f9fa;
|
||||
padding: 12px;
|
||||
margin: 5px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
color: #495057;
|
||||
}
|
||||
.feature-icon {
|
||||
margin-right: 5px;
|
||||
color: #28a745;
|
||||
}
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 25px;
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
border-top: 1px solid #eee;
|
||||
background: #f9f9f9;
|
||||
}
|
||||
.highlight {
|
||||
color: #764ba2;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div class="logo">NO COPY</div>
|
||||
<h1>Недостаточно токенов</h1>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<p class="greeting">
|
||||
Здравствуйте, <span class="username">{{username}}</span>!
|
||||
</p>
|
||||
|
||||
<p>При попытке провести мониторинг файлов, токенов для автоматического мониторинга не достаточно.</p>
|
||||
|
||||
<div class="token-info">
|
||||
<p style="margin: 0; color: #666;">Ваш текущий баланс:</p>
|
||||
<p class="token-amount">{{current_tokens}} токенов</p>
|
||||
<p class="info-text">Не хватает: <span class="token-required">{{missing_tokens}} токенов</span></p>
|
||||
</div>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<a href="{{link_to_token_board}}" class="action-button">Пополнить баланс</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p>© 2024 NO COPY. Все права защищены.</p>
|
||||
<p>Это письмо отправлено автоматически, пожалуйста, не отвечайте на него.</p>
|
||||
<p>Если у вас возникли вопросы, обратитесь в службу поддержки.</p>
|
||||
<p style="margin-top: 10px;">
|
||||
<a href="#" style="color: #667eea; text-decoration: none;">Тарифы</a> •
|
||||
<a href="#" style="color: #667eea; text-decoration: none;">Как пополнить</a> •
|
||||
<a href="#" style="color: #667eea; text-decoration: none;">Помощь</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user