"epubField" mechanism for gun rpc
This commit is contained in:
parent
03b957f15c
commit
1a15d20441
1 changed files with 35 additions and 6 deletions
|
|
@ -122,6 +122,8 @@ const executeGunQuery = (query, method, listener) => {
|
||||||
* @param {string} queryData.subscriptionId
|
* @param {string} queryData.subscriptionId
|
||||||
* @param {string} queryData.deviceId
|
* @param {string} queryData.deviceId
|
||||||
* @param {string=} queryData.epubForDecryption
|
* @param {string=} queryData.epubForDecryption
|
||||||
|
* @param {string=} queryData.epubField If the epub is included in the received
|
||||||
|
* data itself. Handshake requests for example, have an epub field.
|
||||||
* @returns {GunListener}
|
* @returns {GunListener}
|
||||||
*/
|
*/
|
||||||
const queryListenerCallback = ({
|
const queryListenerCallback = ({
|
||||||
|
|
@ -129,7 +131,8 @@ const queryListenerCallback = ({
|
||||||
publicKeyForDecryption,
|
publicKeyForDecryption,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
deviceId,
|
deviceId,
|
||||||
epubForDecryption
|
epubForDecryption,
|
||||||
|
epubField
|
||||||
}) => async (data, key, _msg, event) => {
|
}) => async (data, key, _msg, event) => {
|
||||||
try {
|
try {
|
||||||
const subscription = Subscriptions.get({
|
const subscription = Subscriptions.get({
|
||||||
|
|
@ -144,12 +147,37 @@ const queryListenerCallback = ({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const eventName = `query:data`
|
const eventName = `query:data`
|
||||||
|
if (publicKeyForDecryption?.length > 15 || epubForDecryption || epubField) {
|
||||||
if (publicKeyForDecryption?.length > 15) {
|
|
||||||
const decData = await deepDecryptIfNeeded(
|
const decData = await deepDecryptIfNeeded(
|
||||||
data,
|
data,
|
||||||
publicKeyForDecryption,
|
publicKeyForDecryption,
|
||||||
epubForDecryption
|
(() => {
|
||||||
|
if (epubField) {
|
||||||
|
if (Common.isObj(data)) {
|
||||||
|
const epub = data[epubField]
|
||||||
|
if (Common.isPopulatedString(epub)) {
|
||||||
|
return epub
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error(
|
||||||
|
`Got epubField in a rifle query, but the resulting value obtained is not an string -> `,
|
||||||
|
{
|
||||||
|
data,
|
||||||
|
epub
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
logger.warn(
|
||||||
|
`Got epubField in a rifle query for a non-object data -> `,
|
||||||
|
{
|
||||||
|
epubField,
|
||||||
|
data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return epubForDecryption
|
||||||
|
})()
|
||||||
)
|
)
|
||||||
emit(eventName, { subscriptionId, response: { data: decData, key } })
|
emit(eventName, { subscriptionId, response: { data: decData, key } })
|
||||||
return
|
return
|
||||||
|
|
@ -258,7 +286,7 @@ const startSocket = socket => {
|
||||||
}
|
}
|
||||||
|
|
||||||
on('subscribe:query', (query, response) => {
|
on('subscribe:query', (query, response) => {
|
||||||
const { $shock, publicKey, epubForDecryption } = query
|
const { $shock, publicKey, epubForDecryption, epubField } = query
|
||||||
const subscriptionId = uuidv4()
|
const subscriptionId = uuidv4()
|
||||||
try {
|
try {
|
||||||
if (!isAuthenticated()) {
|
if (!isAuthenticated()) {
|
||||||
|
|
@ -286,7 +314,8 @@ const startSocket = socket => {
|
||||||
publicKeyForDecryption: publicKey,
|
publicKeyForDecryption: publicKey,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
deviceId: encryptionId,
|
deviceId: encryptionId,
|
||||||
epubForDecryption
|
epubForDecryption,
|
||||||
|
epubField
|
||||||
})
|
})
|
||||||
|
|
||||||
socketCallback(null, {
|
socketCallback(null, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue