feat: storage-uploadthing package (#6316)

Co-authored-by: James <james@trbl.design>
This commit is contained in:
Elliot DeNolf
2024-05-10 17:05:35 -04:00
committed by GitHub
parent ea84e82ad5
commit ed880d5018
34 changed files with 774 additions and 17 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,43 @@
import { uploadthingStorage } from '@payloadcms/storage-uploadthing'
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 } from './shared.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
// Load test env 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: [
uploadthingStorage({
collections: {
[mediaSlug]: true,
},
options: {
apiKey: process.env.UPLOADTHING_SECRET,
acl: 'public-read',
},
}),
],
})

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"
]
}