Skip to content

Commit

Permalink
feat(ipfsServer.ipfs): if directory contains "index.html" then show it
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed May 29, 2019
1 parent ecebe52 commit b0e9276
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions IpfsServer/Pages/ipfs.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading;
Expand Down Expand Up @@ -93,11 +94,30 @@ public IEnumerable<IFileSystemLink> Directories
/// </remarks>
public async Task<IActionResult> OnGetAsync(CancellationToken cancel)
{
node = await ipfs.FileSystem.ListFileAsync(Path, cancel);
if (String.IsNullOrWhiteSpace(Path))
{
return NotFound();
}

try
{
node = await ipfs.FileSystem.ListFileAsync(Path, cancel);
}
catch (ArgumentException e)
{
return NotFound(e.Message);
}

// If a directory, then display a page with directory contents.
// If a directory, then display a page with directory contents or if
// the directory contain "index.html", redirect to the page.
if (node.IsDirectory)
{
if (!Path.EndsWith("/") && node.Links.Any(l => l.Name == "index.html"))
{
return Redirect($"/ipfs/{Path}/index.html");
}

Path = Path.TrimEnd('/');
return Page();
}

Expand Down
2 changes: 1 addition & 1 deletion IpfsServer/WebUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WebUIController : Controller
[HttpGet]
public ActionResult Get()
{
return Redirect("/ipfs/QmfQkD8pBSBCBxWEwFSu4XaDVSWK6bjnNuaWZjMyQbyDub/index.html");
return Redirect("/ipfs/QmfQkD8pBSBCBxWEwFSu4XaDVSWK6bjnNuaWZjMyQbyDub");
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/IpfsEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<ItemGroup>
<PackageReference Include="Ipfs.Core" Version="0.50.1" />
<PackageReference Include="Makaretu.Dns.Unicast" Version="0.8.0" />
<PackageReference Include="Makaretu.Dns.Unicast" Version="0.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0" />
<PackageReference Include="PeerTalk" Version="0.11.3" />
Expand Down

0 comments on commit b0e9276

Please sign in to comment.