NCBACK-25 add protection for audio and use hash method from library
Test Workflow / test (push) Successful in 3s
Test Workflow / test (push) Successful in 3s
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package ru.soune.nocopy.util;
|
||||
|
||||
import com.vrt.fileprotection.FileProtector;
|
||||
import com.vrt.fileprotection.image.ImageLocalSearch;
|
||||
import com.vrt.fileprotection.image.ImageScore;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.dto.file.SimilarFileDTO;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
|
||||
@Service
|
||||
public class FileUtil {
|
||||
public ImageLocalSearch.Result convertToResult(SimilarFileDTO response) {
|
||||
FileProtector.FileInfo fileInfo =
|
||||
new FileProtector.FileInfo(FileProtector.Type.IMAGE, response.getFileId(),
|
||||
String.valueOf(response.getOwnerId()));
|
||||
ImageScore imageScore = new ImageScore(ImageScore.Rate.valueOf(response.getSimilarityLevel()),
|
||||
response.getHammingDistance());
|
||||
|
||||
return new ImageLocalSearch.Result(fileInfo, imageScore);
|
||||
}
|
||||
|
||||
public FileProtector.FileInfo createFileInfo(FileEntity fileEntity) {
|
||||
FileProtector.Type type = determineFileType(fileEntity.getMimeType());
|
||||
|
||||
return new FileProtector.FileInfo(type, fileEntity.getId(), String.valueOf(fileEntity.getUserId()));
|
||||
}
|
||||
|
||||
public int hamming64(int aHi, int aLo, int bHi, int bLo) {
|
||||
return Integer.bitCount(aHi ^ bHi)
|
||||
+ Integer.bitCount(aLo ^ bLo);
|
||||
}
|
||||
|
||||
private FileProtector.Type determineFileType(String mimeType) {
|
||||
if (mimeType == null) {
|
||||
return FileProtector.Type.IMAGE;
|
||||
}
|
||||
|
||||
if (mimeType.startsWith("image")) {
|
||||
return FileProtector.Type.IMAGE;
|
||||
} else if (mimeType.startsWith("video")) {
|
||||
return FileProtector.Type.VIDEO;
|
||||
} else if (mimeType.startsWith("audio")) {
|
||||
return FileProtector.Type.AUDIO;
|
||||
} else {
|
||||
return FileProtector.Type.IMAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user