информация о SHA1 как метаданные к файлам
This commit is contained in:
@@ -2,6 +2,7 @@ package ru.di9.mirror.core.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import ru.di9.mirror.core.domain.FileInfo;
|
||||
import ru.di9.mirror.core.entity.ArtifactEntity;
|
||||
import ru.di9.mirror.core.handler.response.GetFileResponse;
|
||||
@@ -10,6 +11,7 @@ import ru.di9.mirror.core.storage.FileStorage;
|
||||
import ru.di9.mirror.core.service.ExternalMavenService;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -37,11 +39,11 @@ public class MavenHandler {
|
||||
return optionalInputStream
|
||||
.map(inputStream -> new GetFileResponse(fileInfo.name(), inputStream));
|
||||
} else {
|
||||
return findInMirrors(path, fileInfo.name(), artifactEntity);
|
||||
return findInMirrors(path, fileInfo, artifactEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<GetFileResponse> findInMirrors(String path, String fileName, ArtifactEntity artifactEntity) {
|
||||
private Optional<GetFileResponse> findInMirrors(String path, FileInfo fileInfo, ArtifactEntity artifactEntity) {
|
||||
Optional<InputStream> result;
|
||||
for (ExternalMavenService externalMavenService : externalMavenServices) {
|
||||
final String nameForStore = "/" + externalMavenService.getId() + "/" + path;
|
||||
@@ -49,7 +51,7 @@ public class MavenHandler {
|
||||
result = fileStorage.findByName(nameForStore);
|
||||
if (result.isPresent()) {
|
||||
return result
|
||||
.map(inputStream -> new GetFileResponse(fileName, inputStream));
|
||||
.map(inputStream -> new GetFileResponse(fileInfo.name(), inputStream));
|
||||
} else {
|
||||
result = externalMavenService.getFile(path);
|
||||
if (result.isPresent()) {
|
||||
@@ -57,9 +59,18 @@ public class MavenHandler {
|
||||
repository.save(artifactEntity);
|
||||
}
|
||||
|
||||
fileStorage.save(nameForStore, result.get());
|
||||
if (fileInfo.ext().equalsIgnoreCase("sha1")) {
|
||||
try {
|
||||
String sha1str = IOUtils.toString(result.get(), StandardCharsets.UTF_8);
|
||||
fileStorage.setMetadata(nameForStore.substring(0, nameForStore.lastIndexOf(".")), "sha1", sha1str);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
fileStorage.save(nameForStore, result.get());
|
||||
}
|
||||
return fileStorage.findByName(nameForStore)
|
||||
.map(inputStream -> new GetFileResponse(fileName, inputStream));
|
||||
.map(inputStream -> new GetFileResponse(fileInfo.name(), inputStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,7 @@ public interface FileStorage {
|
||||
|
||||
void save(String name, InputStream inputStream);
|
||||
|
||||
void setMetadata(String name, String key, String value);
|
||||
|
||||
List<FileItem> list(String prefix);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user