2026-04-22 16:24:43 +07:00
|
|
|
package ru.soune.nocopy.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2026-05-15 13:07:16 +07:00
|
|
|
import ru.soune.nocopy.dto.docviewer.DockViewResponse;
|
|
|
|
|
import ru.soune.nocopy.entity.docviewer.DockView;
|
|
|
|
|
import ru.soune.nocopy.entity.file.FileEntity;
|
|
|
|
|
import ru.soune.nocopy.entity.user.User;
|
2026-04-22 16:24:43 +07:00
|
|
|
import ru.soune.nocopy.migration.S3MigrationTool;
|
2026-05-15 13:07:16 +07:00
|
|
|
import ru.soune.nocopy.repository.DockViewRepository;
|
|
|
|
|
import ru.soune.nocopy.repository.FileEntityRepository;
|
|
|
|
|
import ru.soune.nocopy.repository.UserRepository;
|
|
|
|
|
import ru.soune.nocopy.service.geo.GeoCountryService;
|
2026-04-22 16:24:43 +07:00
|
|
|
|
2026-05-15 13:07:16 +07:00
|
|
|
import java.util.List;
|
2026-04-22 16:24:43 +07:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/admin/migration")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class MigrationController {
|
|
|
|
|
|
|
|
|
|
private final S3MigrationTool migrationTool;
|
|
|
|
|
|
2026-05-15 13:07:16 +07:00
|
|
|
private final DockViewRepository dockViewRepository;
|
|
|
|
|
|
|
|
|
|
private final GeoCountryService geoCountryService;
|
|
|
|
|
|
|
|
|
|
private final UserRepository userRepository;
|
|
|
|
|
|
|
|
|
|
private final FileEntityRepository fileEntityRepository;
|
|
|
|
|
|
2026-04-22 16:24:43 +07:00
|
|
|
@PostMapping("/start")
|
|
|
|
|
public ResponseEntity<String> startMigration() {
|
|
|
|
|
log.info("Migration triggered via API");
|
|
|
|
|
|
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
|
try {
|
|
|
|
|
migrationTool.migrationFilesToS3();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("Migration failed", e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok("Migration started. Check logs for progress.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/status")
|
|
|
|
|
public ResponseEntity<String> getStatus() {
|
|
|
|
|
return ResponseEntity.ok("Check application logs and migration_failed.txt for details");
|
|
|
|
|
}
|
2026-05-15 13:07:16 +07:00
|
|
|
|
|
|
|
|
@PostMapping("/fill-dock-view")
|
|
|
|
|
public ResponseEntity<String> fillDockView() {
|
|
|
|
|
List<DockView> dockViews = dockViewRepository.findAll();
|
|
|
|
|
|
|
|
|
|
for (DockView dockView: dockViews) {
|
|
|
|
|
String viewerIp = dockView.getViewerIp();
|
|
|
|
|
Long viewerId = dockView.getViewerId();
|
|
|
|
|
String geoEnName = geoCountryService.getCityByIp(viewerIp, "en") + "/" +
|
|
|
|
|
geoCountryService.getCountryByIp(viewerIp, "en");
|
|
|
|
|
String geoRuName = geoCountryService.getCityByIp(viewerIp, "ru") + "/" +
|
|
|
|
|
geoCountryService.getCountryByIp(viewerIp, "ru");
|
|
|
|
|
User user = userRepository.findById(viewerId).orElse(null);
|
|
|
|
|
FileEntity file = fileEntityRepository.findByFileId(dockView.getFileId());
|
|
|
|
|
|
|
|
|
|
dockView.setGeoNameRu(geoRuName);
|
|
|
|
|
dockView.setGeoNameEn(geoEnName);
|
|
|
|
|
dockView.setViewerName(user == null ? "guest" : user.getFullName());
|
|
|
|
|
dockView.setDocName(file.getOriginalFileName());
|
2026-05-15 13:17:47 +07:00
|
|
|
|
|
|
|
|
dockViewRepository.save(dockView);
|
2026-05-15 13:07:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResponseEntity.ok("fill old dock view");
|
|
|
|
|
}
|
2026-04-22 16:24:43 +07:00
|
|
|
}
|