11import type { Plugin } from 'payload'
22
3+ import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'
34import { azureStorage } from '@payloadcms/storage-azure'
45import { gcsStorage } from '@payloadcms/storage-gcs'
56import { s3Storage } from '@payloadcms/storage-s3'
@@ -12,14 +13,21 @@ import { devUser } from '../credentials.js'
1213import { Media } from './collections/Media.js'
1314import { MediaWithPrefix } from './collections/MediaWithPrefix.js'
1415import { RestrictedMedia } from './collections/RestrictedMedia.js'
16+ import { TestMetadata } from './collections/TestMetadata.js'
1517import { Users } from './collections/Users.js'
16- import { mediaSlug , mediaWithPrefixSlug , restrictedMediaSlug , prefix } from './shared.js'
18+ import {
19+ mediaSlug ,
20+ mediaWithPrefixSlug ,
21+ prefix ,
22+ restrictedMediaSlug ,
23+ testMetadataSlug ,
24+ } from './shared.js'
1725import { createTestBucket } from './utils.js'
1826
1927const filename = fileURLToPath ( import . meta. url )
2028const dirname = path . dirname ( filename )
2129
22- let storagePlugin : Plugin
30+ let storagePlugin : Plugin = { } as Plugin
2331let uploadOptions
2432
2533// Load config to work with emulated services
@@ -37,9 +45,9 @@ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
3745 [ restrictedMediaSlug ] : true ,
3846 } ,
3947 allowContainerCreate : process . env . AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true' ,
40- baseURL : process . env . AZURE_STORAGE_ACCOUNT_BASEURL ,
41- connectionString : process . env . AZURE_STORAGE_CONNECTION_STRING ,
42- containerName : process . env . AZURE_STORAGE_CONTAINER_NAME ,
48+ baseURL : process . env . AZURE_STORAGE_ACCOUNT_BASEURL ! ,
49+ connectionString : process . env . AZURE_STORAGE_CONNECTION_STRING ! ,
50+ containerName : process . env . AZURE_STORAGE_CONTAINER_NAME ! ,
4351 } )
4452}
4553
@@ -52,7 +60,7 @@ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'gcs') {
5260 } ,
5361 [ restrictedMediaSlug ] : true ,
5462 } ,
55- bucket : process . env . GCS_BUCKET ,
63+ bucket : process . env . GCS_BUCKET ! ,
5664 options : {
5765 apiEndpoint : process . env . GCS_ENDPOINT ,
5866 projectId : process . env . GCS_PROJECT_ID ,
7785 } ,
7886 [ restrictedMediaSlug ] : true ,
7987 } ,
80- bucket : process . env . S3_BUCKET ,
88+ bucket : process . env . S3_BUCKET ?? '' ,
8189 config : {
8290 credentials : {
83- accessKeyId : process . env . S3_ACCESS_KEY_ID ,
84- secretAccessKey : process . env . S3_SECRET_ACCESS_KEY ,
91+ accessKeyId : process . env . S3_ACCESS_KEY_ID ?? '' ,
92+ secretAccessKey : process . env . S3_SECRET_ACCESS_KEY ?? '' ,
8593 } ,
8694 endpoint : process . env . S3_ENDPOINT ,
8795 forcePathStyle : process . env . S3_FORCE_PATH_STYLE === 'true' ,
@@ -98,11 +106,11 @@ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'r2') {
98106 prefix,
99107 } ,
100108 } ,
101- bucket : process . env . R2_BUCKET ,
109+ bucket : process . env . R2_BUCKET ?? '' ,
102110 config : {
103111 credentials : {
104- accessKeyId : process . env . S3_ACCESS_KEY_ID ,
105- secretAccessKey : process . env . S3_SECRET_ACCESS_KEY ,
112+ accessKeyId : process . env . S3_ACCESS_KEY_ID ?? '' ,
113+ secretAccessKey : process . env . S3_SECRET_ACCESS_KEY ?? '' ,
106114 } ,
107115 endpoint : process . env . S3_ENDPOINT ,
108116 forcePathStyle : process . env . S3_FORCE_PATH_STYLE === 'true' ,
@@ -111,13 +119,38 @@ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'r2') {
111119 } )
112120}
113121
122+ const testMetadataPlugin = cloudStoragePlugin ( {
123+ collections : {
124+ [ testMetadataSlug ] : {
125+ adapter : ( ) => ( {
126+ name : 'test-metadata-adapter' ,
127+ handleUpload : ( { file, data } ) => {
128+ const metadata = {
129+ ...data ,
130+ customStorageId : `storage-${ Date . now ( ) } ` ,
131+ uploadTimestamp : new Date ( ) . toISOString ( ) ,
132+ storageProvider : 'test-adapter' ,
133+ bucketName : 'test-bucket' ,
134+ objectKey : data . filename || file . filename , // Use the processed filename from data
135+ processingStatus : 'completed' ,
136+ uploadVersion : '1.0.0' ,
137+ }
138+ return metadata
139+ } ,
140+ handleDelete : ( ) => Promise . resolve ( ) ,
141+ staticHandler : ( ) => new Response ( 'Not found' , { status : 404 } ) ,
142+ } ) ,
143+ } ,
144+ } ,
145+ } )
146+
114147export default buildConfigWithDefaults ( {
115148 admin : {
116149 importMap : {
117150 baseDir : path . resolve ( dirname ) ,
118151 } ,
119152 } ,
120- collections : [ Media , MediaWithPrefix , RestrictedMedia , Users ] ,
153+ collections : [ Media , MediaWithPrefix , RestrictedMedia , TestMetadata , Users ] ,
121154 onInit : async ( payload ) => {
122155 /*const client = new AWS.S3({
123156 endpoint: process.env.S3_ENDPOINT,
@@ -151,7 +184,7 @@ export default buildConfigWithDefaults({
151184 `Using plugin-cloud-storage adapter: ${ process . env . PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER } ` ,
152185 )
153186 } ,
154- plugins : [ storagePlugin ] ,
187+ plugins : [ storagePlugin , testMetadataPlugin ] ,
155188 upload : uploadOptions ,
156189 typescript : {
157190 outputFile : path . resolve ( dirname , 'payload-types.ts' ) ,
0 commit comments