Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request form Github Actions #42

Merged
merged 5 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nervous-weeks-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

upgrade readme
17 changes: 8 additions & 9 deletions .github/workflows/Test.yml → .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🧪 Test
name: 🧪 CI
on:
push:
branches:
Expand All @@ -10,8 +10,9 @@ defaults:
shell: bash

jobs:
test:
name: Test
CI:
name: CI
if: ${{ github.repository_owner == 'guotingchao' }}
runs-on: ubuntu-latest
steps:
- name: 🟢 Setup node
Expand Down Expand Up @@ -50,15 +51,13 @@ jobs:
id: install-dependencies
run: pnpm install

- name: Test
- name: 🧪 Test
run: pnpm run test

- name: Reset promotion branch
run: |
git fetch origin main:main
git reset --hard main
- name: 📦 Build
run: pnpm run build

- name: Create Pull Request
- name: 🦋 Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ on:
push:
branches:
- main

# concurrency: ${{ github.workflow }}-${{ github.ref }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
release:
name: 🚀 Release
# strategy:
# matrix:
# os: [ubuntu-latest]
# node-version: [lts/*]
# pnpm-version: [latest]
if: ${{ github.repository_owner == 'guotingchao' }}
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout
Expand Down Expand Up @@ -67,8 +60,8 @@ jobs:
uses: changesets/action@v1.4.7
with:
title: "chore(release): version packages 🦋"
publish: pnpm publish
version: pnpm version
publish: pnpm run publish
version: pnpm run version
commit: "chore(release): version packages 🦋 [skip ci]"
env:
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
Expand Down
123 changes: 96 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
# @cardbrother/nestjs-tencent-cloud-sdk
<h1 align="center">@cardbrother/nestjs-tencent-cloud-sdk</h1>

---

[![Test](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Test.yml/badge.svg)](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Test.yml)

[![Release & Publish](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Release.yml/badge.svg)](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Release.yml)

