Skip to content

Commit

Permalink
docs: update the README
Browse files Browse the repository at this point in the history
  • Loading branch information
yclgkd committed Aug 18, 2023
1 parent 09c598e commit e49ce1a
Show file tree
Hide file tree
Showing 6 changed files with 8,706 additions and 3,057 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm exec lint-staged
226 changes: 224 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,224 @@
# strapi-v4-provider-cos
Tencent Cloud COS storage provider designed specifically for Strapi v4. Simplifies the integration of Tencent Cloud COS as a file storage solution within Strapi v4.
# strapi-provider-upload-tencent-cloud-storage

## Resources

- [LICENSE](LICENSE)

## Links

- [Strapi website](https://strapi.io/)
- [Strapi documentation](https://docs.strapi.io)
- [Strapi community on Discord](https://discord.strapi.io)
- [Strapi news on Twitter](https://twitter.com/strapijs)

## Installation

```bash
# using yarn
yarn add strapi-provider-upload-tencent-cloud-storage

# using npm
npm install strapi-provider-upload-tencent-cloud-storage --save
```

## Configuration

- `provider` defines the name of the provider
- `providerOptions` is passed down during the construction of the provider. It contains the following properties:

- SecretId: Tencent Cloud API SecretId
- 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.
- 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)

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).

### Provider Configuration

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

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

### Configuration for a private COS bucket and signed URLs

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.

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:

```js
module.exports = ({ env }) => ({
// ...
upload: {
config: {
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
},
},
},
// ...
});
```

### Security Middleware Configuration

Due to the default settings in the Strapi Security Middleware you will need to modify the `contentSecurityPolicy` settings to properly see thumbnail previews in the Media Library. You should replace `strapi::security` string with the object bellow instead as explained in the [middleware configuration](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/middlewares.html#loading-order) documentation.

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

```js
module.exports = [
// ...
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
'yourBucketName.cos.yourRegion.myqcloud.com',
],
'media-src': [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
'yourBucketName.cos.yourRegion.myqcloud.com'
],
upgradeInsecureRequests: null,
},
},
},
},
// ...
];
```

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

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

```js
module.exports = ({ env }) => ({
// ...
upload: {
config: {
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'),
},
},
},
// ...
});
```

### Contribution

Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const log = (...args: any) => {

export = {
init(config: ConfigOptions) {
const {SecretId, SecretKey, Bucket, Region, ACL = 'default', Expires = 3600} = config
const {SecretId, SecretKey, Bucket, Region, ACL = 'default', Expires = 360} = config
const COSInitConfig = {
SecretId,
SecretKey,
Expand Down
29 changes: 26 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"name": "strapi-provider-upload-tencent-cloud-storage",
"version": "1.1.1",
"version": "1.1.2",
"description": "A integration of Tencent Cloud COS as a file storage solution within Strapi.",
"main": "dist/index.js",
"directories": {
"lib": "./lib"
},
"scripts": {
"build": "tsc"
"cz": "cz",
"format": "prettier --write --ignore-unknown",
"build": "tsc",
"prepare": "husky install",
"preinstall": "npx only-allow pnpm -y"
},
"repository": {
"type": "git",
Expand All @@ -19,16 +23,27 @@
"tencent-cos",
"cos",
"strapi-provider",
"strapi-provider-upload",
"object-storage"
],
"author": "Brian Yao",
"author": {
"name": "Brian Yao",
"email": "[email protected]"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/yclgkd/strapi-provider-upload-tencent-cloud-storage/issues"
},
"homepage": "https://github.com/yclgkd/strapi-provider-upload-tencent-cloud-storage#readme",
"devDependencies": {
"@commitlint/cli": "^17.7.0",
"@commitlint/config-conventional": "^17.7.0",
"@types/node": "^20.5.0",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.0",
"prettier": "3.0.2",
"typescript": "^5.1.6"
},
"dependencies": {
Expand All @@ -45,5 +60,13 @@
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}
Loading

0 comments on commit e49ce1a

Please sign in to comment.