mirror of https://codeberg.org/pzp/pzp-db.git
refactor: use initializeFeed() inside create()
This commit is contained in:
parent
9dd5f92ce8
commit
d39ee6b017
12
lib/index.js
12
lib/index.js
|
@ -237,16 +237,9 @@ exports.init = function initDB(peer, config) {
|
||||||
if (!opts.content) return cb(new Error('create() requires a `content`'))
|
if (!opts.content) return cb(new Error('create() requires a `content`'))
|
||||||
if (!opts.type) return cb(new Error('create() requires a `type`'))
|
if (!opts.type) return cb(new Error('create() requires a `type`'))
|
||||||
|
|
||||||
const feedRootHash = getFeedRoot(FeedV1.stripAuthor(keys.id), opts.type)
|
initializeFeed(opts, (err, feedRootHash) => {
|
||||||
if (!feedRootHash) {
|
|
||||||
const feedRoot = FeedV1.createRoot(keys, opts.type)
|
|
||||||
add(feedRoot, FeedV1.getMsgHash(feedRoot), (err) => {
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
if (err) return cb(new Error('create() failed to create root', {cause: err}));
|
if (err) return cb(new Error('create() failed to initialize feed', { cause: err }));
|
||||||
create(opts, cb)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill-in tangle opts:
|
// Fill-in tangle opts:
|
||||||
const tangleTemplates = opts.tangles ?? []
|
const tangleTemplates = opts.tangles ?? []
|
||||||
|
@ -290,6 +283,7 @@ exports.init = function initDB(peer, config) {
|
||||||
onRecordAdded.set(rec)
|
onRecordAdded.set(rec)
|
||||||
cb(null, rec)
|
cb(null, rec)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFeedRoot(authorId, findType) {
|
function getFeedRoot(authorId, findType) {
|
||||||
|
|
Loading…
Reference in New Issue