mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
Sandbox ipfs renderer
This commit is contained in:
parent
3240c53174
commit
946f0b57fc
1 changed files with 20 additions and 5 deletions
|
|
@ -1,11 +1,25 @@
|
|||
loadSyle(document.currentScript.src.replace("js", "css"))
|
||||
// loadScript("https://unpkg.com/ipfs/dist/index.min.js", (scr) => {
|
||||
// let cid = params.url.replace("ipfs:",'');
|
||||
// console.log("script", scr, Ipfs, params)
|
||||
// getData(cid);
|
||||
// })
|
||||
|
||||
loadScript("https://unpkg.com/ipfs@0.63.2/dist/index.min.js", (scr) => {
|
||||
let cid = params.url.replace("ipfs:",'');
|
||||
console.log("script", scr, Ipfs, params)
|
||||
|
||||
getData(cid);
|
||||
})
|
||||
|
||||
async function test(cid) {
|
||||
let file = {
|
||||
path: "hello.txt",
|
||||
content: "Hello World 101",
|
||||
}
|
||||
console.log("adding", file)
|
||||
|
||||
const node = await Ipfs.create()
|
||||
console.log("adding", file)
|
||||
|
||||
const fileAdded = await node.add(file);
|
||||
console.log("added", fileAdded)
|
||||
}
|
||||
async function addData(data) {
|
||||
const node = await Ipfs.create()
|
||||
const results = node.add(data)
|
||||
|
|
@ -19,6 +33,7 @@ async function getData(cid) {
|
|||
const stream = node.cat(cid)
|
||||
const decoder = new TextDecoder()
|
||||
let data = ''
|
||||
console.log("Got IPFS Data", data)
|
||||
|
||||
for await (const chunk of stream) {
|
||||
data += decoder.decode(chunk, { stream: true })
|
||||
|
|
|
|||
Loading…
Reference in a new issue