Skip to content

Commit

Permalink
🤖 Pull Request form develop (#96)
Browse files Browse the repository at this point in the history
* ✨ Update COS interface and provider

- Refactored COS interface and provider
- Updated import statements for clarity
- Improved handling of COS options

* 📰 Update CI

- Added changeset for patch update
- Updated workflow to trigger on pull requests
- Renamed job from 'Release' to 'Publish'

* feat(CI&CD): ✨ push new workflow

* ci(CI&CD): 🎡 cI

* feat(new feature): ✨ add ci

* ci(CI&CD): 🎡 cI

* feat(new feature): ✨ add sts support

* 📝 Update README with Tencent STS usage

- Added code snippets for using Tencent STS
- Updated README and README_ZH files

---------

Co-authored-by: guozichun <guotingchaopr@gmail.com>
  • Loading branch information
github-actions[bot] and guotingchao committed May 11, 2024
1 parent 84fb374 commit 4629cea
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-starfishes-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

Add STS support
5 changes: 5 additions & 0 deletions .changeset/few-insects-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

update workflow
5 changes: 5 additions & 0 deletions .changeset/funny-ties-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

update ci
5 changes: 5 additions & 0 deletions .changeset/khaki-cameras-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

change the options
5 changes: 5 additions & 0 deletions .changeset/lovely-horses-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

update CI
5 changes: 5 additions & 0 deletions .changeset/ninety-ducks-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

update readme
5 changes: 5 additions & 0 deletions .changeset/perfect-emus-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

update ci
5 changes: 5 additions & 0 deletions .changeset/wicked-bananas-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cardbrother/nestjs-tencent-cloud-sdk": patch
---

update ci
17 changes: 8 additions & 9 deletions .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,19 @@ jobs:
pnpm build
- name: 📣 Create Release Pull Request and Publish new version to Npm
id: changesets
id: publish
uses: changesets/action@v1.4.7
with:
publish: pnpm run publish:release
env:
GITHUB_TOKEN: ${{ env.PAT }}
NPM_TOKEN: ${{ env.NPM_TOKEN }}

- name: 🎺 Publish new version to Github Packages
id: publish
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ env.PAT }}
registry: "https://npm.pkg.github.com/guotingchao"
# - name: 🎺 Publish new version to Github Packages
# uses: JS-DevTools/npm-publish@v3
# with:
# token: ${{ env.PAT }}
# registry: "@cardbhttps://npm.pkg.github.com/guotingchao"

- if: ${{ steps.publish.outputs.type }}
run: echo "Version changed!"
# - if: ${{ steps.publish.outputs.type }}
# run: echo "Version changed!"
13 changes: 4 additions & 9 deletions src/@cardbrother/tencent-cloud-sdk/cos/cos.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import {
GetBucketResult,
GetObjectUrlParams,
GetObjectUrlResult,
StaticGetAuthorizationOptions,
UploadFileParams,
UploadFileResult,
} from 'cos-nodejs-sdk-v5';
import * as COS from 'cos-nodejs-sdk-v5';

