|
|
@ -144,7 +144,9 @@ namespace Volo.Docs.Documents |
|
|
input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version; |
|
|
input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version; |
|
|
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version; |
|
|
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version; |
|
|
|
|
|
|
|
|
var cacheKey = CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode,input.Version); |
|
|
var cacheKey = |
|
|
|
|
|
CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode, |
|
|
|
|
|
input.Version); |
|
|
|
|
|
|
|
|
async Task<DocumentResource> GetResourceAsync() |
|
|
async Task<DocumentResource> GetResourceAsync() |
|
|
{ |
|
|
{ |
|
|
@ -180,13 +182,15 @@ namespace Volo.Docs.Documents |
|
|
await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version); |
|
|
await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version); |
|
|
|
|
|
|
|
|
return esDocs.Select(esDoc => new DocumentSearchOutput //TODO: auto map
|
|
|
return esDocs.Select(esDoc => new DocumentSearchOutput //TODO: auto map
|
|
|
{ |
|
|
{ |
|
|
Name = esDoc.Name, |
|
|
Name = esDoc.Name, |
|
|
FileName = esDoc.FileName, |
|
|
FileName = esDoc.FileName, |
|
|
Version = esDoc.Version, |
|
|
Version = esDoc.Version, |
|
|
LanguageCode = esDoc.LanguageCode, |
|
|
LanguageCode = esDoc.LanguageCode, |
|
|
Highlight = esDoc.Highlight |
|
|
Highlight = esDoc.Highlight |
|
|
}).Where(x => x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName).ToList(); |
|
|
}).Where(x => |
|
|
|
|
|
x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName) |
|
|
|
|
|
.ToList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<bool> FullSearchEnabledAsync() |
|
|
public async Task<bool> FullSearchEnabledAsync() |
|
|
@ -205,34 +209,63 @@ namespace Volo.Docs.Documents |
|
|
|
|
|
|
|
|
foreach (var document in documents) |
|
|
foreach (var document in documents) |
|
|
{ |
|
|
{ |
|
|
var version = GetProjectVersionPrefixIfExist(project) + document.Version; |
|
|
try |
|
|
var navigationDocument = await GetDocumentWithDetailsDtoAsync( |
|
|
|
|
|
project, |
|
|
|
|
|
project.NavigationDocumentName, |
|
|
|
|
|
document.LanguageCode, |
|
|
|
|
|
version |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!DocsJsonSerializerHelper.TryDeserialize<NavigationNode>(navigationDocument.Content, |
|
|
|
|
|
out var navigationNode)) |
|
|
|
|
|
{ |
|
|
{ |
|
|
throw new UserFriendlyException( |
|
|
await AddDocumentToUrls(prefix, project, document, documentUrls); |
|
|
$"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
navigationNode.Items?.ForEach(node => |
|
|
|
|
|
{ |
|
|
{ |
|
|
documentUrls.AddIfNotContains( |
|
|
Logger.LogException(ex); |
|
|
GetDocumentLinks(node, documentUrls, prefix, project.ShortName, document) |
|
|
} |
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return documentUrls; |
|
|
return documentUrls; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private List<string> GetDocumentLinks(NavigationNode node, List<string> documentUrls, string prefix, |
|
|
private async Task AddDocumentToUrls(string prefix, Project project, Document document, |
|
|
|
|
|
List<string> documentUrls) |
|
|
|
|
|
{ |
|
|
|
|
|
var navigationNodes = await GetNavigationNodesAsync(prefix, project, document); |
|
|
|
|
|
AddDocumentUrls(prefix, navigationNodes, documentUrls, project, document); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void AddDocumentUrls(string prefix, |
|
|
|
|
|
List<NavigationNode> navigationNodes, |
|
|
|
|
|
List<string> documentUrls, |
|
|
|
|
|
Project project, |
|
|
|
|
|
Document document) |
|
|
|
|
|
{ |
|
|
|
|
|
navigationNodes?.ForEach(node => |
|
|
|
|
|
{ |
|
|
|
|
|
documentUrls.AddIfNotContains( |
|
|
|
|
|
GetDocumentLinks(node, documentUrls, prefix, project.ShortName, document) |
|
|
|
|
|
); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<NavigationNode>> GetNavigationNodesAsync(string prefix, Project project, |
|
|
|
|
|
Document document) |
|
|
|
|
|
{ |
|
|
|
|
|
var version = GetProjectVersionPrefixIfExist(project) + document.Version; |
|
|
|
|
|
var navigationDocument = await GetDocumentWithDetailsDtoAsync( |
|
|
|
|
|
project, |
|
|
|
|
|
project.NavigationDocumentName, |
|
|
|
|
|
document.LanguageCode, |
|
|
|
|
|
version |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!DocsJsonSerializerHelper.TryDeserialize<NavigationNode>(navigationDocument.Content, |
|
|
|
|
|
out var navigationNode)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException( |
|
|
|
|
|
$"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return navigationNode.Items; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<string> GetDocumentLinks(NavigationNode node, List<string> documentUrls, string prefix, |
|
|
string shortName, Document document) |
|
|
string shortName, Document document) |
|
|
{ |
|
|
{ |
|
|
if (!IsExternalLink(node.Path)) |
|
|
if (!IsExternalLink(node.Path)) |
|
|
@ -253,7 +286,8 @@ namespace Volo.Docs.Documents |
|
|
private string NormalizePath(string prefix, string path, string shortName, Document document) |
|
|
private string NormalizePath(string prefix, string path, string shortName, Document document) |
|
|
{ |
|
|
{ |
|
|
var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format); |
|
|
var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format); |
|
|
var normalizedPath = prefix + document.LanguageCode + "/" + shortName + "/" + document.Version + "/" + pathWithoutFileExtension; |
|
|
var normalizedPath = prefix + document.LanguageCode + "/" + shortName + "/" + document.Version + "/" + |
|
|
|
|
|
pathWithoutFileExtension; |
|
|
|
|
|
|
|
|
return normalizedPath; |
|
|
return normalizedPath; |
|
|
} |
|
|
} |
|
|
@ -301,7 +335,8 @@ namespace Volo.Docs.Documents |
|
|
input.Version |
|
|
input.Version |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (!DocsJsonSerializerHelper.TryDeserialize<DocumentParametersDto>(document.Content,out var documentParameters)) |
|
|
if (!DocsJsonSerializerHelper.TryDeserialize<DocumentParametersDto>(document.Content, |
|
|
|
|
|
out var documentParameters)) |
|
|
{ |
|
|
{ |
|
|
throw new UserFriendlyException( |
|
|
throw new UserFriendlyException( |
|
|
$"Cannot validate document parameters file '{project.ParametersDocumentName}' for the project {project.Name}."); |
|
|
$"Cannot validate document parameters file '{project.ParametersDocumentName}' for the project {project.Name}."); |
|
|
@ -363,7 +398,8 @@ namespace Volo.Docs.Documents |
|
|
var documentDto = ObjectMapper.Map<Document, DocumentWithDetailsDto>(document); |
|
|
var documentDto = ObjectMapper.Map<Document, DocumentWithDetailsDto>(document); |
|
|
|
|
|
|
|
|
documentDto.Project = ObjectMapper.Map<Project, ProjectDto>(project); |
|
|
documentDto.Project = ObjectMapper.Map<Project, ProjectDto>(project); |
|
|
documentDto.Contributors = ObjectMapper.Map<List<DocumentContributor>, List<DocumentContributorDto>>(document.Contributors); |
|
|
documentDto.Contributors = |
|
|
|
|
|
ObjectMapper.Map<List<DocumentContributor>, List<DocumentContributorDto>>(document.Contributors); |
|
|
|
|
|
|
|
|
return documentDto; |
|
|
return documentDto; |
|
|
} |
|
|
} |
|
|
@ -374,7 +410,8 @@ namespace Volo.Docs.Documents |
|
|
Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the source..."); |
|
|
Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the source..."); |
|
|
|
|
|
|
|
|
var source = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
var source = _documentStoreFactory.Create(project.DocumentStoreType); |
|
|
var sourceDocument = await source.GetDocumentAsync(project, documentName, languageCode, version, oldDocument?.LastSignificantUpdateTime); |
|
|
var sourceDocument = await source.GetDocumentAsync(project, documentName, languageCode, version, |
|
|
|
|
|
oldDocument?.LastSignificantUpdateTime); |
|
|
|
|
|
|
|
|
await _documentRepository.DeleteAsync(project.Id, sourceDocument.Name, sourceDocument.LanguageCode, |
|
|
await _documentRepository.DeleteAsync(project.Id, sourceDocument.Name, sourceDocument.LanguageCode, |
|
|
sourceDocument.Version); |
|
|
sourceDocument.Version); |
|
|
|