feat: conditional gcs setup
This commit is contained in:
parent
4c07349f9d
commit
6bc4e6e8df
4 changed files with 22 additions and 13 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
DATABASE_URI=mongodb://127.0.0.1/dreikoenige
|
DATABASE_URI=mongodb://127.0.0.1/dreikoenige
|
||||||
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
PAYLOAD_SECRET=YOUR_SECRET_HERE
|
||||||
GOOGLE_BUCKET=google_storage_bucket
|
GOOGLE_BUCKET=google_storage_bucket #can be omitted
|
||||||
RESEND_API_KEY=some_api_key
|
RESEND_API_KEY=some_api_key
|
||||||
|
PUBLIC_URL=http://localhost:3000
|
||||||
|
|
@ -46,6 +46,15 @@ Create and run a container, then set your `DATABASE_URI` to the Postgres URL. En
|
||||||
|
|
||||||
Alternatively, you can enable the Postgres service in `docker-compose.yml` (currently commented out) and use that as your local DB.
|
Alternatively, you can enable the Postgres service in `docker-compose.yml` (currently commented out) and use that as your local DB.
|
||||||
|
|
||||||
|
## Google Cloud Storage
|
||||||
|
|
||||||
|
Media and document uploads use `@payloadcms/storage-gcs`. The plugin is always registered but conditionally enabled via the `GOOGLE_BUCKET` environment variable:
|
||||||
|
|
||||||
|
- **`GOOGLE_BUCKET` set** — files are uploaded to GCS and served from `https://storage.googleapis.com/<bucket>/`.
|
||||||
|
- **`GOOGLE_BUCKET` unset** — the plugin is disabled and Payload falls back to local file storage. The `alwaysInsertFields` flag keeps the schema identical in both cases, so `payload-types.ts` and `importMap.js` stay stable across environments.
|
||||||
|
|
||||||
|
No additional configuration is needed for local development — simply omit `GOOGLE_BUCKET` from your `.env`.
|
||||||
|
|
||||||
## Migrations (Payload)
|
## Migrations (Payload)
|
||||||
|
|
||||||
Create a new migration:
|
Create a new migration:
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,6 @@ export interface Church {
|
||||||
*/
|
*/
|
||||||
export interface Document {
|
export interface Document {
|
||||||
id: string;
|
id: string;
|
||||||
prefix?: string | null;
|
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
|
|
@ -285,7 +284,6 @@ export interface Media {
|
||||||
publicWithoutName: boolean;
|
publicWithoutName: boolean;
|
||||||
consent: boolean;
|
consent: boolean;
|
||||||
};
|
};
|
||||||
prefix?: string | null;
|
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
|
|
@ -1654,7 +1652,6 @@ export interface MagazineSelect<T extends boolean = true> {
|
||||||
* via the `definition` "documents_select".
|
* via the `definition` "documents_select".
|
||||||
*/
|
*/
|
||||||
export interface DocumentsSelect<T extends boolean = true> {
|
export interface DocumentsSelect<T extends boolean = true> {
|
||||||
prefix?: T;
|
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
url?: T;
|
url?: T;
|
||||||
|
|
@ -1681,7 +1678,6 @@ export interface MediaSelect<T extends boolean = true> {
|
||||||
publicWithoutName?: T;
|
publicWithoutName?: T;
|
||||||
consent?: T;
|
consent?: T;
|
||||||
};
|
};
|
||||||
prefix?: T;
|
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
url?: T;
|
url?: T;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
AlignFeature,
|
AlignFeature,
|
||||||
UnorderedListFeature,
|
UnorderedListFeature,
|
||||||
LinkFeature,
|
LinkFeature,
|
||||||
HTMLConverterFeature, FixedToolbarFeature,
|
FixedToolbarFeature,
|
||||||
} from '@payloadcms/richtext-lexical'
|
} from '@payloadcms/richtext-lexical'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { buildConfig } from 'payload'
|
import { buildConfig } from 'payload'
|
||||||
|
|
@ -141,22 +141,25 @@ export default buildConfig({
|
||||||
sharp,
|
sharp,
|
||||||
plugins: [
|
plugins: [
|
||||||
gcsStorage({
|
gcsStorage({
|
||||||
|
enabled: !!process.env.GOOGLE_BUCKET,
|
||||||
|
alwaysInsertFields: true,
|
||||||
collections: {
|
collections: {
|
||||||
media: {
|
media: {
|
||||||
disablePayloadAccessControl: true,
|
disablePayloadAccessControl: true,
|
||||||
prefix: 'media/',
|
prefix: 'media/',
|
||||||
generateFileURL: args => `https://storage.googleapis.com/${process.env.GOOGLE_BUCKET}/media/${args.filename}`
|
generateFileURL: (args) =>
|
||||||
|
`https://storage.googleapis.com/${process.env.GOOGLE_BUCKET}/media/${args.filename}`,
|
||||||
},
|
},
|
||||||
documents: {
|
documents: {
|
||||||
disablePayloadAccessControl: true,
|
disablePayloadAccessControl: true,
|
||||||
prefix: 'documents/',
|
prefix: 'documents/',
|
||||||
generateFileURL: args => `https://storage.googleapis.com/${process.env.GOOGLE_BUCKET}/documents/${args.filename}`
|
generateFileURL: (args) =>
|
||||||
|
`https://storage.googleapis.com/${process.env.GOOGLE_BUCKET}/documents/${args.filename}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
bucket: process.env.GOOGLE_BUCKET || "",
|
bucket: process.env.GOOGLE_BUCKET || '',
|
||||||
options: {},
|
options: {},
|
||||||
acl: undefined
|
acl: undefined,
|
||||||
})
|
}),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue