feat: builds plugin with azure adapter

This commit is contained in:
James
2022-08-06 14:49:46 -04:00
parent 4e1da749c9
commit 2b7547fbae
28 changed files with 1363 additions and 550 deletions

View File

@@ -1,3 +1,9 @@
MONGODB_URI=mongodb://localhost/payload-plugin-cloud-storage
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
PAYLOAD_SECRET=
PAYLOAD_SECRET=45ligj345ligj4wl5igj4lw5igj45ligj45wlijl
PAYLOAD_CONFIG_PATH=src/payload.config.ts
AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
AZURE_STORAGE_CONTAINER_NAME=az-media
AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1

View File

@@ -12,9 +12,10 @@
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
},
"dependencies": {
"@azure/storage-blob": "^12.11.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"payload": "^0.19.2"
"payload": "^1.0.16"
},
"devDependencies": {
"@types/express": "^4.17.9",

View File

@@ -1,13 +1,56 @@
import type { CollectionConfig } from 'payload/types'
/* eslint-disable no-console */
import type { CollectionConfig, Field } from 'payload/types'
const urlField: Field = {
name: 'url',
type: 'text',
hooks: {
afterRead: [
({ value }) => {
console.log('hello from hook')
return value
},
],
},
}
export const Media: CollectionConfig = {
slug: 'media',
upload: true,
upload: {
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',
},
// The following fields should be able to be merged in to default upload fields
urlField,
{
name: 'sizes',
type: 'group',
fields: [
{
name: 'square',
type: 'group',
fields: [urlField],
},
],
},
],
}

View File

@@ -1,10 +1,8 @@
import { CollectionConfig } from 'payload/types';
import type { CollectionConfig } from 'payload/types'
const Users: CollectionConfig = {
slug: 'users',
auth: {
disableLocalStrategy: true,
},
auth: true,
admin: {
useAsTitle: 'upn',
},
@@ -14,6 +12,6 @@ const Users: CollectionConfig = {
fields: [
// no fields in this demo necessary
],
};
}
export default Users;
export default Users

View File

@@ -1,7 +1,7 @@
import { buildConfig } from 'payload/config'
import path from 'path'
import Users from './collections/Users'
import { cloudStorage } from '../../src/plugin'
import { cloudStorage, azureBlobStorageAdapter } from '../../src'
import { Media } from './collections/Media'
export default buildConfig({
@@ -32,7 +32,13 @@ export default buildConfig({
cloudStorage({
collections: [
{
slug: 'users',
slug: 'media',
adapter: azureBlobStorageAdapter({
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
}),
},
],
}),

View File

@@ -12,6 +12,7 @@
"outDir": "./dist",
"rootDir": "../",
"jsx": "react",
"sourceMap": true
},
"ts-node": {
"transpileOnly": true

File diff suppressed because it is too large Load Diff