Created
November 24, 2015 13:19
-
-
Save frenchbread/6d82223508dcc02db74d to your computer and use it in GitHub Desktop.
This file contains 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
Template.importApiDocumentation.events({ | |
'change #apiDocumentationFile': function (event/*, template*/) { | |
var customProxy = "umbrella.apinf.io"; | |
var customBasePath = "/api-umbrella"; | |
// Gets selected file from the form | |
var file = event.target.files[0]; | |
// Initialises new reader instance | |
var reader = new FileReader(); | |
// Reads file | |
reader.readAsText(file, "UTF-8"); | |
// When ready .. | |
reader.onload = function (event) { | |
// Gets file data from reader object | |
var fileData = event.target.result; | |
// Parses file data to JSON object, to be able to modify it | |
var dataObj = JSON.parse(fileData); | |
// Saving initial values of `host` and `basePath` | |
dataObj.initial_host = dataObj.host; | |
dataObj.initial_basePath = dataObj.basePath; | |
// Updating values | |
dataObj.host = customProxy; | |
dataObj.basePath = customBasePath; | |
var documentationFile = JSON.stringify(dataObj); | |
// Creates blob object with content type of JSON | |
var blobData = new Blob([documentationFile], {type: "application/json"}); | |
// Creates file object from Blob object | |
var updatedFile = new File([blobData], file.name, {type: "application/json"}); | |
// Insert into filesystem collection | |
ApiDocumentation.insert(updatedFile); | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment