ADD directory sharding for permanent clips
This commit is contained in:
@@ -72,7 +72,6 @@ public class ClipService {
|
||||
return clipRepository.findByUser(user);
|
||||
}
|
||||
|
||||
|
||||
private User getUser() {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.isAuthenticated() && auth.getPrincipal() instanceof CustomOAuth2User oAuth2user) {
|
||||
|
||||
@@ -43,12 +43,27 @@ public class DirectoryService {
|
||||
}
|
||||
|
||||
public File getOutputFile(String id, String extension) {
|
||||
String dir = outputDir + File.separator + id + (extension.isEmpty() ? "" : "." + extension);
|
||||
if (id == null || id.length() < 2) {
|
||||
throw new IllegalArgumentException("ID must be at least 2 characters long");
|
||||
}
|
||||
|
||||
// Create subdirectories from first 2 characters of the ID
|
||||
String shard1 = id.substring(0, 2);
|
||||
String shard2 = id.substring(2);
|
||||
|
||||
String dir = outputDir +
|
||||
File.separator +
|
||||
shard1 +
|
||||
File.separator +
|
||||
shard2 +
|
||||
(extension.isEmpty() ? "" : "." + extension);
|
||||
|
||||
return new File(dir);
|
||||
}
|
||||
|
||||
public void saveData(File file, MultipartFile multipartFile) {
|
||||
public void saveAtDir(File file, MultipartFile multipartFile) {
|
||||
try {
|
||||
createDirectory(file.getAbsolutePath());
|
||||
Path filePath = Paths.get(file.getAbsolutePath());
|
||||
Files.copy(multipartFile.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (IOException e) {
|
||||
@@ -61,6 +76,7 @@ public class DirectoryService {
|
||||
Path destPath = Paths.get(target.getAbsolutePath());
|
||||
|
||||
try {
|
||||
Files.createDirectories(destPath.getParent());
|
||||
Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
logger.info("Copied file from {} to {}", sourcePath, destPath);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class UploadService {
|
||||
|
||||
File inputFile = directoryService.getTempInputFile(uuid, extension);
|
||||
File outputFile = directoryService.getTempOutputFile(uuid, extension);
|
||||
directoryService.saveData(inputFile, file);
|
||||
directoryService.saveAtDir(inputFile, file);
|
||||
|
||||
// add job
|
||||
logger.info("Uploaded file and creating job with UUID: {}", uuid);
|
||||
|
||||
Reference in New Issue
Block a user