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 develop #96

Merged
merged 8 commits into from
May 11, 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/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();
});
});