小编Mic*_*dek的帖子

Firestore 引用创建“TypeError:将循环结构转换为 JSON”

我在 Vue JS 应用程序中使用 Firebase 的 Firestore:

"firebase": "^5.8.0",
"vue-firestore": "^0.3.16",
Run Code Online (Sandbox Code Playgroud)

当我尝试获取具有引用另一个文档(Firestore 中的引用类型)的字段的文档时,出现以下错误:

[Vue warn]: Error in render: "TypeError: Converting circular structure to JSON"
Run Code Online (Sandbox Code Playgroud)

每当我将文档中该字段的类型更改为字符串时,它似乎都可以正常工作。

我知道这是因为 Firestore JS SDK 中的某些内容试图将文档(以及文档附带的一堆元数据)序列化为 JSON,并且某处有循环引用?

在我的数据结构和字段中,我没有循环引用。它只是一个引用另一个文档的字段,并且被引用的文档不再引用任何其他文档。

我获取数据的代码是:

methods: {
      getContent() {
        const db = this.$firebase.firestore();
        db
          .collection('places')
          .doc(this.$route.params.placeKey)
          .orderBy('name')
          .get()
          .then(snap => {
            this.places = []

            snap.forEach(doc => {
              this.places.push(doc.data())
            })
          })
      }
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

1)首先,我在代码中做错了什么吗?即使没有引发错误,Firestore 的 JS SDK 会为我解析参考吗?或者我是否必须调用参考并自己解决以获取参考文档的数据?2) 当您有可以参考的文档时,Firestore 的最佳做法是什么?你应该使用引用吗?什么时候?你什么时候会非规范化?

谢谢!

firebase firebase-realtime-database vuefire google-cloud-firestore

4
推荐指数
1
解决办法
1651
查看次数

正则表达式在解释器中无法正常工作

我想搜索一个字符串并找到华氏温度单位并将它们转换成celcius.

要做到这一点,我的方法是让用户正则表达式在给定字符串中找到华氏温度单位,如果找到任何单位,请获取数字并将其转换为celcius.

这是我提出的正则表达式:

regexp = re.compile("\d+(.*?)(\bfahrenheit\b|\bf\b)", re.IGNORECASE)
Run Code Online (Sandbox Code Playgroud)

这是正则表达式.

在Pythex网站上似乎工作正常,但是,在我的翻译中,相同的正则表达式与任何东西都不匹配.

有什么建议?

python regex python-2.7

3
推荐指数
1
解决办法
198
查看次数

生产中的Blobstore没有得到BlobKey(而在dev_appserver中它确实如此)

我有一个流程可以从给定的网址中提取图片并将其保存到Google云端存储并检索服务网址.现在,我的理解(从我读过的文档中)是我还必须在引用GCS文件的过程中创建一个blob.如果我的理解不正确,请告诉我.

获取图像并尝试保存图像的处理程序是:

img_request = urlfetch.fetch(img_url)
    if img_request.status_code == 200:
        img_title               = hashlib.sha1(img_url).hexdigest()
        img_content             = img_request.content
        img_type                = img_request.headers['content-type']
        cloud_storage_filename  = '/images/%s/%s' % (self.source_name, img_title)

        blobstore_filename      = '/gs%s' % cloud_storage_filename
        blobstore_key           = blobstore.create_gs_key(blobstore_filename)

        cloud_storage_file      = gcs.open(filename=cloud_storage_filename, mode='w', content_type=img_type)
        cloud_storage_file.write(img_content)
        cloud_storage_file.close()

        # If I print blobstore_key at this stage, I am getting a result here.
        blobstore_key           = blobstore.get(blobstore_key).key()
        blobstore_serving_url   = images.get_serving_url(blobstore_key)

        # Structured Property to be part of a Datastore Model
        img_model = data_model.Image(
            s_source_url    = img_url,
            k_blob_key      = blobstore_key,
            s_serving_url   = …
Run Code Online (Sandbox Code Playgroud)

google-app-engine blobstore python-2.7 google-cloud-storage

3
推荐指数
1
解决办法
896
查看次数

未与 Cloud Functions 和 Firestore 建立连接

我在从云功能连接到我的 Firestore 数据库时遇到问题。

我收到以下错误:

i  functions: Beginning execution of "test"
>  Error: 14 UNAVAILABLE: No connection established
>      at Object.callErrorFromStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
>      at Object.onReceiveStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/client.js:174:52)
>      at Object.onReceiveStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:340:141)
>      at Object.onReceiveStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:303:181)
>      at Http2CallStream.outputStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:114:27)
>      at Http2CallStream.maybeOutputStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:153:22)
>      at Http2CallStream.endCall (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)
>      at Http2CallStream.cancelWithStatus (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:430:14)
>      at ChannelImplementation.tryPick (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/channel.js:214:32)
>      at Object.updateState (/Users/michael/project/functions/node_modules/@grpc/grpc-js/build/src/channel.js:82:26) {
>    code: 14,
>    details: 'No connection established',
>    metadata: Metadata { internalRepr: Map {}, options: {} }
>  }
Run Code Online (Sandbox Code Playgroud)

服务帐户凭据由GOOGLE_APPLICATION_CREDENTIALS …

node.js firebase google-cloud-functions google-cloud-firestore

3
推荐指数
1
解决办法
932
查看次数

密码盐和秘密

因此,在构建webapp并存储密码时,安全性和性能都是要记住的重要事项.由于GPU的速度越来越快,我们已经看到即使盐析SHA1密码也很容易被破解的证据,我想知道存储密码的最佳做法是什么.

我认为,为了增加存储密码的安全性,你可以为salt添加一个秘密.所以例如,这个的python代码可能是:

import hashlib
import hmac

secret = 'XYZ'
h = hmac.new('salt' + secret, 'password')
Run Code Online (Sandbox Code Playgroud)
  • 这是常见的事吗?
  • 这有什么缺点?
  • 这个领域的最佳实践是什么?

PS我没有在安全论坛上发布这个,因为我想要一个webapp开发人员的观点.

python security passwords performance google-app-engine

1
推荐指数
1
解决办法
1602
查看次数