Skip to content
Snippets Groups Projects
Commit 792db626 authored by Adam Procter's avatar Adam Procter
Browse files

added in catch and try for IPFS

however IPFS node creation now seems to not work :(
parent fc839a44
Branches
No related tags found
No related merge requests found
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
ref="fileInput" ref="fileInput"
@change="onFileSelected" @change="onFileSelected"
/> />
<h1>{{ status }}</h1>
<h2>ID: {{ id }}</h2>
<h2>Agent version: {{ agentVersion }}</h2>
<!-- <!--
<button type="button" @click="saveIPFS">Upload</button> <button type="button" @click="saveIPFS">Upload</button>
<button type="button" @click="getIPFS">Get IPFS</button> --> <button type="button" @click="getIPFS">Get IPFS</button> -->
...@@ -44,8 +47,8 @@ export default { ...@@ -44,8 +47,8 @@ export default {
data: function () { data: function () {
return { return {
status: 'Connecting to IPFS...', status: 'Connecting to IPFS...',
// id: '', id: '',
// agentVersion: '', agentVersion: '',
selectedFile: null, selectedFile: null,
fileContents: this.fileContents, fileContents: this.fileContents,
output: output, output: output,
...@@ -79,7 +82,7 @@ export default { ...@@ -79,7 +82,7 @@ export default {
try { try {
// Await for ipfs node instance. // Await for ipfs node instance.
node = await ipfs node = await ipfs
//console.log(ipfs) // console.log(node)
// Call ipfs `id` method. // Call ipfs `id` method.
// Returns the identity of the Peer. // Returns the identity of the Peer.
const { agentVersion, id } = await node.id() const { agentVersion, id } = await node.id()
...@@ -99,20 +102,30 @@ export default { ...@@ -99,20 +102,30 @@ export default {
}, },
async saveIPFS() { async saveIPFS() {
for await (const result of node.add(this.selectedFile)) { try {
//console.log(result.cid.string) for await (const result of node.add(this.selectedFile)) {
this.fileContents = result //console.log(result.cid.string)
// console.log(this.fileContents.path) this.fileContents = result
// node.swarm.peers().then((a) => console.log(a)) // console.log(this.fileContents.path)
this.getIPFS() // node.swarm.peers().then((a) => console.log(a))
this.getIPFS()
}
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
} }
}, },
async getIPFS() { async getIPFS() {
for await (const newfile of node.get(this.fileContents.path)) { try {
// console.log(newfile.path) for await (const newfile of node.get(this.fileContents.path)) {
this.path = newfile.path // console.log(newfile.path)
this.copyClipBoard(this.path) this.path = newfile.path
this.copyClipBoard(this.path)
}
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment