floCloudAPI v2.4.4: edit comment feature

- senders can now edit the comment of data they sent (by re-signing the new data)
This commit is contained in:
sairajzero 2023-07-26 03:45:35 +05:30
parent 904deaa63c
commit 471f291848

View File

@ -1,4 +1,4 @@
(function (EXPORTS) { //floCloudAPI v2.4.3a (function (EXPORTS) { //floCloudAPI v2.4.4
/* FLO Cloud operations to send/request application data*/ /* FLO Cloud operations to send/request application data*/
'use strict'; 'use strict';
const floCloudAPI = EXPORTS; const floCloudAPI = EXPORTS;
@ -609,49 +609,39 @@
}) })
} }
*/ */
/*(NEEDS UPDATE) //edit comment of data in supernode cloud (sender only)
//edit comment of data in supernode cloud (mutable comments only) floCloudAPI.editApplicationData = function (vectorClock, comment_edit, options = {}) {
floCloudAPI.editApplicationData = function(vectorClock, newComment, oldData, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let p0 //request the data from cloud for resigning
if (!oldData) { let req_options = Object.assign({}, options);
options.atVectorClock = vectorClock; req_options.atVectorClock = vectorClock;
options.callback = false; requestApplicationData(undefined, req_options).then(result => {
p0 = requestApplicationData(false, options) if (!result.length)
} else return reject("Data not found");
p0 = Promise.resolve({ let data = result[0];
vectorClock: { if (data.senderID !== user.id)
...oldData return reject("Only sender can edit comment");
} data.comment = comment_edit;
}) let hashcontent = ["receiverID", "time", "application", "type", "message", "comment"]
p0.then(d => { .map(d => data[d]).join("|");
if (d.senderID != user.id) let re_sign = user.sign(hashcontent);
return reject("Invalid requestorID") var request = {
else if (!d.comment.startsWith("EDIT:")) receiverID: options.receiverID || DEFAULT.adminID,
return reject("Data immutable")
let data = {
requestorID: user.id, requestorID: user.id,
receiverID: d.receiverID, pubKey: user.public,
time: Date.now(), time: Date.now(),
application: d.application, vectorClock: vectorClock,
edit: { edit: comment_edit,
vectorClock: vectorClock, re_sign: re_sign
comment: newComment
}
} }
d.comment = data.edit.comment; let request_hash = ["time", "vectorClock", "edit", "re_sign"].map(d => request[d]).join("|");
let hashcontent = ["receiverID", "time", "application", "type", "message", request.sign = user.sign(request_hash);
"comment" singleRequest(request.receiverID, request)
] .then(result => resolve(result))
.map(x => d[x]).join("|")
data.edit.sign = user.sign(hashcontent)
singleRequest(data.receiverID, data)
.then(result => resolve("Data comment updated"))
.catch(error => reject(error)) .catch(error => reject(error))
}) }).catch(error => reject(error))
}) })
} }
*/
//tag data in supernode cloud (subAdmin access only) //tag data in supernode cloud (subAdmin access only)
floCloudAPI.tagApplicationData = function (vectorClock, tag, options = {}) { floCloudAPI.tagApplicationData = function (vectorClock, tag, options = {}) {