Skip to content

Commit

Permalink
feat(gateway): initial directory listing support (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 authored Oct 13, 2022
1 parent 2db7bf0 commit 3316a53
Show file tree
Hide file tree
Showing 13 changed files with 844 additions and 24 deletions.
1 change: 1 addition & 0 deletions iroh-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ reqwest = { version = "0.11.10", features = ["rustls-tls"], default-features = f
hex-literal = "0.3.4"
hex = "0.4.3"
http-body = "0.4.5"
phf = { version = "0.11", features = ["macros"] }

[dev-dependencies]
axum-macros = "0.2.0" # use #[axum_macros::debug_handler] for better error messages on handlers
Expand Down
6 changes: 6 additions & 0 deletions iroh-gateway/assets/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<h1>404 Not Found</h1>
<p>
The requested resource was not found.
</p>
</div>
93 changes: 93 additions & 0 deletions iroh-gateway/assets/dir_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="A directory of content-addressed files hosted on IPFS">
<meta property="og:title" content="Files on IPFS">
<meta property="og:description" content="{{ root_path }}">
<meta property="og:type" content="website">
<meta property="og:image" content="https://gateway.ipfs.io/ipfs/QmSDeYAe9mga6NdTozAZuyGL3Q1XjsLtvX28XFxJH8oPjq">

<meta name="twitter:title" content="{{ root_path }}">
<meta name="twitter:description" content="A directory of files hosted on the distributed, decentralized web using IPFS">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://gateway.ipfs.io/ipfs/QmSDeYAe9mga6NdTozAZuyGL3Q1XjsLtvX28XFxJH8oPjq">
<meta name="twitter:creator" content="@n0computer">
<meta name="twitter:site" content="@n0computer">

<meta name="image" content="https://gateway.ipfs.io/ipfs/QmSDeYAe9mga6NdTozAZuyGL3Q1XjsLtvX28XFxJH8oPjq">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="short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z3/op5G/9HKav/Rymr/0cpq/9HKav/Rymr/0cpq/9HKav/Rymr/0cpq/9HKav+inkb/nplD/wAAAAAAAAAAAAAAAKKeRv+3slb/0cpq/9HKav/Rymr/0cpq/9HKav/Rymr/0cpq/9HKav+1sFX/op5G/wAAAAAAAAAAAAAAAAAAAAAAAAAAop5GUKKeRv/Nxmf/0cpq/9HKav/Rymr/0cpq/83GZ/+inkb/op5GSAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAop5G16KeRv/LxWb/y8Vm/6KeRv+inkaPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAop5G/6KeRtcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/n8AAPgfAADwDwAAwAMAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAwAMAAPAPAAD4HwAA/n8AAA==" />
<link rel="stylesheet" href="/style.css"/>
<link rel="stylesheet" href="/icons.css">
<title>{{ root_path }}</title>
</head>
<body>
<div id="page-header">
<div id="page-header-logo">
<svg viewBox="0 0 258 129" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M51.8152 58.2582L18.8572 39.4491C18.9312 38.8636 18.9312 38.2781 18.8572 37.6926L51.8152 18.9202C54.5926 20.9328 58.3698 20.9328 61.1472 18.9202L94.0682 37.6926C93.9941 38.2781 93.9941 38.8636 94.0682 39.4491L61.1472 58.2216C58.3698 56.2089 54.5926 56.2089 51.8152 58.2582Z" fill="white"/>
<path d="M52.2226 111.319C51.6672 111.539 51.1858 111.831 50.7044 112.197L17.7463 93.3883C18.1166 89.9851 16.228 86.7649 13.0803 85.4109V47.8294C13.6358 47.6099 14.1172 47.3171 14.5986 46.9512L47.5196 65.7236C47.1493 69.1268 49.0379 72.3471 52.1856 73.701V111.319H52.2226Z" fill="white"/>
<path d="M99.8822 85.4115C96.7345 86.7654 94.8089 90.0222 95.2163 93.3888L62.2952 112.161C61.8138 111.832 61.2954 111.539 60.7769 111.283L60.7029 73.9577C63.8506 72.6037 65.7762 69.3469 65.3689 65.9803L98.3269 46.9883C98.8083 47.3176 99.3267 47.6104 99.8452 47.8665V85.4115H99.8822Z" fill="white"/>
<path d="M56.4813 6.36891L107.807 35.6437V94.1933L56.4813 123.468L5.15565 94.2299V35.6437L56.4813 6.36891ZM56.4813 0.879883L54.0743 2.27044L2.7486 31.5452L0.341553 32.8992V35.6437V94.1933V96.9378L2.7486 98.3284L54.0743 127.603L56.4813 128.994L58.8884 127.603L110.214 98.3284L112.621 96.9378V94.1933V35.6437V32.8992L110.214 31.5086L58.8884 2.23384L56.4813 0.879883Z" fill="white"/>
<path d="M149.846 42.166H140.432V87.7076H149.846V42.166Z" fill="white"/>
<path d="M166.263 87.7076V70.9973C168.557 71.1738 170.911 71.1738 172.853 71.1738C186.268 71.1738 190.151 64.525 190.151 56.3463C190.151 46.4024 183.032 42.166 172.088 42.166H156.848V87.7076H166.263ZM171.323 64.5838C169.558 64.5838 167.028 64.5838 166.204 64.525V49.0502H172.088C177.736 49.0502 180.973 51.7568 180.973 56.6993V56.817C181.031 60.7004 179.619 64.5838 171.323 64.5838Z" fill="white"/>
<path d="M222.336 42.166H193.74V87.7076H203.155V67.6434H221.042V60.8181H203.096V49.1091H221.689L222.336 42.166Z" fill="white"/>
<path d="M253.33 51.7059L255.715 45.6299C252.195 43.0746 247.368 42.166 241.349 42.166C232.547 42.166 225.335 46.2545 225.335 54.6587C225.335 62.2111 230.9 65.1639 236.409 66.9811L241.973 68.855C245.778 70.161 248.901 71.4103 248.901 75.4988C248.901 79.2466 245.665 80.723 240.724 80.723C235.727 80.723 230.389 79.2466 227.323 77.3159L224.938 83.903C228.913 86.4583 233.967 87.7076 240.724 87.7076C250.378 87.7076 257.816 83.4487 257.816 74.4767C257.816 66.0725 251.4 63.4036 244.926 61.2458L238.907 59.2583C236.295 58.4065 234.308 57.214 234.308 53.8637C234.308 50.4566 237.09 49.0938 241.292 49.0938C246.403 48.9234 250.378 49.8888 253.33 51.7059Z" fill="white"/>
</svg>
</div>
<div id="page-header-menu">
<div class="menu-item-wide"><a href="https://iroh.computer/docs/install" target="_blank" rel="noopener noreferrer">install iroh</a></div>
<div class="menu-item-wide"><a href="https://iroh.computer/docs/ipfs" target="_blank" rel="noopener noreferrer">about IPFS</a></div>
<div class="menu-item-narrow"><a href="https://iroh.computer/docs/ipfs" target="_blank" rel="noopener noreferrer">about</a></div>
<div class="menu-item-narrow"><a href="https://iroh.computer/docs/install" target="_blank" rel="noopener noreferrer">install</a></div>
<div>
<a href="https://github.com/n0-computer/iroh/issues/new" target="_blank" rel="noopener noreferrer" title="Report a bug">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18.4 21"><circle cx="7.5" cy="4.8" r="1"/><circle cx="11.1" cy="4.8" r="1"/><path d="M12.7 8.4c-0.5-1.5-1.9-2.5-3.5-2.5 -1.6 0-3 1-3.5 2.5H12.7z"/><path d="M8.5 9.7H5c-0.5 0.8-0.7 1.7-0.7 2.7 0 2.6 1.8 4.8 4.2 5.2V9.7z"/><path d="M13.4 9.7H9.9v7.9c2.4-0.4 4.2-2.5 4.2-5.2C14.1 11.4 13.9 10.5 13.4 9.7z"/><circle cx="15.7" cy="12.9" r="1"/><circle cx="15.1" cy="15.4" r="1"/><circle cx="15.3" cy="10.4" r="1"/><circle cx="2.7" cy="12.9" r="1"/><circle cx="3.3" cy="15.4" r="1"/><circle cx="3.1" cy="10.4" r="1"/></svg>
</a>
</div>
</div>
</div>
<div id="content">
<div id="content-header" class="d-flex flex-wrap">
<div>
<strong>
Index of
{{#each breadcrumbs ~}}
/{{#if this.path }}<a href="{{ public_url_base }}{{ this.path }}">{{ this.name }}</a>{{else}}{{ this.name }}{{/if}}
{{~ else }}
{{ path }}
{{/each }}
</strong>
{{#if root_cid }}
<div class="ipfs-cid" translate="no">
{{ root_cid }}
</div>
{{/if }}
</div>
{{#if size }}
<div class="no-linebreak flex-shrink-1 ml-auto">
<strong>&nbsp;{{ size }}</strong>
</div>
{{/if }}
</div>
<div class="table-responsive">
<table>
{{#each links}}
<tr>
<td class="type-icon">
<div class="{{ this.icon }}">&nbsp;</div>
</td>
<td>
<a href="{{ this.path }}">{{ this.name }}</a>
</td>
<td class="no-linebreak">
</td>
<td class="no-linebreak">{{ this.size }}</td>
</tr>
{{/each }}
</table>
</div>
</div>
</body>
</html>
Loading

0 comments on commit 3316a53

Please sign in to comment.