feat: storage-uploadthing package (#6316)
Co-authored-by: James <james@trbl.design>
This commit is contained in:
8
test/storage-uploadthing/.eslintrc.cjs
Normal file
8
test/storage-uploadthing/.eslintrc.cjs
Normal file
@@ -0,0 +1,8 @@
|
||||
/** @type {import('eslint').Linter.Config} */
|
||||
module.exports = {
|
||||
ignorePatterns: ['payload-types.ts'],
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.eslint.json'],
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
}
|
||||
34
test/storage-uploadthing/collections/Media.ts
Normal file
34
test/storage-uploadthing/collections/Media.ts
Normal 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',
|
||||
},
|
||||
],
|
||||
}
|
||||
9
test/storage-uploadthing/collections/MediaWithPrefix.ts
Normal file
9
test/storage-uploadthing/collections/MediaWithPrefix.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { CollectionConfig } from 'payload/types'
|
||||
|
||||
export const MediaWithPrefix: CollectionConfig = {
|
||||
slug: 'media-with-prefix',
|
||||
upload: {
|
||||
disableLocalStorage: false,
|
||||
},
|
||||
fields: [],
|
||||
}
|
||||
16
test/storage-uploadthing/collections/Users.ts
Normal file
16
test/storage-uploadthing/collections/Users.ts
Normal 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
|
||||
],
|
||||
}
|
||||
43
test/storage-uploadthing/config.ts
Normal file
43
test/storage-uploadthing/config.ts
Normal 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',
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
3
test/storage-uploadthing/shared.ts
Normal file
3
test/storage-uploadthing/shared.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const mediaSlug = 'media'
|
||||
export const mediaWithPrefixSlug = 'media-with-prefix'
|
||||
export const prefix = 'test-prefix'
|
||||
13
test/storage-uploadthing/tsconfig.eslint.json
Normal file
13
test/storage-uploadthing/tsconfig.eslint.json
Normal 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"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user