mirror of https://codeberg.org/pzp/pzp-db.git
plugin.js knows less about feed-v1
This commit is contained in:
parent
babfd5e39f
commit
7e90efd48d
|
@ -16,6 +16,7 @@ const {
|
|||
validateBatch,
|
||||
validateMsgHash,
|
||||
} = require('./validation')
|
||||
const { isEmptyObject } = require('../utils')
|
||||
const Tangle = require('../tangle')
|
||||
|
||||
/**
|
||||
|
@ -91,6 +92,12 @@ const Tangle = require('../tangle')
|
|||
// return author.startsWith('ppppp:feed/v1/')
|
||||
// }
|
||||
|
||||
function isFeedRoot(msg, authorId, findType) {
|
||||
const findWho = stripAuthor(authorId)
|
||||
const { who, type, tangles } = msg.metadata
|
||||
return who === findWho && type === findType && isEmptyObject(tangles)
|
||||
}
|
||||
|
||||
function toPlaintextBuffer(opts) {
|
||||
return Buffer.from(stringify(opts.content), 'utf8')
|
||||
}
|
||||
|
@ -190,6 +197,7 @@ function fromPlaintextBuffer(plaintextBuf, msg) {
|
|||
module.exports = {
|
||||
getMsgHash,
|
||||
getMsgId,
|
||||
isFeedRoot,
|
||||
// getFeedId,
|
||||
// isFeedId,
|
||||
// isMsg,
|
||||
|
|
|
@ -13,7 +13,12 @@ function stripMsgKey(msgKey) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} id
|
||||
* @returns {string}
|
||||
*/
|
||||
function stripAuthor(id) {
|
||||
if (id.startsWith('ppppp:feed/v1/') === false) return id
|
||||
const withoutPrefix = id.replace('ppppp:feed/v1/', '')
|
||||
return withoutPrefix.split('/')[0]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ const promisify = require('promisify-4loc')
|
|||
const Obz = require('obz')
|
||||
const FeedV1 = require('./feed-v1')
|
||||
const Tangle = require('./tangle')
|
||||
const { ReadyGate, isEmptyObject } = require('./utils')
|
||||
const { ReadyGate } = require('./utils')
|
||||
const { decrypt } = require('./encryption')
|
||||
|
||||
/**
|
||||
|
@ -169,14 +169,8 @@ exports.init = function initDB(peer, config) {
|
|||
}
|
||||
|
||||
function getFeedRoot(findWho, findType) {
|
||||
const findWho_ = findWho.startsWith('ppppp:feed/v1/')
|
||||
? findWho.substring(16)
|
||||
: findWho
|
||||
for (const rec of records()) {
|
||||
const { who, type, tangles } = rec.msg.metadata
|
||||
if (who === findWho_ && type === findType && isEmptyObject(tangles)) {
|
||||
return rec.hash
|
||||
}
|
||||
if (FeedV1.isFeedRoot(rec.msg, findWho, findType)) return rec.hash
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -18,12 +18,11 @@ class ReadyGate {
|
|||
}
|
||||
}
|
||||
|
||||
function isEmptyObject(obj) {
|
||||
function isEmptyObject(obj) {
|
||||
for (const _key in obj) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = { ReadyGate, isEmptyObject }
|
||||
|
|
Loading…
Reference in New Issue