Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 0bbf953

Browse files
committed
Setup adding download link for file
1 parent a34c207 commit 0bbf953

File tree

1 file changed

+24
-1
lines changed
  • examples/transfer-files/complete/js

1 file changed

+24
-1
lines changed

examples/transfer-files/complete/js/app.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const $allDisabledInputs = document.querySelectorAll('input:disabled')
2020
let ipfs
2121
let peerInfo
2222

23+
// TODO groups
24+
// ipfs stuff
25+
// creating html stuff
26+
// event listeners
27+
// states
28+
2329
function start () {
2430
if (!ipfs) {
2531
updateView('starting', ipfs)
@@ -74,6 +80,19 @@ const catFile = () => {
7480
console.log('file got end')
7581
console.log(buf)
7682
})
83+
// TODO currently, can't grab content from file either in get...
84+
const downloadContent = window.btoa(window.unescape(window.encodeURIComponent('content of file')))
85+
const downloadLink = 'data:application/octet-stream;charset=utf-8;base64,' + downloadContent
86+
const listItem = document.createElement('div')
87+
const link = document.createElement('a')
88+
link.setAttribute('href', downloadLink)
89+
link.setAttribute('download', multihash)
90+
const date = (new Date()).toLocaleTimeString()
91+
link.innerText = date + ' - ' + multihash + ' - Size: ' + file.size
92+
const fileList = document.querySelector('.file-list')
93+
94+
listItem.appendChild(link)
95+
fileList.insertBefore(listItem, fileList.firstChild)
7796
}
7897
})
7998
stream.on('end', () => {
@@ -208,4 +227,8 @@ function updateView (state, ipfs) {
208227
}
209228
}
210229

211-
setupEventListeners()
230+
const startApplication = () => {
231+
setupEventListeners()
232+
}
233+
234+
startApplication()

0 commit comments

Comments
 (0)