diff options
-rw-r--r-- | src/js/arching-kaos-file-system.js | 19 | ||||
-rw-r--r-- | src/js/utils.js | 6 |
2 files changed, 18 insertions, 7 deletions
diff --git a/src/js/arching-kaos-file-system.js b/src/js/arching-kaos-file-system.js index 1c12a06..bee474e 100644 --- a/src/js/arching-kaos-file-system.js +++ b/src/js/arching-kaos-file-system.js @@ -88,10 +88,21 @@ function akfsFromMapGetOriginalHash(reply, params) function akfsFromMapGetOriginalFilename(reply, params) { - const [ hash ] = params; + const [ data, toDownload ] = params; if(typeof(reply) === "string") { - console.log(reply.split('\n')[0].split(' ')[1]); + // console.log(reply.split('\n')[0].split(' ')[1]); + var first_line = reply.split('\n')[0].split(' '); + var filename = ""; + for ( let i = 1; i < first_line.length; i++ ) + { + filename += first_line[i]; + if ( i < first_line.length - 1 ) + { + filename += " "; + } + } + if ( toDownload ) offerDownloadableData(data, filename); } } @@ -159,9 +170,9 @@ export function akfsWorkOnChunks() { akfsSerializeChunks(thingy.root_hash); var data = makeUpData(); - offerDownloadableData(data); + archingKaosFetchBlob(akfsGetMapURL(thingy.map_hash), akfsFromMapGetOriginalFilename, [data, true]); downloaded = true; - console.log(workspace); + // console.log(workspace); } function akfsChunkOrLeaf(reply, params) diff --git a/src/js/utils.js b/src/js/utils.js index 6a355a8..a5f34dc 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -27,10 +27,10 @@ export function debugLog(message) if (showDebug) console.log(message); } -export function offerDownloadableData(data) +export function offerDownloadableData(data, filename) { var link = document.createElement('a'); - link.download = 'data'; + link.download = filename === undefined ? 'data': filename; var blob = new Blob([data]); // , {type: 'text/plain'} link.href = window.URL.createObjectURL(blob); link.click(); @@ -46,6 +46,6 @@ export function decodeBase64ToHex(base64String) { // Convert the byte array to a hex string representation return Array.from(byteArray) .map(byte => byte.toString(16).padStart(2, '0')) // Convert to hex and pad with zeros - .join(''); // Join with spaces for readability + .join(''); } // @license-end |