Posts being sent to Users Social Trading Repo

This commit is contained in:
Luis Fernando Molina committed 2021-09-12 11:01:21 +02:00
1 parent 3d0db423ed
commit 2b92426d9c
13 files changed
+372 -58

No files matched your search

@@ -65,6 +65,40 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule
}
return JSON.stringify(response)
}
if (
eventMessage.eventType === SA.projects.socialTrading.globals.eventTypes.NEW_USER_POST ||
eventMessage.eventType === SA.projects.socialTrading.globals.eventTypes.REPLY_TO_USER_POST ||
eventMessage.eventType === SA.projects.socialTrading.globals.eventTypes.REPOST_USER_POST
) {
/*
We need to save the post at the User's storage and remove the text from the message
going to the Network Node.
*/
let commitMessage
switch (eventMessage.eventType) {
case SA.projects.socialTrading.globals.eventTypes.NEW_USER_POST: {
commitMessage = "New Post"
break
}
case SA.projects.socialTrading.globals.eventTypes.REPLY_TO_USER_POST: {
commitMessage = "Reply to User Post"
break
}
case SA.projects.socialTrading.globals.eventTypes.REPOST_USER_POST: {
commitMessage = "Repost User Post"
break
}
}
/*
The post text is eliminated, since it is now at the user's storage,
and a hash of the content was generated, and that is what is going to
the Network Node.
*/
eventMessage.emitterPostHash = await savePostAtStorage(eventMessage.text, commitMessage, eventMessage.timestamp)
eventMessage.text = undefined
}
eventMessage.emitterUserProfileId = DK.TEST_NETWORK_CLIENT_USER_PROFILE_ID
messageHeader.eventMessage = JSON.stringify(eventMessage)
@@ -84,4 +118,35 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule
}
}
}
async function savePostAtStorage(text, commitMessage, timestamp) {
const { createHash } = await import('crypto')
const hash = createHash('sha256')
let post = {
timestamp: timestamp,
text: text
}
const fileContent = JSON.stringify(post, undefined, 4)
const fileHash = hash.update(fileContent).digest('hex')
const fileName = fileHash + ".json"
let filePath = './My-Social-Trading-Data/User-Posts/' + SA.projects.foundations.utilities.filesAndDirectories.pathFromDate(timestamp)
TS.projects.foundations.utilities.miscellaneousFunctions.mkDirByPathSync(filePath)
SA.nodeModules.fs.writeFileSync(filePath + '/' + fileName, fileContent)
const options = {
baseDir: process.cwd() + '/My-Social-Trading-Data',
binary: 'git',
maxConcurrentProcesses: 6,
}
const git = SA.nodeModules.simpleGit(options)
await git.add('./*')
await git.commit(commitMessage)
await git.push('origin')
return fileHash
}
}
@@ -139,8 +139,6 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() {
emitterUserProfile.addPost(
thisObject.emitterUserProfileId,
thisObject.targetUserProfileId,
thisObject.emitterBotProfileId,
thisObject.targetBotProfileId,
thisObject.emitterPostHash,
thisObject.targetPostHash,
thisObject.eventType - 10,