This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (50 loc) · 1.77 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<script>
import * as wn from "webnative"
import { getSimpleLinks } from "webnative/fs/protocol/basic"
import { PublicFile } from "webnative/fs/v1/PublicFile"
import { PublicTree } from "webnative/fs/v1/PublicTree"
const USERNAME_TO_LOOKUP = "icidasset"
async function init() {
const program = await wn.program({
namespace: "public-data-viewer"
})
const { depot, reference } = program.components
const cid = await reference.dataRoot.lookup(USERNAME_TO_LOOKUP)
const publicCid = (await getSimpleLinks(depot, cid)).public.cid
const publicTree = await PublicTree.fromCID(depot, reference, publicCid)
const unsplashDir = await publicTree.get(
wn.path.unwrap(wn.path.directory("Unsplash")) // [ "Unsplash" ]
)
const links = Object.values(
await unsplashDir.ls([])
)
// Render pictures
const pictures = await Promise.all(
links.map(async picture => {
const file = await unsplashDir.get([ picture.name ])
// Alternatively, load the public file directly
// const file = await PublicFile.fromCID(depot, picture.cid)
// Picture `src`
const url = URL.createObjectURL(new Blob([ file.content ]))
// Alternatively, use the IPFS gateway
// const url = `https://ipfs.runfission.com/ipfs/${picture.cid.toString()}/userland`
return `<img src="${url}" width="400" style="max-width: 90vw" /><br />`
})
)
return `
<div>
${pictures.join("")}
</div>
`
}
let promise = init()
</script>
<div>
{#await promise}
<p>Waiting ...</p>
{:then contents}
<p>{@html contents}</p>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
</div>