Skip to content

Commit

Permalink
fix(:cdn): the default domain name has not been replaced when using CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
yclgkd committed Sep 1, 2023
1 parent e49ce1a commit 7b1fa21
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 166 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ node_modules
dist
.DS_Store
.pnpm-debug.log*

1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lib
pnpm-lock.yaml
tsconfig.json
.npmignore
.husky
143 changes: 38 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ npm install strapi-provider-upload-tencent-cloud-storage --save
- SecretKey: Tencent Cloud API SecretKey
- Region: Tencent Cloud API Region
- Bucket: Tencent Cloud API Bucket
- ACL: (optional) ACL applied to the uploaded files. If you set it to `private` you will need to configure the [security middleware](#security-middleware-configuration) to properly see thumbnail previews in the Media Library.
- ACL: (optional) ACL applied to the uploaded files.
- Expires: (optional) Expiration time of the signed URL. Default value is 360 seconds (6 minutes).
- initOptions: (optional) Options passed to the constructor of the provider. You can find the complete list of [options here](https://cloud.tencent.com/document/product/436/8629#:~:text=%E5%8F%82%E8%A7%81%20demo%20%E7%A4%BA%E4%BE%8B%E3%80%82-,%E9%85%8D%E7%BD%AE%E9%A1%B9,-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0)
- uploadOptions: (optional) Options passed to the `upload` method. You can find the complete list of [options here](https://cloud.tencent.com/document/product/436/64980#.E7.AE.80.E5.8D.95.E4.B8.8A.E4.BC.A0.E5.AF.B9.E8.B1.A1)
- initOptions: (optional) Options passed to the constructor of the provider. You can find the complete list of [options here](https://cloud.tencent.com/document/product/436/8629#:~:text=%E5%8F%82%E8%A7%81%20demo%20%E7%A4%BA%E4%BE%8B%E3%80%82-,%E9%85%8D%E7%BD%AE%E9%A1%B9,-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0).
- uploadOptions: (optional) Options passed to the `upload` method. You can find the complete list of [options here](https://cloud.tencent.com/document/product/436/64980#.E7.AE.80.E5.8D.95.E4.B8.8A.E4.BC.A0.E5.AF.B9.E8.B1.A1).
- CDNDomain: (optional) CDN Accelerated Domain.
- StorageRootPath: (optional) The storage path of the file in the bucket.

See the [documentation about using a provider](https://docs.strapi.io/developer-docs/latest/plugins/upload.html#using-a-provider) for information on installing and using a provider. To understand how environment variables are used in Strapi, please refer to the [documentation about environment variables](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#environment-variables).

Expand All @@ -46,12 +48,12 @@ module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-tencent-cloud-storage',
provider: "strapi-provider-upload-tencent-cloud-storage",
providerOptions: {
SecretId: env('COS_SecretId'),
SecretKey: env('COS_SecretKey'),
Region: env('COS_Region'),
Bucket: env('COS_Bucket'),
SecretId: env("COS_SecretId"),
SecretKey: env("COS_SecretKey"),
Region: env("COS_Region"),
Bucket: env("COS_Bucket"),
},
},
},
Expand All @@ -63,6 +65,8 @@ module.exports = ({ env }) => ({

If your bucket is configured to be private, you will need to set the `ACL` option to `private` in the `params` object. This will ensure file URLs are signed.

**Note:** If you are using a CDN, the URLs will not be signed.

You can also define the expiration time of the signed URL by setting the `Expires` option in the `providerOptions` object. The default value is 360 seconds (6 minutes).

`./config/plugins.js` or `./config/plugins.ts` for TypeScript projects:
Expand All @@ -72,13 +76,13 @@ module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-tencent-cloud-storage',
provider: "strapi-provider-upload-tencent-cloud-storage",
providerOptions: {
SecretId: env('COS_SecretId'),
SecretKey: env('COS_SecretKey'),
Region: env('COS_Region'),
Bucket: env('COS_Bucket'),
ACL: 'private', // <= set ACL to private
SecretId: env("COS_SecretId"),
SecretKey: env("COS_SecretKey"),
Region: env("COS_Region"),
Bucket: env("COS_Bucket"),
ACL: "private", // <= set ACL to private
},
},
},
Expand All @@ -96,25 +100,25 @@ Due to the default settings in the Strapi Security Middleware you will need to m
module.exports = [
// ...
{
name: 'strapi::security',
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': [
"connect-src": ["'self'", "https:"],
"img-src": [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
'yourBucketName.cos.yourRegion.myqcloud.com',
"data:",
"blob:",
"market-assets.strapi.io",
"yourBucketName.cos.yourRegion.myqcloud.com",
],
'media-src': [
"media-src": [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
'yourBucketName.cos.yourRegion.myqcloud.com'
"data:",
"blob:",
"market-assets.strapi.io",
"yourBucketName.cos.yourRegion.myqcloud.com",
],
upgradeInsecureRequests: null,
},
Expand All @@ -125,78 +129,7 @@ module.exports = [
];
```

### Configure the access domain (CDN/global acceleration)

#### Default CDN Acceleration Domain

`./config/plugins.js` or `./config/plugins.ts` for TypeScript projects:

```js
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-tencent-cloud-storage',
providerOptions: {
Domain: '{Bucket}.file.myqcloud.com', // <= Custom acceleration domain name, the Domain parameter supports templates. In this example, {Bucket} will be automatically replaced with the provided Bucket during the request.
SecretId: env('COS_SecretId'),
SecretKey: env('COS_SecretKey'),
Region: env('COS_Region'),
Bucket: env('COS_Bucket'),
},
},
},
// ...
});
```

#### Custom CDN Acceleration Domain

`./config/plugins.js` or `./config/plugins.ts` for TypeScript projects:

```js
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-tencent-cloud-storage',
providerOptions: {
Domain: 'example-cdn-domain.com', // <= Custom Accelerated Domain
SecretId: env('COS_SecretId'),
SecretKey: env('COS_SecretKey'),
Region: env('COS_Region'),
Bucket: env('COS_Bucket'),
},
},
},
// ...
});
```

#### Custom Source Site Domain

`./config/plugins.js` or `./config/plugins.ts` for TypeScript projects:

```js
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-tencent-cloud-storage',
providerOptions: {
Domain: 'example-cos-domain.com', // <= Custom Source Site Domain
SecretId: env('COS_SecretId'),
SecretKey: env('COS_SecretKey'),
Region: env('COS_Region'),
Bucket: env('COS_Bucket'),
},
},
},
// ...
});
```

#### Global Accelerated Domain
### Configure the access domain (CDN acceleration)

`./config/plugins.js` or `./config/plugins.ts` for TypeScript projects:

Expand All @@ -205,20 +138,20 @@ module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'strapi-provider-upload-tencent-cloud-storage',
provider: "strapi-provider-upload-tencent-cloud-storage",
providerOptions: {
UseAccelerate: true,
SecretId: env('COS_SecretId'),
SecretKey: env('COS_SecretKey'),
Region: env('COS_Region'),
Bucket: env('COS_Bucket'),
CDNDomain: "example-cdn-domain.com", // <= CDN Accelerated Domain
SecretId: env("COS_SecretId"),
SecretKey: env("COS_SecretKey"),
Region: env("COS_Region"),
Bucket: env("COS_Bucket"),
},
},
},
// ...
});
```

### Contribution
## Contribution

Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!
Loading

0 comments on commit 7b1fa21

Please sign in to comment.