小编wub*_*ube的帖子

将 @babel/preset-env 与 useBuiltIns:'usage' 一起使用时,是否需要导入 core-js/stable 和 regenerator-runtime/runtime?

我将 babel7.8.3@babel/preset-env,useBuiltIns: 'usage'和一起使用corejs: 3@babel/preset-env我不清楚的文档。

我需要在我的入口文件顶部添加以下几行还是由 babel 自动完成?

import 'core-js/stable';
import 'regenerator-runtime/runtime';
Run Code Online (Sandbox Code Playgroud)

build babeljs babel-preset-env core-js

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

openssl_encrypt()随机失败 - IV传递的只有$ {x}个字节长,cipher期望一个精确到16字节的IV

这是我用来加密/解密数据的代码:

// Set the method
$method = 'AES-128-CBC';

// Set the encryption key
$encryption_key = 'myencryptionkey';

// Generet a random initialisation vector
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));

// Define the date to be encrypted
$data = "Encrypt me, please!";

var_dump("Before encryption: $data");

// Encrypt the data
$encrypted = openssl_encrypt($data, $method, $encryption_key, 0, $iv);

var_dump("Encrypted: ${encrypted}");

// Append the vector at the end of the encrypted string
$encrypted = $encrypted . ':' . $iv;

// Explode the string using the `:` separator.
$parts …
Run Code Online (Sandbox Code Playgroud)

php encryption aes encryption-symmetric php-openssl

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

无法在 Firebase Firestore 安全规则中使用逻辑 OR 运算符 - 条件始终评估为“false”

/companies/{company}如果登录用户是经理记录不存在,我想允许写入。

我有以下安全规则:

service cloud.firestore {
  match /databases/{database}/documents {
    function isManager() {
      return get(/databases/$(database)/documents/managers/$(request.auth.uid)).data.id == request.auth.uid;
    }

    function companyExists(company) {
      return exists(/databases/$(database)/documents/companies/$(company));
    }

    match /{document=**} {
      allow read, write: if false;
    }

    match /companies/{company} {
      allow read: if resource.data.isActive == true || isManager();
      allow write: if !companyExists(company) || isManager();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

以下行有问题:

allow write: if !companyExists(company) || isManager();
Run Code Online (Sandbox Code Playgroud)

false即使!companyExists(company)函数计算结果为 ,此条件也始终计算为true

我确信companyExists(company)isManager()函数可以按预期工作,因为我已经分别测试了它们。

例如,如果我使用以下规则:

allow write: if !companyExists(company);
Run Code Online (Sandbox Code Playgroud)

然后,表达式的计算结果true …

firebase firebase-security google-cloud-firestore

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

TypeScript:基于来自枚举的对象键进行键入

我有一个枚举。我想使用其值为这些值成为键的对象创建类型。以下示例演示了我想要实现的目标:

export enum MyEnum {
  PROP_1 = "prop 1",
  PROP_2 = "prop 2",
  // ... more props
}

export interface MyInterface {
  property: {
    "prop 1": boolean,
    "prop 2": boolean,
    // ... more props
  }
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我想避免在接口中重复枚举的所有属性。

是否可以做类似的事情:

export enum MyEnum {
  PROP_1 = "prop 1",
  PROP_2 = "prop 2",
  // ... more props
}

// PSEUDOCODE!
export interface MyInterface {
  property: {
    [values from MyEnum]: boolean
  }
}
Run Code Online (Sandbox Code Playgroud)

更新:

感谢@jcalz提供解决方案:

enum MyEnum {
  PROP_1 = "prop 1",
  PROP_2 = …
Run Code Online (Sandbox Code Playgroud)

typescript typescript-typings

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

跨域请求到 AWS S3 的 AJAX 请求有时会导致 CORS 错误

我需要从 S3 检索一些可公开访问的文件。

这是我的 S3 CORS 配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)

这是我的 JS 代码:

const response = await fetch(url, {
    mode: 'cors',
});

const blob = await response.blob();
Run Code Online (Sandbox Code Playgroud)

它有效,但并非总是如此。有时我在控制台中出现以下错误:

从源“ https://my.host ”访问“ https://my-bycketuel/file.jpg ”的XMLHttpRequest已被 CORS 策略阻止:没有“Access-Control-Allow-Origin”标头存在于请求的资源。

但是在我重新加载页面(有时是几次,有时只是一次)之后,错误就消失了,我可以读取响应对象。

javascript ajax amazon-s3 amazon-web-services cors

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