Created
April 20, 2018 20:26
-
-
Save jacobmoyle/3fdd668818657ca6919623adb5104ffe to your computer and use it in GitHub Desktop.
Work in progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const fetchResume = (profile, params) => { | |
| if (!params.token) { | |
| throw new Error('Required params not given to download resume.'); | |
| } | |
| return { | |
| [RSAA]: { | |
| endpoint: `/profiles/${profile.get('id')}/download${buildUrlParams( | |
| params | |
| )}`, | |
| method: 'GET', | |
| types: [ | |
| PROFILES_RESUME_REQUEST, | |
| { | |
| type: PROFILES_RESUME_SUCCESS, | |
| payload: (action, state, res) => { | |
| let chunks = []; | |
| const reader = res.body.getReader(); | |
| reader | |
| .read() | |
| .then(function documentBuilder({ done, value }) { | |
| if (done) { | |
| console.log('stream complete'); | |
| return chunks; | |
| } | |
| console.log('stream not done'); | |
| console.log(value); | |
| chunks.push(value); | |
| return reader.read().then(documentBuilder); | |
| }) | |
| .then(chunks => { | |
| // debugger; | |
| const sampleArr = parseEncodingToString(chunks); | |
| saveByteArray('Sample Report', sampleArr); | |
| }); | |
| console.log('done bitch!', chunks); | |
| // const base64ToArrayBuffer = base64 => { | |
| const parseEncodingToString = chunks => { | |
| var binaryString = window.atob(chunks); | |
| debugger; | |
| // var binaryLen = binaryString.length; | |
| let string = uintToString(chunks); | |
| // var bytes = new Uint8Array(chunks[0]); | |
| // console.log('bytes: ', bytes); | |
| // for (var i = 0; i < chunks[0].length; i++) { | |
| // var ascii = chunks[0].charCodeAt(i); | |
| // console.log('ascii: ', ascii); | |
| // bytes[i] = ascii; | |
| // } | |
| // return bytes; | |
| return string; | |
| }; | |
| const saveByteArray = (reportName, byte) => { | |
| var blob = new Blob([byte], { type: 'text/plain' }); | |
| console.log(blob, byte); | |
| var link = document.createElement('a'); | |
| link.href = window.URL.createObjectURL(blob); | |
| var fileName = reportName; | |
| console.log(fileName); | |
| link.download = fileName; | |
| link.click(); | |
| }; | |
| function uintToString(uintArray) { | |
| let encodedString = ''; | |
| uintArray.map(chunk => { | |
| debugger; | |
| encodedString += String.fromCharCode(...chunk); | |
| }); | |
| // var encodedString = String.fromCharCode(...uintArray[0]); | |
| // var encodedString2 = String.fromCharCode(...uintArray[1]); | |
| // var bothStrings = (encodedString += encodedString2); | |
| // console.log(encodedString); | |
| // var decodedString = decodeURIComponent(escape(encodedString)); | |
| // return decodedString; | |
| return encodedString; | |
| } | |
| // var sampleArr = base64ToArrayBuffer(res); | |
| // saveByteArray('Sample Report', sampleArr); | |
| } | |
| }, | |
| { | |
| type: PROFILES_RESUME_FAILURE, | |
| meta: { errorMessage: 'There was a problem fetching the resume.' } | |
| } | |
| ], | |
| bailout: state => { | |
| // if (state.fetching && state.fetching.get('profiles')) { | |
| // return true; | |
| // } | |
| } | |
| } | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Console.log(‘done bitch’) hahahahahahaahahah