[![package version](https://badge.fury.io/js/@cardbrother%2Fnestjs-tencent-cloud-sdk.svg)](https://badge.fury.io/js/@cardbrother%2Fnestjs-tencent-cloud-sdk)
[![CI](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Test.yml/badge.svg)](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Test.yml) [![Release & Publish](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Release.yml/badge.svg)](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Release.yml) [![package version](https://badge.fury.io/js/@cardbrother%2Fnestjs-tencent-cloud-sdk.svg)](https://badge.fury.io/js/@cardbrother%2Fnestjs-tencent-cloud-sdk) ![NPM Downloads](https://img.shields.io/npm/d18m/%40cardbrother%2Fnestjs-tencent-cloud-sdk) ![GitHub language count](https://img.shields.io/github/languages/count/guotingchao/nest-tencent-cloud-sdk?color=green)![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/t/guotingchao/nest-tencent-cloud-sdk/main?logo=github&logoColor=green&color=%23FF40E0D0)
![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/t/guotingchao/nest-tencent-cloud-sdk/develop?logo=github&logoColor=green&label=Develop%20Commits&color=%23FF40E0D0)

### Description

---
Language: [English](README.md) | [中文](README_ZH.md)

> Tencent Cloud SDK for NestJS Developers

- Use pnpm or bun
- Zero config
- support all Tencent Cloud API
- supoort latest version of Tencent Cloud API

### Installation
## 🔨 Installation

- npm

```bash
$ npm install @cardbrother/nest-tencent-cloud-sdk
npm install @cardbrother/nest-tencent-cloud-sdk
```

- yarn
Expand All @@ -33,15 +21,17 @@ $ npm install @cardbrother/nest-tencent-cloud-sdk
$ yarn add @cardbrother/nest-tencent-cloud-sdk
```

- pnpm 🚀 **Recommended**
- 🚀 pnpm **Recommended**

```bash
$ pnpm add @cardbrother/nest-tencent-cloud-sdk
```

### Usage
## 🍚 Usage

##### TencentCloud SDK
> In your `AppModule`or `FeatureModule` module, import the `TencentCloudModule` and call the `forRoot` method to configure the Tencent Cloud SDK with your `secretId` and `secretKey`:

#### **Basic usage:**

```ts
import { Module } from '@nestjs/common';
Expand All @@ -50,21 +40,100 @@ import { TencentCloudModule } from '@cardbrother/nest-tencent-cloud-sdk';
@Module({
imports: [
TencentCloudModule.forRoot({
secretId: 'your secretId',
secretKey,
global: true, // false by default
apiId: 'TENCENT_API_ID',
apiSecret: 'TENCENT_API_SECRET',
region: 'TENCENT_REGION',
cos: {
Bucket: 'COS_BUCKET',
Region: 'COS_REGION',
SecretId: 'COS_SECRET_ID',
SecretKey: 'COS_SECRET_KEY',
},
global: true, // if true, the TencentCloudService will be a global service, default is false
}),
],
})
export class AppModule {}
```

---

#### **Dynamic useage**

> If you want to use a dynamic configuration, you can use the `forRootAsync` method to configure the Tencent Cloud SDK with your `secretId` and `secretKey`:

```ts
import { TencentCloudModule } from '@cardbrother/nestjs-tencent-cloud-sdk';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
TencentCloudModule.forRootAsync({
useFactory: async (configService: ConfigService) => ({
apiId: configService.get<string>('TENCENT_API_ID'),
apiSecret: configService.get<string>('TENCENT_API_SECRET'),
region: configService.get<string>('TENCENT_REGION', 'ap-shanghai'),
cos: {
Bucket: configService.get<string>('COS_BUCKET'),
Region: configService.get<string>('COS_REGION'),
SecretId: configService.get<string>('COS_SECRET_ID'),
SecretKey: configService.get<string>('COS_SECRET_KEY'),
},
global: true, // if true, the TencentCloudService will be a global service, default is false
}),
imports: [ConfigModule],
inject: [ConfigService],
global: true,
}),
],
})
export class AppModule {}
```

###### TencentCloud COS SDK
#### **Use TencentCloudService**

```ts
import { Injectable } from '@nestjs/common';
import { TencentCloudService } from '@cardbrother/nest-tencent-cloud-sdk';

@Injectable()
export class AppService {
constructor(
private readonly tencentCloudService: TencentCloudService,
@Inject(TENCENT_CLOUD_MODULE_OPTIONS_TOKEN)
private readonly options: TencentCloudModuleOptions, // If u want to get the options u can use this
) {}

// imgData is a base64 string
async useOCR(imgData: string) {
// Here the encapsulated object is dynamically instantiated based on the enumeration
const ocrClient = await this.tencentCloudService.useClient('OCR'); // or SMS,COS,etc
return ocrClient.fastOcr({
ImageBase64: imgData,
});
}
}
```

#### **Usage Tencent COS**

> 💡 Tips: If you pass Bucket, Region, or any parameter here it overrides the configuration at the time of imported module the reference, if you don't pass it then the import `TencentCloudModule.forRoot` configuration is used.

```ts
const cosClient = await this.tencentCloudService.useClient('COS');
cosClient.upload({
Bucket: this.options.cos.Bucket, // It's not required. Default use the configuration at the Module Import time
Region: this.options.cos.Region, // It's not required. Default use the configuration at the Module Import time
Key: 'test.txt',
Body: 'hello world',
FilePath: 'test.txt',
});
```

### [CHANGELOG](https://github.com/guotingchao/nest-tencent-cloud-sdk/blob/main/CHANGELOG.md)
#### 📝 [CHANGELOG](CHANGELOG.md)

### License [MIT](https://github.com/guotingchao/nest-tencent-cloud-sdk/blob/main/LICENSE)
#### License [MIT](https://github.com/guotingchao/nest-tencent-cloud-sdk/blob/main/LICENSE)
139 changes: 139 additions & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<h1 align="center">@cardbrother/nestjs-tencent-cloud-sdk</h1>

[![CI](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Test.yml/badge.svg)](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Test.yml) [![Release & Publish](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Release.yml/badge.svg)](https://github.com/guotingchao/nest-tencent-cloud-sdk/actions/workflows/Release.yml) [![package version](https://badge.fury.io/js/@cardbrother%2Fnestjs-tencent-cloud-sdk.svg)](https://badge.fury.io/js/@cardbrother%2Fnestjs-tencent-cloud-sdk) ![NPM Downloads](https://img.shields.io/npm/d18m/%40cardbrother%2Fnestjs-tencent-cloud-sdk) ![GitHub language count](https://img.shields.io/github/languages/count/guotingchao/nest-tencent-cloud-sdk?color=green)![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/t/guotingchao/nest-tencent-cloud-sdk/main?logo=github&logoColor=green&color=%23FF40E0D0)
![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/t/guotingchao/nest-tencent-cloud-sdk/develop?logo=github&logoColor=green&label=Develop%20Commits&color=%23FF40E0D0)

Language: [English](README.md) | [中文](README_ZH.md)

> 腾讯云 SDK 适用于 NestJS 开发者

## 🔨 安装

- npm

```bash
npm install @cardbrother/nest-tencent-cloud-sdk
```

- yarn

```bash
$ yarn add @cardbrother/nest-tencent-cloud-sdk
```

- 🚀 pnpm **推荐**

```bash
$ pnpm add @cardbrother/nest-tencent-cloud-sdk
```

## 🍚 使用

> 在 `AppModule` 或 `FeatureModule` 模块中,导入 `TencentCloudModule` 并调用 `forRoot` 方法配置 Tencent Cloud SDK 的 `secretId` 和 `secretKey`:

#### **基础使用:**

```ts
import { Module } from '@nestjs/common';
import { TencentCloudModule } from '@cardbrother/nest-tencent-cloud-sdk';

@Module({
imports: [
TencentCloudModule.forRoot({
apiId: 'TENCENT_API_ID',
apiSecret: 'TENCENT_API_SECRET',
region: 'TENCENT_REGION',
cos: {
Bucket: 'COS_BUCKET',
Region: 'COS_REGION',
SecretId: 'COS_SECRET_ID',
SecretKey: 'COS_SECRET_KEY',
},
global: true, // 如果为 true,则 TencentCloudService 将是全局服务,默认为 false
}),
],
})
export class AppModule {}
```

---

#### **动态模块导入**

> 如果您想使用动态配置,可以使用 `forRootAsync` 方法将您的 `secretId` 和 `secretKey` 配置为腾讯云 SDK:

```ts
import { TencentCloudModule } from '@cardbrother/nestjs-tencent-cloud-sdk';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
TencentCloudModule.forRootAsync({
useFactory: async (configService: ConfigService) => ({
apiId: configService.get<string>('TENCENT_API_ID'),
apiSecret: configService.get<string>('TENCENT_API_SECRET'),
region: configService.get<string>('TENCENT_REGION', 'ap-shanghai'),
cos: {
Bucket: configService.get<string>('COS_BUCKET'),
Region: configService.get<string>('COS_REGION'),
SecretId: configService.get<string>('COS_SECRET_ID'),
SecretKey: configService.get<string>('COS_SECRET_KEY'),
},
global: true, // 如果为 true,则 TencentCloudService 将是全局服务,默认为 false
}),
imports: [ConfigModule],
inject: [ConfigService],
global: true,
}),
],
})
export class AppModule {}
```

#### **使用 TencentCloudService**

```ts
import { Injectable } from '@nestjs/common';
import { TencentCloudService } from '@cardbrother/nest-tencent-cloud-sdk';

