Skip to content

Commit

Permalink
Load File function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-Fernando-Molina committed Dec 18, 2021
1 parent 2977daa commit d2832d1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
3 changes: 2 additions & 1 deletion DesktopRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ exports.newDesktopRoot = function newDesktopRoot() {
octokit: require("@octokit/rest"),
simpleGit: require('simple-git'),
nodeFetch: require('node-fetch'),
graphql: require("@octokit/graphql")
graphql: require("@octokit/graphql"),
axios: require('axios')
}
SA.version = require('./package.json').version
/*
Expand Down
3 changes: 2 additions & 1 deletion DesktopRootReact.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ exports.newDesktopRoot = function newDesktopRoot() {
octokit: require("@octokit/rest"),
simpleGit: require('simple-git'),
nodeFetch: require('node-fetch'),
graphql: require("@octokit/graphql")
graphql: require("@octokit/graphql"),
axios: require('axios')
}
SA.version = require('./package.json').version
/*
Expand Down
3 changes: 2 additions & 1 deletion NetworkRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ exports.newNetworkRoot = function newNetworkRoot() {
web3: require('web3'),
ws: require('ws'),
simpleGit: require('simple-git'),
graphql: require("@octokit/graphql")
graphql: require("@octokit/graphql"),
axios: require('axios')
}
SA.version = require('./package.json').version
/*
Expand Down
3 changes: 2 additions & 1 deletion PlatformRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ SA.nodeModules = {
process: require('process'),
childProcess: require('child_process'),
twitter: require('twitter-api-v2'),
slack: require('@slack/web-api')
slack: require('@slack/web-api'),
axios: require('axios')
}

SA.version = require('./package.json').version
Expand Down
4 changes: 2 additions & 2 deletions Projects/Network/SA/Modules/HttpNetworkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.newNetworkModulesHttpNetworkClient = function newNetworkModulesHttpNetwo
*/
let promise = new Promise((resolve, reject) => {

const axios = require('axios')
const axios = SA.nodeModules.axios
axios
.post('http://' + thisObject.host + ':' + thisObject.port + '/New-Signal', message)
.then(res => {
Expand All @@ -67,7 +67,7 @@ exports.newNetworkModulesHttpNetworkClient = function newNetworkModulesHttpNetwo
*/
let promise = new Promise((resolve, reject) => {

const axios = require('axios')
const axios = SA.nodeModules.axios
axios
.post('http://' + thisObject.host + ':' + thisObject.port + '/Ping')
.then(res => {
Expand Down
38 changes: 32 additions & 6 deletions Projects/Open-Storage/SA/Utilities/GithubStorage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
exports.newOpenStorageUtilitiesGithubStorage = function () {

let thisObject = {
saveData: saveData,
fetchData: fetchData
saveFile: saveFile,
loadFile: loadFile
}

return thisObject

async function saveData(fileName, filePath, fileContent, sotrageContainer) {
async function saveFile(fileName, filePath, fileContent, sotrageContainer) {

const token = SA.secrets.apisSecrets.map.get(sotrageContainer.config.codeName).apiToken
const { Octokit } = SA.nodeModules.octokit
Expand Down Expand Up @@ -43,7 +43,7 @@ exports.newOpenStorageUtilitiesGithubStorage = function () {
repository.name === undefined ||
repository.object === null
) {
console.log('[ERROR] Github Storage -> Save Data -> SHA graphql failed.')
console.log('[ERROR] Github Storage -> Save File -> SHA graphql failed.')
return
}

Expand All @@ -52,7 +52,7 @@ exports.newOpenStorageUtilitiesGithubStorage = function () {
if (
sha === undefined
) {
console.log('[ERROR] Github Storage -> Save Data -> SHA calculation failed.')
console.log('[ERROR] Github Storage -> Save File -> SHA calculation failed.')
return
}

Expand All @@ -70,7 +70,33 @@ exports.newOpenStorageUtilitiesGithubStorage = function () {
})
}

async function fetchData(fileName, sotrageContainer) {
async function loadFile(fileName, filePath, sotrageContainer) {

const completePath = filePath + '/' + fileName + '.json'
const repo = sotrageContainer.config.repositoryName
const owner = sotrageContainer.config.githubUserName
const branch = 'main'
const URL = "https://raw.githubusercontent.com/" + owner + "/" + repo + "/" + branch + "/" + completePath
/*
This function helps a caller to use await syntax while the called
function uses callbacks, specifically for retrieving files.
*/
let promise = new Promise((resolve, reject) => {

const axios = SA.nodeModules.axios
axios
.get(URL)
.then(res => {
//console.log(`statusCode: ${res.status}`)

resolve(res.data)
})
.catch(error => {
console.error('[ERROR] Github Storage -> Load File -> Error = ' + error)
reject()
})
})

return promise
}
}
3 changes: 2 additions & 1 deletion TaskServerRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ SA.nodeModules = {
ccxtMisc: require('./node_modules/ccxt/js/base/functions/misc'),
lookpath: require('lookpath'),
twitter: require('twitter-api-v2'),
graphql: require("@octokit/graphql")
graphql: require("@octokit/graphql"),
axios: require('axios')
}
SA.version = require('./package.json').version
/*
Expand Down

0 comments on commit d2832d1

Please sign in to comment.