feat(plugin-cloud-storage): implement storage packages (#5928)

This commit is contained in:
Elliot DeNolf
2024-04-22 14:31:20 -04:00
committed by GitHub
parent 6685a0fa7e
commit c23984cac3
90 changed files with 2451 additions and 100 deletions

View File

@@ -0,0 +1,8 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
ignorePatterns: ['payload-types.ts'],
parserOptions: {
project: ['./tsconfig.eslint.json'],
tsconfigRootDir: __dirname,
},
}

View File

@@ -0,0 +1,34 @@
import type { CollectionConfig } from 'payload/types'
export const Media: CollectionConfig = {
slug: 'media',
upload: {
disableLocalStorage: true,
resizeOptions: {
position: 'center',
width: 200,
height: 200,
},
imageSizes: [
{
height: 400,
width: 400,
crop: 'center',
name: 'square',
},
{
width: 900,
height: 450,
crop: 'center',
name: 'sixteenByNineMedium',
},
],
},
fields: [
{
name: 'alt',
label: 'Alt Text',
type: 'text',
},
],
}

View File

@@ -0,0 +1,9 @@
import type { CollectionConfig } from 'payload/types'
export const MediaWithPrefix: CollectionConfig = {
slug: 'media-with-prefix',
upload: {
disableLocalStorage: false,
},
fields: [],
}

View File

@@ -0,0 +1,16 @@
import type { CollectionConfig } from 'payload/types'
export const Users: CollectionConfig = {
slug: 'users',
auth: true,
admin: {
useAsTitle: 'email',
},
access: {
read: () => true,
},
fields: [
// Email added by default
// Add more fields as needed
],
}

View File

@@ -0,0 +1,45 @@
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
import dotenv from 'dotenv'
import { fileURLToPath } from 'node:url'
import path from 'path'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
import { Media } from './collections/Media.js'
import { MediaWithPrefix } from './collections/MediaWithPrefix.js'
import { Users } from './collections/Users.js'
import { mediaSlug, mediaWithPrefixSlug, prefix } from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
let uploadOptions
// TODO: Load this into CI or have shared creds
dotenv.config({
path: path.resolve(dirname, '.env'),
})
export default buildConfigWithDefaults({
collections: [Media, MediaWithPrefix, Users],
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
},
plugins: [
vercelBlobStorage({
collections: {
[mediaSlug]: true,
[mediaWithPrefixSlug]: {
prefix,
},
},
token: process.env.BLOB_READ_WRITE_TOKEN,
}),
],
upload: uploadOptions,
})

View File

@@ -0,0 +1,3 @@
export const mediaSlug = 'media'
export const mediaWithPrefixSlug = 'media-with-prefix'
export const prefix = 'test-prefix'

View File

@@ -0,0 +1,13 @@
{
// extend your base config to share compilerOptions, etc
//"extends": "./tsconfig.json",
"compilerOptions": {
// ensure that nobody can accidentally use this config for a build
"noEmit": true
},
"include": [
// whatever paths you intend to lint
"./**/*.ts",
"./**/*.tsx"
]
}