我想创建一个 microblog
每个人都可以阅读所有帖子,但只有所有者可以删除或编辑帖子。在 gundb
无海人人可以编辑或删除帖子,在sea( gun.user())
我必须共享公钥,在海上如何获取所有用户的帖子并在时间轴中显示帖子?
我怎么能用 gundb 创建这个?
最佳答案
我一直在 gun
中寻找有关数据隐私问题的答案,这是我的答案:
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
var gun = Gun()
gun.user().create('firstMicroblogAuthor', 'somePassword')
gun.user().auth('firstMicroblogAuthor', 'somePassword')
var post = {
title: 'First post',
text: 'Hello world!'
}
var author = gun.get('~@firstMicroblogAuthor') // There should be the same `username` in Step 2
gun
.user()
.get('posts')
.set(post) // At this step, we saved the post in a user schedule, which by default is only writable by the user
.once(function() {
this.get('author').put(author) // In this step, we link our post with the author (with our user)
gun.get('posts').set(this) // At this step, we save the post with the author installed in the main graph
})
gun.user().leave()
gun.user().create('secondMicroblogAuthor', 'somePassword')
gun.user().auth('secondMicroblogAuthor', 'somePassword')
gun
.get('posts') // Read posts from public graph
.once(function() {
this.get('text').put('Goodbye world!') // In this case, we will get an error, because this post was protected
})
关于gun - gundb中的私有(private)写入和公共(public)读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56044288/