Throw DocumentNotFoundException when file not exists

pull/3641/head
liangshiwei 5 years ago
parent 26b056c324
commit 96324916b4

@ -87,6 +87,11 @@ namespace Volo.Docs.FileSystem.Documents
{
throw new SecurityException("Can not get a resource file out of the project folder!");
}
if (!File.Exists(path))
{
throw new DocumentNotFoundException(path);
}
}
}
}

@ -371,7 +371,8 @@ else
RedirectUrl = Model.DocumentsUrlPrefix + Model.LanguageCode + "/" + Model.ProjectName + "/"
+ (Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version),
ErrorCode = "404",
ErrorMessage = L.GetString("DocumentNotFound")
ErrorMessage = L.GetString("DocumentNotFound"),
AutoRedirect = !Model.DocumentName.IsNullOrWhiteSpace()
}
}))
}

@ -34,7 +34,7 @@ namespace Volo.Docs.Pages.Documents.Project
public string LanguageCode { get; set; }
public bool DocumentFound { get; set; } = true;
public bool ProjectFound { get; set; } = true;
public bool LoadSuccess => DocumentFound && ProjectFound;
@ -347,43 +347,13 @@ namespace Volo.Docs.Pages.Documents.Project
try
{
if (DocumentName.IsNullOrWhiteSpace())
{
Document = await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput
{
ProjectId = Project.Id,
LanguageCode = LanguageCode,
Version = Version
}
);
}
else
{
Document = await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
LanguageCode = LanguageCode,
Version = Version
}
);
}
Document = await GetSpecificDocumentOrDefaultAsync(LanguageCode);
}
catch (DocumentNotFoundException)
{
if (LanguageCode != DefaultLanguageCode)
{
Document = await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
LanguageCode = DefaultLanguageCode,
Version = Version
}
);
Document = await GetSpecificDocumentOrDefaultAsync(DefaultLanguageCode);
DocumentLanguageIsDifferent = true;
}
@ -545,6 +515,33 @@ namespace Volo.Docs.Pages.Documents.Project
}
private async Task<DocumentWithDetailsDto> GetSpecificDocumentOrDefaultAsync(string languageCode)
{
if (DocumentName.IsNullOrWhiteSpace())
{
return await _documentAppService.GetDefaultAsync(
new GetDefaultDocumentInput
{
ProjectId = Project.Id,
LanguageCode = languageCode,
Version = Version
}
);
}
else
{
return await _documentAppService.GetAsync(
new GetDocumentInput
{
ProjectId = Project.Id,
Name = DocumentNameWithExtension,
LanguageCode = languageCode,
Version = Version
}
);
}
}
public async Task SetDocumentPreferencesAsync()
{
var projectParameters = await _documentAppService.GetParametersAsync(
@ -604,7 +601,7 @@ namespace Volo.Docs.Pages.Documents.Project
{
return null;
}
var firstParagraph = new Regex(@"<p>(.*?)</p>", RegexOptions.IgnoreCase);
var match = firstParagraph.Match(Document.Content);
if (!match.Success)

@ -3,14 +3,17 @@
}
<div class="row position-relative vh-100" style="background: #e8e8e8;">
<div class="center" id="DocumentErrorContainer">
<span class="notfound-@Model.ErrorCode">@Model.ErrorCode</span>
<span class="notfound-@Model.ErrorCode">@Model.ErrorCode</span>
<h1>
@Model.ErrorMessage
</h1>
<br />
<a href="@(Model.RedirectUrl)" class="btn btn-primary px-4" id="ErrorRedirect">
Go Back <span id="ErrorRedirectSeconds">(3)</span>
</a>
<br/>
@if (Model.AutoRedirect)
{
<a href="@(Model.RedirectUrl)" class="btn btn-primary px-4" id="ErrorRedirect">
Go Back <span id="ErrorRedirectSeconds">(3)</span>
</a>
}
</div>
</div>
@ -19,7 +22,7 @@
h1 {
font-size: 1.75em;
line-height: 1.75;
color: #777;
color: #777;
font-weight: normal;
}
@ -36,7 +39,7 @@
transform: translate(-50%, -50%);
text-align: center;
}
.notfound-404 {
font-size: 300px;
font-weight: 700;
@ -48,5 +51,5 @@
margin-bottom: -150px;
z-index: -1;
position: relative;
}
</style>
}
</style>

@ -7,5 +7,7 @@
public string ErrorCode { get; set; }
public string RedirectUrl { get; set; }
public bool AutoRedirect { get; set; } = true;
}
}

@ -12,7 +12,7 @@
}, 1000);
}
if (document.getElementById("DocumentErrorContainer")) {
if (document.getElementById("ErrorRedirect")) {
errorPageRedirect();
}
});

Loading…
Cancel
Save