import {
TencentCloudCosOptions,
TencentCloudModuleOptions,
} from '../tencent-cloud.interface';
import { TencentCloudModuleOptions } from '../tencent-cloud.interface';
export interface ICosProvider {
/**
* @name 上传文件
Expand Down Expand Up @@ -46,7 +42,7 @@ export interface ICosProvider {
* @param {params} StaticGetAuthorizationOptions - Cos配置
* @returns Authorization - 签名对象
*/
getAuthorization(options: TencentCloudCosOptions): Promise<string>;
getAuthorization(options: COS.StaticGetAuthorizationOptions): Promise<string>;

/**
* @name GetDownloadUrl
Expand All @@ -62,14 +58,13 @@ export interface ICosProvider {
* @description Cos抽象类
*/
export class CosAbstructClient {
public readonly baseCosOption: StaticGetAuthorizationOptions;
public readonly baseCosOption: COS.COSOptions;
protected readonly cosInstance: COS;
constructor(options: TencentCloudModuleOptions) {
this.baseCosOption = options.cos;
if (this.baseCosOption) {
this.cosInstance = new COS({
SecretId: this.baseCosOption.SecretId,
SecretKey: this.baseCosOption.SecretKey,
...this.baseCosOption,
});
} else console.warn('cos options is not defined in Module initlization');
}
Expand Down
7 changes: 4 additions & 3 deletions src/@cardbrother/tencent-cloud-sdk/cos/cos.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import COS, {
GetBucketResult,
GetObjectUrlParams,
GetObjectUrlResult,
StaticGetAuthorizationOptions,
UploadFileParams,
UploadFileResult,
} from 'cos-nodejs-sdk-v5';

import {
TENCENT_CLOUD_MODULE_OPTIONS_TOKEN,
TencentCloudCosOptions,
TencentCloudModuleOptions,
} from '../tencent-cloud.interface';
import { CosAbstructClient, ICosProvider } from './cos.interface';
Expand Down Expand Up @@ -47,10 +47,11 @@ export class CosProvider extends CosAbstructClient implements ICosProvider {
}

public async getAuthorization(
options: TencentCloudCosOptions,
options: Omit<StaticGetAuthorizationOptions, 'SecretId' | 'SecretKey'>,
): Promise<string> {
return await getAuthorization({
...this.baseCosOption,
SecretId: this.options.apiId,
SecretKey: this.options.apiSecret,
...options,
});
}
Expand Down
8 changes: 2 additions & 6 deletions src/@cardbrother/tencent-cloud-sdk/tencent-cloud.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ModuleMetadata, Type } from '@nestjs/common';
import { StaticGetAuthorizationOptions } from 'cos-nodejs-sdk-v5';
import COS from 'cos-nodejs-sdk-v5';
import { AbstractClient } from 'tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client';
import { ClientProfile } from 'tencentcloud-sdk-nodejs/tencentcloud/common/interface';

Expand Down Expand Up @@ -42,7 +42,7 @@ export interface TencentCloudModuleOptions {
region?: string;
global?: true;
profile?: ClientProfile;
cos?: StaticGetAuthorizationOptions;
cos?: COS.COSOptions;
}

/**
Expand Down Expand Up @@ -80,7 +80,3 @@ export interface ClientTypeToClassMap {
COS: CosProvider;
STS: StsProvider;
}

export type TencentCloudCosOptions = {
[P in 'SecretId' | 'SecretKey' | 'Region']?: StaticGetAuthorizationOptions[P];
} & Omit<StaticGetAuthorizationOptions, 'SecretId' | 'SecretKey' | 'Region'>;
55 changes: 27 additions & 28 deletions src/@cardbrother/tencent-cloud-sdk/tests/cos-client.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('@cardbrother/tencentCloudModule COS Test', () => {
cos: {
SecretId: tencent_cos_secretId,
SecretKey: tencent_cos_secretKey,
Region: 'eu-frankfurt',
},
}),
],
Expand All @@ -42,35 +41,35 @@ describe('@cardbrother/tencentCloudModule COS Test', () => {
const cosClient = await tencentCloudService.useClient('COS');
expect(cosClient).toBeDefined();
expect(cosClient).toEqual(expect.any(CosProvider));
const testOrignalPictureSource =
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const sign = await cosClient.getAuthorization({
Method: 'GET',
Key: testOrignalPictureSource,
Region: 'api-guangzhou',
Expires: 900, // 900 seconds
});
// const testOrignalPictureSource =
// 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
// const sign = await cosClient.getAuthorization({
// Method: 'GET',
// Key: testOrignalPictureSource,
// Region: 'api-guangzhou',
// Expires: 900, // 900 seconds
// });

const imgUrl = await cosClient.getDownloadUrl({
Bucket: 'test-1250000000',
Key: testOrignalPictureSource,
Region: 'api-guangzhou',
Sign: true,
});
// const imgUrl = await cosClient.getDownloadUrl({
// Bucket: 'test-1250000000',
// Key: testOrignalPictureSource,
// Region: 'api-guangzhou',
// Sign: true,
// });

console.debug('🐛🐛🐛 --------------------------------------------🐛🐛🐛');
console.debug(
'IMG URL: %s',
imgUrl.Url +
(imgUrl.Url.indexOf('?') > -1 ? '&' : '?') +
'response-content-disposition=inline',
);
console.debug(
'🐛🐛🐛 ::: Sign Url:::',
testOrignalPictureSource + `?${sign}&response-content-disposition=inline`,
);
console.debug('🐛🐛🐛 --------------------------------------------🐛🐛🐛');
// console.debug('🐛🐛🐛 --------------------------------------------🐛🐛🐛');
// console.debug(
// 'IMG URL: %s',
// imgUrl.Url +
// (imgUrl.Url.indexOf('?') > -1 ? '&' : '?') +
// 'response-content-disposition=inline',
// );
// console.debug(
// '🐛🐛🐛 ::: Sign Url:::',
// testOrignalPictureSource + `?${sign}&response-content-disposition=inline`,
// );
// console.debug('🐛🐛🐛 --------------------------------------------🐛🐛🐛');

expect(imgUrl).not.toBeNull();
// expect(imgUrl).not.toBeNull();
});
});

0 comments on commit 4629cea

Please sign in to comment.