@celljs/cloud 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.zh-cn.md +49 -0
- package/package.json +2 -2
package/README.zh-cn.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Cell - 云组件
|
|
2
|
+
|
|
3
|
+
云包的共享抽象:凭据、区域和账户的来源,以及 [`@celljs/oss`](../oss) 和 [`@celljs/cos`](../cos) 实现的 `ObjectStorageService` 接口。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @celljs/cloud
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 凭据、区域、账户
|
|
10
|
+
|
|
11
|
+
| 组件 | 默认来源 |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `CredentialsProvider` | `cloud.credentials`:`{ accessKeyId, accessKeySecret, token? }` |
|
|
14
|
+
| `RegionProvider` | `cloud.region` |
|
|
15
|
+
| `AccountProvider` | `cloud.account`:`{ id }` |
|
|
16
|
+
| `ClientOptionsProvider` | `cloud.client`:云商客户端的额外选项 |
|
|
17
|
+
|
|
18
|
+
```yaml
|
|
19
|
+
cloud:
|
|
20
|
+
region: cn-hangzhou
|
|
21
|
+
credentials:
|
|
22
|
+
accessKeyId: "${env.ACCESS_KEY_ID}"
|
|
23
|
+
accessKeySecret: "${env.ACCESS_KEY_SECRET}"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
将凭据保存在环境变量中(`cell.yml` 中的 `${env.X}`);配置仅在服务端。绑定自己的 provider(`rebind: true`)从其他地方读取它们,如密钥管理系统。
|
|
27
|
+
|
|
28
|
+
## 对象存储
|
|
29
|
+
|
|
30
|
+
`ObjectStorageService` 有 `createBucket`、`deleteBucket`、`listBuckets`、`listObjects`、`getObject`、`getStream`、`putObject`、`copyObject`、`deleteObject` 和 `headObject`,对每个云商的请求形状相同:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Autowired, Component } from '@celljs/core';
|
|
34
|
+
import { ObjectStorageService } from '@celljs/cloud';
|
|
35
|
+
|
|
36
|
+
@Component()
|
|
37
|
+
export class Uploads {
|
|
38
|
+
@Autowired(ObjectStorageService)
|
|
39
|
+
protected readonly storage: ObjectStorageService<any>;
|
|
40
|
+
|
|
41
|
+
save(key: string, body: Buffer) {
|
|
42
|
+
return this.storage.putObject({ bucket: 'uploads', key, body });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
安装一个实现:`@celljs/oss`(阿里云)或 `@celljs/cos`(腾讯云)。`getRawCloudService()` 返回云商自有的客户端用于其他操作。
|
|
48
|
+
|
|
49
|
+
部署应用到云平台不需要这个包:见 `cell deploy` 的 preset。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/cloud",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@celljs/core": "4.
|
|
35
|
+
"@celljs/core": "4.7.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|