From 792db6263a1b4d091af418fca7ff64eef68ce669 Mon Sep 17 00:00:00 2001 From: Adam Procter <adamprocter@researchnot.es> Date: Tue, 30 Jun 2020 15:41:18 +0100 Subject: [PATCH] added in catch and try for IPFS however IPFS node creation now seems to not work :( --- app/src/components/UploadLayer.vue | 39 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/app/src/components/UploadLayer.vue b/app/src/components/UploadLayer.vue index 62e0145..034645d 100644 --- a/app/src/components/UploadLayer.vue +++ b/app/src/components/UploadLayer.vue @@ -9,6 +9,9 @@ ref="fileInput" @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="getIPFS">Get IPFS</button> --> @@ -44,8 +47,8 @@ export default { data: function () { return { status: 'Connecting to IPFS...', - // id: '', - // agentVersion: '', + id: '', + agentVersion: '', selectedFile: null, fileContents: this.fileContents, output: output, @@ -79,7 +82,7 @@ export default { try { // Await for ipfs node instance. node = await ipfs - //console.log(ipfs) + // console.log(node) // Call ipfs `id` method. // Returns the identity of the Peer. const { agentVersion, id } = await node.id() @@ -99,20 +102,30 @@ export default { }, async saveIPFS() { - for await (const result of node.add(this.selectedFile)) { - //console.log(result.cid.string) - this.fileContents = result - // console.log(this.fileContents.path) - // node.swarm.peers().then((a) => console.log(a)) - this.getIPFS() + try { + for await (const result of node.add(this.selectedFile)) { + //console.log(result.cid.string) + this.fileContents = result + // console.log(this.fileContents.path) + // node.swarm.peers().then((a) => console.log(a)) + this.getIPFS() + } + } catch (err) { + // Set error status text. + this.status = `Error: ${err}` } }, async getIPFS() { - for await (const newfile of node.get(this.fileContents.path)) { - // console.log(newfile.path) - this.path = newfile.path - this.copyClipBoard(this.path) + try { + for await (const newfile of node.get(this.fileContents.path)) { + // console.log(newfile.path) + this.path = newfile.path + this.copyClipBoard(this.path) + } + } catch (err) { + // Set error status text. + this.status = `Error: ${err}` } }, -- GitLab