Skip to content

Commit

Permalink
feat: add indicator if CID is cached in local datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
xrazis committed Apr 8, 2022
1 parent 514411b commit 5fa797a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
4 changes: 2 additions & 2 deletions assets/bindata.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/bindata_version_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
package assets

const (
BindataVersionHash = "512eb789cd905714e03f29d4e04de7549e8c9c3e"
BindataVersionHash = "7b83fb3f6357a1305028d01241559815cb5ac8a6"
)
9 changes: 8 additions & 1 deletion assets/dir-index-html/dir-index.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions assets/dir-index-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"license": "MIT",
"scripts": {
"start": "cd test && go run .",
"build": "npm run build:clean && npm run build:remove-style-links && npm run build:minify-wrap-css && npm run build:combine-html-css && npm run build:remove-unused",
"build": "npm run build:clean && npm run build:remove-links && npm run build:minify-wrap && npm run build:combine-html-css-js && npm run build:remove-unused",
"build:clean": "rm dir-index.html",
"build:remove-style-links": "sed '/<link rel=\"stylesheet\"/d' ./src/dir-index.html > ./base-html.html",
"build:minify-wrap-css": "(echo \"<style>\" && cat ./src/icons.css ./src/style.css | tr -d \"\t\n\r\" && echo && echo \"</style>\") > ./minified-wrapped-style.html",
"build:combine-html-css": "sed '/<\\/title>/ r ./minified-wrapped-style.html' ./base-html.html > ./dir-index.html",
"build:remove-unused": "rm ./base-html.html && rm ./minified-wrapped-style.html"
"build:remove-links": "sed -e '/<script rel=\"script\"/d' -e '/<link rel=\"stylesheet\"/d' ./src/dir-index.html > ./base-html.html",
"build:minify-wrap": "(echo \"<style>\" && cat ./src/icons.css ./src/style.css | tr -d \"\t\n\r\" && echo && echo \"</style>\" && echo \"<script>\" && cat ./src/script.js | tr -d \"\t\n\n\" && echo && echo \"</script>\") > ./minified-wrapped.html",
"build:combine-html-css-js": "sed '/<\\/title>/ r ./minified-wrapped.html' ./base-html.html > ./dir-index.html",
"build:remove-unused": "rm ./base-html.html && rm ./minified-wrapped.html"
}
}
5 changes: 5 additions & 0 deletions assets/dir-index-html/src/dir-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlo89/56ZQ/8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUjDu1lo89/6mhTP+zrVP/nplD/5+aRK8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHNiIS6Wjz3/ubFY/761W/+vp1D/urRZ/8vDZf/GvmH/nplD/1BNIm8AAAAAAAAAAAAAAAAAAAAAAAAAAJaPPf+knEj/vrVb/761W/++tVv/r6dQ/7q0Wf/Lw2X/y8Nl/8vDZf+tpk7/nplD/wAAAAAAAAAAAAAAAJaPPf+2rVX/vrVb/761W/++tVv/vrVb/6+nUP+6tFn/y8Nl/8vDZf/Lw2X/y8Nl/8G6Xv+emUP/AAAAAAAAAACWjz3/vrVb/761W/++tVv/vrVb/761W/+vp1D/urRZ/8vDZf/Lw2X/y8Nl/8vDZf/Lw2X/nplD/wAAAAAAAAAAlo89/761W/++tVv/vrVb/761W/++tVv/r6dQ/7q0Wf/Lw2X/y8Nl/8vDZf/Lw2X/y8Nl/56ZQ/8AAAAAAAAAAJaPPf++tVv/vrVb/761W/++tVv/vbRa/5aPPf+emUP/y8Nl/8vDZf/Lw2X/y8Nl/8vDZf+emUP/AAAAAAAAAACWjz3/vrVb/761W/++tVv/vrVb/5qTQP+inkb/op5G/6KdRv/Lw2X/y8Nl/8vDZf/Lw2X/nplD/wAAAAAAAAAAlo89/761W/++tVv/sqlS/56ZQ//LxWb/0Mlp/9DJaf/Kw2X/oJtE/7+3XP/Lw2X/y8Nl/56ZQ/8AAAAAAAAAAJaPPf+9tFr/mJE+/7GsUv/Rymr/0cpq/9HKav/Rymr/0cpq/9HKav+xrFL/nplD/8vDZf+emUP/AAAAAAAAAACWjz3/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">
<script rel="script" src="script.js" async></script>
<title>{{ .Path }}</title>
</head>
<body>
Expand Down Expand Up @@ -70,6 +71,7 @@
</td>
<td></td>
<td></td>
<td></td>
</tr>
{{ range .Listing }}
<tr>
Expand All @@ -79,6 +81,9 @@
<td>
<a href="{{ .Path | urlEscape }}">{{ .Name }}</a>
</td>
<td class="not-cached-locally">
<div title="File not cached locally" class="">R</div>
</td>
<td class="no-linebreak">
{{ if .Hash }}
<a class="ipfs-hash" translate="no" href={{ if $root.DNSLink }}"https://cid.ipfs.io/#{{ .Hash | urlEscape}}" target="_blank" rel="noreferrer noopener"{{ else }}"{{ $root.GatewayURL }}/ipfs/{{ .Hash | urlEscape}}?filename={{ .Name | urlEscape }}"{{ end }}>
Expand Down
20 changes: 20 additions & 0 deletions assets/dir-index-html/src/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
document.addEventListener('DOMContentLoaded', () => {
const listingsPath = [
{{ range .Listing }}
'{{.Path}}',
{{ end }}
];

const init = {
method: 'GET',
headers: {'Accept': 'application/vnd.ipfs.cache.local'}
};

listingsPath.forEach((element, index) => {
fetch(element, init)
.then(response => {
if (response.status === 404)
document.getElementsByClassName('not-cached-locally').item(index).firstElementChild.style.display = 'block';
});
});
});
8 changes: 7 additions & 1 deletion assets/dir-index-html/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ td {
}

.type-icon,
.type-icon>* {
.type-icon>*,
.not-cached-locally,
.not-cached-locally>*{
width:1.15em
}

.not-cached-locally > div {
display: none;
}

.no-linebreak {
white-space:nowrap
}
Expand Down

0 comments on commit 5fa797a

Please sign in to comment.