我将 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) 这是我用来加密/解密数据的代码:
// 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) /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 …
我有一个枚举。我想使用其值为这些值成为键的对象创建类型。以下示例演示了我想要实现的目标:
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) 我需要从 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”标头存在于请求的资源。
但是在我重新加载页面(有时是几次,有时只是一次)之后,错误就消失了,我可以读取响应对象。
aes ×1
ajax ×1
amazon-s3 ×1
babeljs ×1
build ×1
core-js ×1
cors ×1
encryption ×1
firebase ×1
javascript ×1
php ×1
php-openssl ×1
typescript ×1