Skip to content

Commit

Permalink
New configuration for Strapi V4 with migration guide
Browse files Browse the repository at this point in the history
Signed-off-by: Vanessa Pasque (Lith) <lith@amykron.com>
  • Loading branch information
Lith committed Dec 1, 2021
1 parent a7a8c8f commit ac9907a
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 517 deletions.
18 changes: 18 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Migration Guide

Please be careful and save all of your datas before beginning the migration.

### Follow official migration guide of Strapi

_Work in progress_, not available yet`

### Update `provider` field in `files` table

This action will be necessary if you want to delete old files imported in Strapi V3, later.

```mysql
UPDATE `files` SET `provider` = 'strapi-provider-upload-google-cloud-storage' WHERE `provider` = 'google-cloud-storage';
```

/!\ Be careful, this migration guide is not finished yet. /!\

89 changes: 55 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ This works only for deployment to GCP products such as App Engine, Cloud Run, an

Edit `./config/plugins.js`

```javascript
```js
module.exports = {
upload: {
provider: 'google-cloud-storage',
config: {
provider: 'strapi-provider-upload-google-cloud-storage',
providerOptions: {
bucketName: '#bucketName#',
publicFiles: false,
uniform: false,
basePath: '',
},
},
},
//...
}
Expand All @@ -82,10 +84,11 @@ module.exports = {

Edit `./config/plugins.js`

```javascript
```js
module.exports = {
upload: {
provider: 'google-cloud-storage',
config: {
provider: 'strapi-provider-upload-google-cloud-storage',
providerOptions: {
bucketName: '#bucketName#',
publicFiles: true,
Expand All @@ -95,6 +98,7 @@ module.exports = {
basePath: '',
},
},
},
//...
}
```
Expand All @@ -107,17 +111,19 @@ This file, under `config/env/{env}/` will be overriding default configuration pr

**Example with environment variable**

```javascript
```js
module.exports = ({ env }) => ({
upload: {
provider: 'google-cloud-storage',
providerOptions: {
serviceAccount: env.json('GCS_SERVICE_ACCOUNT'),
bucketName: env('GCS_BUCKET_NAME'),
basePath: env('GCS_BASE_PATH'),
baseUrl: env('GCS_BASE_URL'),
publicFiles: env.bool('GCS_PUBLIC_FILES'),
uniform: env.bool('GCS_UNIFORM'),
config: {
provider: 'strapi-provider-upload-google-cloud-storage',
providerOptions: {
serviceAccount: env.json('GCS_SERVICE_ACCOUNT'),
bucketName: env('GCS_BUCKET_NAME'),
basePath: env('GCS_BASE_PATH'),
baseUrl: env('GCS_BASE_URL'),
publicFiles: env('GCS_PUBLIC_FILES'),
uniform: env('GCS_UNIFORM'),
},
},
},
//...
Expand All @@ -126,6 +132,38 @@ module.exports = ({ env }) => ({

Environment variable can be changed has your way.

## Setting up `strapi::security` middlewares to avoid CSP blocked url

Edit `./config/middlewares.js`
- In the field `img-src` and `media-src` add your own CDN url, by default it's `storage.googleapis.com` but you need to add your own CDN url

```js
module.exports = [
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'storage.googleapis.com'],
'media-src': ["'self'", 'data:', 'blob:', 'storage.googleapis.com'],
upgradeInsecureRequests: null,
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::favicon',
'strapi::public',
];
```

## How to configure variable ?

#### `serviceAccount` :
Expand Down Expand Up @@ -225,27 +263,6 @@ Example:
},
```

### `getContentType`:

Function that is executed to get the content type of the uploaded file.

When no function is provided, the default content type of the file (`file.mime` is used).

- Default value: `undefined`
- Optional

Example:

```js
getContentType: (file) => {
switch ((file && file.ext || '').toLowerCase()) {
case '.avif':
return 'image/avif';
default:
return file.mime;
}
},
```

## FAQ

Expand All @@ -268,6 +285,10 @@ Follow this step :
- Copy the full content of the file
- Paste it under the variable `ServiceAccount` in `plugins.js` config file in JSON

## Migration

Due to release of Strapi v4, you need to migrate your databases files informations.
Follow our [migration guide](./MIGRATION_GUIDE.md).

## Links

Expand Down
18 changes: 11 additions & 7 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Security Policy

Strapi V4 is now release, please use release >= 4.0.0
For old version, please refer to older release.

## Supported Versions

| Version | Supported |
| ------- | ------------------ |
| 3.6.8 | :white_check_mark: |
| 3.6.5 | :white_check_mark: |
| 3.6.3 | :white_check_mark: |
| 3.6.2 | :white_check_mark: |
| 3.4.6 | :white_check_mark: |
| 3.1.6 | :white_check_mark: |
| 3.1.5 | :white_check_mark: |
| 4.0.0 | :white_check_mark: |
| 3.6.8 | :x: |
| 3.6.5 | :x: |
| 3.6.3 | :x: |
| 3.6.2 | :x: |
| 3.4.6 | :x: |
| 3.1.6 | :x: |
| 3.1.5 | :x: |
| 3.1.4 | :x: |
| 3.0.x | :x: |

Expand Down
60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
{
"name": "strapi-provider-upload-google-cloud-storage",
"version": "3.6.8",
"version": "4.0.0",
"description": "(Non-official) Google Cloud Storage Provider for Strapi Upload",
"directories": {
"lib": "./lib"
},
"main": "./lib",
"scripts": {
"test": "mocha",
"lint": "eslint .",
"coverage": "nyc npm run test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Lith/strapi-provider-upload-google-cloud-storage.git"
},
"keywords": [
"strapi",
"upload",
Expand All @@ -23,9 +10,11 @@
"storage",
"gcp"
],
"strapi": {
"isProvider": true
"homepage": "https://github.com/Lith/strapi-provider-upload-google-cloud-storage#readme",
"bugs": {
"url": "https://github.com/Lith/strapi-provider-upload-google-cloud-storage/issues"
},
"license": "MIT",
"author": {
"name": "Vanessa Pasque",
"email": "lith@amykron.com"
Expand All @@ -36,29 +25,40 @@
"email": "lith@amykron.com"
}
],
"license": "MIT",
"bugs": {
"url": "https://github.com/Lith/strapi-provider-upload-google-cloud-storage/issues"
"main": "./lib",
"directories": {
"lib": "./lib"
},
"homepage": "https://github.com/Lith/strapi-provider-upload-google-cloud-storage#readme",
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
"scripts": {
"test": "mocha",
"lint": "eslint .",
"coverage": "nyc npm run test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Lith/strapi-provider-upload-google-cloud-storage.git"
},
"dependencies": {
"@google-cloud/storage": "^5.14.4",
"slugify": "^1.6.0"
"@google-cloud/storage": "^5.16.0",
"slugify": "^1.6.3"
},
"devDependencies": {
"codecov": "^3.8.3",
"eslint": "^7.32.0",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.1",
"mocha": "^8.4.0",
"eslint-plugin-prettier": "^4.0.0",
"mocha": "^9.1.3",
"mock-require": "^3.0.3",
"nyc": "^15.1.0",
"prettier": "^2.4.1"
"prettier": "^2.5.0"
},
"engines": {
"node": ">=12.x.x <=16.x.x",
"npm": ">=6.0.0"
},
"strapi": {
"isProvider": true
}
}

0 comments on commit ac9907a

Please sign in to comment.