@Injectable()
export class AppService {
constructor(
private readonly tencentCloudService: TencentCloudService,
@Inject(TENCENT_CLOUD_MODULE_OPTIONS_TOKEN)
private readonly options: TencentCloudModuleOptions, // 如果您想获取选项,可以使用这个
) {}

// 使用 OCR 服务
async useOCR(imgData: string) {
// 封装对象是智能的根据枚举动态实例化的
const ocrClient = await this.tencentCloudService.useClient('OCR'); // or SMS,COS,etc
return ocrClient.fastOcr({
ImageBase64: imgData,
});
}
}
```

#### **使用 Tencent COS**

> 💡 提示:如果在此处传递 Bucket、Region 或任何参数,则会覆盖导入模块时的配置;如果不传递,则会使用导入的 `TencentCloudModule.forRoot` 配置。

```ts
const cosClient = await this.tencentCloudService.useClient('COS');
cosClient.upload({
Bucket: this.options.cos.Bucket, // It's not required. Default use the configuration at the Module Import time
Region: this.options.cos.Region, // It's not required. Default use the configuration at the Module Import time
Key: 'test.txt',
Body: 'hello world',
FilePath: 'test.txt',
});
```

#### 📝 [CHANGELOG](CHANGELOG.md)

#### License [MIT](https://github.com/guotingchao/nest-tencent-cloud-sdk/blob/main/LICENSE)