Sandbox ipfs renderer

This commit is contained in:
Nicholas Jitkoff 2022-06-15 07:49:46 -07:00
parent 3240c53174
commit 946f0b57fc

View file

@ -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 })