6

我想创建一个microblog每个人都可以阅读所有帖子,但只有所有者可以删除或编辑帖子的地方。在gundb没有海的情况下,每个人都可以编辑或删除帖子,在sea( gun.user())我必须共享公钥,在海中我如何获取所有用户的帖子并在时间轴中显示帖子?

我怎么能用 gundb 创建这个?

4

3 回答 3

3

我一直在寻找有关数据隐私的问题的答案gun,这是我的答案:

  1. 变量的导入和定义
<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()
  1. 创建微博第一作者
gun.user().create('firstMicroblogAuthor', 'somePassword')
gun.user().auth('firstMicroblogAuthor', 'somePassword')

  1. 创建帖子并获取作者
var post = {
  title: 'First post',
  text: 'Hello world!'
}

var author = gun.get('~@firstMicroblogAuthor') // There should be the same `username` in Step 2
  1. 保存帖子
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
  })
  1. 检查我们的帖子是否受到其他用户的编辑保护:
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
  })
于 2019-09-17T09:48:40.307 回答
1

说 todo-dapp 是 public read user only write 是一种误导,它实际上并没有为您提供查看其他用户文档的能力。

事实上,我一直很恼火的是,实际上没有关于如何做到这一点的文档或示例,当你问开发人员时,你只会面临一次又一次的逃避。

数据库只有在有办法将用户关注点彼此分开时才有用

于 2019-07-12T11:01:11.413 回答
1

每次创建用户时,公钥都可以与所有其他用户共享。(有一个维护列表的超级用户)然后您的前端网站将遍历所有公钥以获取人们发布的所有帖子并显示它们。这样,人们可以阅读所有帖子,但不能编辑。另一种方法是让超级用户运行一个进程,不断索引并将帖子“复制”到他自己的图表中,并且该图表可以被查看。(使其受到更多保护)这是非常高级的答案,但所有这些都可以使用 gun.user() 和枪核心结构来实现。

于 2019-05-08T21:45:26.820 回答