in server/src/main/java/com/epam/aidial/core/server/service/PublicationService.java [401:443]
private void addCustomApplicationRelatedFiles(ProxyContext context, Publication publication) {
List<String> existingUrls = publication.getResources().stream()
.map(Publication.Resource::getSourceUrl)
.toList();
Map<String, Integer> fileNameCounter = new HashMap<>();
List<Publication.Resource> linkedResourcesToPublish = publication.getResources().stream()
.filter(resource -> resource.getAction() != Publication.ResourceAction.DELETE)
.flatMap(resource -> {
ResourceDescriptor source = ResourceDescriptorFactory.fromAnyUrl(resource.getSourceUrl(), encryption);
if (source.getType() != ResourceTypes.APPLICATION) {
return Stream.empty();
}
Application application = applicationService.getApplication(source).getValue();
if (application.getApplicationTypeSchemaId() == null) {
return Stream.empty();
}
String targetFolder = buildTargetFolderForCustomAppFiles(resource);
return ApplicationTypeSchemaUtils.getFiles(context.getConfig(), application, encryption, resourceService)
.stream()
.filter(sourceDescriptor -> !existingUrls.contains(sourceDescriptor.getUrl()) && !sourceDescriptor.isPublic())
.map(sourceDescriptor -> {
String fileName = sourceDescriptor.getName();
int count = fileNameCounter.getOrDefault(fileName, 0) + 1;
fileNameCounter.put(fileName, count);
if (count > 1) {
fileName = fileName.replaceFirst("(\\.[^.]+)$", "_" + count + "$1");
}
return new Publication.Resource()
.setAction(resource.getAction())
.setSourceUrl(sourceDescriptor.getUrl())
.setTargetUrl(ResourceDescriptorFactory.fromDecoded(ResourceTypes.FILE,
ResourceDescriptor.PUBLIC_BUCKET, ResourceDescriptor.PATH_SEPARATOR,
targetFolder + fileName).getUrl());
});
})
.toList();
publication.getResources().addAll(linkedResourcesToPublish);
}