我想创建一个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
})
说 todo-dapp 是 public read user only write 是一种误导,它实际上并没有为您提供查看其他用户文档的能力。
事实上,我一直很恼火的是,实际上没有关于如何做到这一点的文档或示例,当你问开发人员时,你只会面临一次又一次的逃避。
数据库只有在有办法将用户关注点彼此分开时才有用
每次创建用户时,公钥都可以与所有其他用户共享。(有一个维护列表的超级用户)然后您的前端网站将遍历所有公钥以获取人们发布的所有帖子并显示它们。这样,人们可以阅读所有帖子,但不能编辑。另一种方法是让超级用户运行一个进程,不断索引并将帖子“复制”到他自己的图表中,并且该图表可以被查看。(使其受到更多保护)这是非常高级的答案,但所有这些都可以使用 gun.user() 和枪核心结构来实现。