Skip to content

Commit

Permalink
Basic Implementation of Github Storage save file function
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-Fernando-Molina committed Dec 18, 2021
1 parent 071ed72 commit e26dae7
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 43 deletions.
92 changes: 50 additions & 42 deletions Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json
Original file line number Diff line number Diff line change
Expand Up @@ -6718,11 +6718,11 @@
"savedPayload": {
"position": {
"x": 33633.333333333336,
"y": 18800
"y": 23600
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand All @@ -6745,11 +6745,11 @@
"savedPayload": {
"position": {
"x": 33520.38027389096,
"y": 19034.54944474041
"y": 23834.54944474041
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand Down Expand Up @@ -7259,11 +7259,11 @@
"savedPayload": {
"position": {
"x": 33266.577053146444,
"y": 19092.478373654547
"y": 23892.478373654547
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand Down Expand Up @@ -7420,11 +7420,11 @@
"savedPayload": {
"position": {
"x": 32724.954991387654,
"y": 19590.617815763602
"y": 24390.617815763602
},
"targetPosition": {
"x": 32623.755995172804,
"y": 19308.20187576533
"y": 24108.20187576533
},
"floatingObject": {
"isPinned": false,
Expand All @@ -7448,11 +7448,11 @@
"savedPayload": {
"position": {
"x": 32539.627778381004,
"y": 19596.1644482282
"y": 24396.1644482282
},
"targetPosition": {
"x": 32623.755995172804,
"y": 19308.20187576533
"y": 24108.20187576533
},
"floatingObject": {
"isPinned": false,
Expand Down Expand Up @@ -9063,11 +9063,11 @@
"savedPayload": {
"position": {
"x": 32386.4346847759,
"y": 19491.719165499835
"y": 24291.719165499835
},
"targetPosition": {
"x": 32623.755995172804,
"y": 19308.20187576533
"y": 24108.20187576533
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9090,18 +9090,18 @@
"storageContainerReferences": [
{
"type": "Storage Container Reference",
"name": "",
"name": "Github Repository My-Trading-Signals",
"config": "{}",
"project": "Open-Storage",
"id": "bd5d0ff5-f0f0-40b8-bb05-4998cb56da11",
"savedPayload": {
"position": {
"x": 32024.024535802702,
"y": 19326.151155466974
"y": 24126.151155466974
},
"targetPosition": {
"x": 32323.890265487753,
"y": 19317.176515616153
"y": 24117.176515616153
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9122,19 +9122,27 @@
"referenceParentCombinedNodePath": [
[
"Luis-Fernando-Molina",
"User Profile"
"User Profile",
"Governance",
"a8de78f0-c3e4-4a2a-b7e8-f659073969db"
],
[
"New User Storage",
"User Storage"
"User Storage",
"Open-Storage",
"70d2d75b-ad84-4386-93f5-13ad56c111f7"
],
[
"New Github Storage",
"Github Storage"
"Github Storage",
"Open-Storage",
"f141613b-ea77-425c-8e3b-9874a638fcab"
],
[
"Github Repository My-Trading-Signals",
"Storage Container"
"Storage Container",
"Open-Storage",
"51548a10-7f67-4850-8687-e34a9e49ab4e"
]
]
}
Expand All @@ -9144,11 +9152,11 @@
"savedPayload": {
"position": {
"x": 32323.890265487753,
"y": 19317.176515616153
"y": 24117.176515616153
},
"targetPosition": {
"x": 32623.755995172804,
"y": 19308.20187576533
"y": 24108.20187576533
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9167,16 +9175,16 @@
"savedPayload": {
"position": {
"x": 32623.755995172804,
"y": 19308.20187576533
"y": 24108.20187576533
},
"targetPosition": {
"x": 32792.75201259189,
"y": 19060.330243470533
"y": 23860.330243470533
},
"floatingObject": {
"isPinned": false,
"isFrozen": false,
"isCollapsed": false,
"isCollapsed": true,
"angleToParent": 2,
"distanceToParent": 3,
"arrangementStyle": 0
Expand Down Expand Up @@ -9251,11 +9259,11 @@
"savedPayload": {
"position": {
"x": 32493.590873437533,
"y": 19037.911215394604
"y": 23837.911215394604
},
"targetPosition": {
"x": 32792.75201259189,
"y": 19060.330243470533
"y": 23860.330243470533
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9275,11 +9283,11 @@
"savedPayload": {
"position": {
"x": 32792.75201259189,
"y": 19060.330243470533
"y": 23860.330243470533
},
"targetPosition": {
"x": 33063.04267296261,
"y": 18930.165121735266
"y": 23730.165121735266
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9298,11 +9306,11 @@
"savedPayload": {
"position": {
"x": 33063.04267296261,
"y": 18930.165121735266
"y": 23730.165121735266
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand Down Expand Up @@ -9576,11 +9584,11 @@
"savedPayload": {
"position": {
"x": 33063.04267296261,
"y": 18669.834878264734
"y": 23469.834878264734
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand Down Expand Up @@ -9718,11 +9726,11 @@
"savedPayload": {
"position": {
"x": 33266.577053146444,
"y": 18507.521626345453
"y": 23307.521626345453
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand Down Expand Up @@ -9757,11 +9765,11 @@
"savedPayload": {
"position": {
"x": 33894.4741550062,
"y": 18096.351665778773
"y": 22896.351665778773
},
"targetPosition": {
"x": 33707.42721444858,
"y": 18330.901110519182
"y": 23130.901110519182
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9781,11 +9789,11 @@
"savedPayload": {
"position": {
"x": 33707.42721444858,
"y": 18330.901110519182
"y": 23130.901110519182
},
"targetPosition": {
"x": 33520.38027389096,
"y": 18565.45055525959
"y": 23365.45055525959
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9804,11 +9812,11 @@
"savedPayload": {
"position": {
"x": 33520.38027389096,
"y": 18565.45055525959
"y": 23365.45055525959
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": false,
Expand All @@ -9827,11 +9835,11 @@
"savedPayload": {
"position": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"targetPosition": {
"x": 33333.333333333336,
"y": 18800
"y": 23600
},
"floatingObject": {
"isPinned": true,
Expand Down
76 changes: 76 additions & 0 deletions Projects/Open-Storage/SA/Utilities/GithubStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
exports.newOpenStorageUtilitiesGithubStorage = function () {

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

return thisObject

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

const token = 'GET THE TOKEN FROM THE SECRETS FILE'
const { Octokit } = SA.nodeModules.octokit
const octokit = new Octokit({
auth: token,
userAgent: 'Superalgos ' + SA.version
})
const repo = sotrageContainer.config.repositoryName
const owner = sotrageContainer.config.githubUserName
const branch = 'main'
const message = 'Open Storage: New File.'
const completePath = filePath + '/' + fileName + '.json'
const { graphql } = SA.nodeModules.graphql
const { repository } = await graphql(
'{ ' +
' repository(name: "SuperAlgos", owner: "' + owner + '") {' +
' object(expression: "' + branch + ':' + completePath + '") {' +
' ... on Blob {' +
' oid' +
' }' +
' }' +
' name' +
' }' +
'}',
{
headers: {
authorization: 'token ' + token
}
}
)

if (
repository.name === undefined ||
repository.object === null
) {
console.log('[ERROR] Github Storage -> Save Data -> SHA graphql failed.')
return
}

const sha = repository.object.oid

if (
sha === undefined
) {
console.log('[ERROR] Github Storage -> Save Data -> SHA calculation failed.')
return
}

const buff = new Buffer.from(fileContent, 'utf-8');
const content = buff.toString('base64');

await octokit.repos.createOrUpdateFileContents({
owner: owner,
repo: repo,
filePath: completePath,
message: message,
content: content,
sha: sha,
branch: branch
})
}

async function fetchData(fileName, sotrageContainer) {

}
}
9 changes: 8 additions & 1 deletion Projects/ProjectsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,14 @@
"modules": []
},
"SA": {
"utilities": []
"utilities": [
{
"name": "Github Storage",
"propertyName": "githubStorage",
"functionName": "newOpenStorageUtilitiesGithubStorage",
"fileName": "GithubStorage.js"
}
]
}
}
]

0 comments on commit e26dae7

Please sign in to comment.