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

more ipfs tests

parent 46080604
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,21 @@ ...@@ -3,13 +3,21 @@
<h1>{{ status }}</h1> <h1>{{ status }}</h1>
<h2>ID: {{ id }}</h2> <h2>ID: {{ id }}</h2>
<h2>Agent version: {{ agentVersion }}</h2> <h2>Agent version: {{ agentVersion }}</h2>
<h3>Files : {{ fileContents }}</h3>
<form> <form>
<input <input
class="fileInput"
type="file" type="file"
name="import_file" name="fileInput"
v-on:change="selectedFile($event)" ref="fileInput"
@change="onFileSelected"
/> />
<!-- <button @click="this.refs.selectedFile.click()">Choose File</button> -->
<button type="button" @click="saveIPFS">Upload</button>
<button type="button" @click="getIPFS">Get IPFS</button>
</form> </form>
</div> </div>
</template> </template>
...@@ -17,10 +25,9 @@ ...@@ -17,10 +25,9 @@
<script> <script>
import VueIpfs from 'ipfs' import VueIpfs from 'ipfs'
const ipfs = VueIpfs.create() const ipfs = VueIpfs.create()
var node
// var ipfs = VueIpfs var file
// TODO: WOULD BE TO USE add and data is what has come from Vue Form const fileContents = []
// ipfs.add(data, [options])
// The below code should create an IPFS node to add files to // The below code should create an IPFS node to add files to
export default { export default {
...@@ -30,22 +37,44 @@ export default { ...@@ -30,22 +37,44 @@ export default {
status: 'Connecting to IPFS...', status: 'Connecting to IPFS...',
id: '', id: '',
agentVersion: '', agentVersion: '',
selectedFile: null,
fileContents: this.fileContents,
} }
}, },
mounted: function () { mounted: function () {
console.log(VueIpfs) // console.log(VueIpfs)
this.getIpfsNodeInfo() this.getIpfsNodeInfo()
}, },
methods: { methods: {
selectedFile(event) { onFileSelected(event) {
this.file = event.target.files[0] this.selectedFile = event.target.files[0]
console.log(this.file) },
// ipfs.add(this.file)
saveIPFS() {
file = node.files.write('/' + this.selectedFile.name, this.selectedFile, {
create: true,
})
return file
}, },
// getIPFS() {
// const resultPart = node.files.ls('/')
// fileContents.push(resultPart)
// // console.log(fileContents)
// return fileContents
// },
getIPFS() {
const resultPart = node.files.read('/')
fileContents.push(resultPart)
// console.log(fileContents)
return fileContents
},
async getIpfsNodeInfo() { async getIpfsNodeInfo() {
try { try {
// Await for ipfs node instance. // Await for ipfs node instance.
const node = await ipfs node = await ipfs
//console.log(ipfs) //console.log(ipfs)
// Call ipfs `id` method. // Call ipfs `id` method.
// Returns the identity of the Peer. // Returns the identity of the Peer.
...@@ -63,4 +92,8 @@ export default { ...@@ -63,4 +92,8 @@ export default {
} }
</script> </script>
<style lang="css" scoped></style> <style lang="css" scoped>
.fileInput {
/* display: none; */
}
</style>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment