@ainsleydev/payload-helper 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,9 +2,5 @@ import type { CollectionConfig, Field } from 'payload';
|
|
|
2
2
|
/**
|
|
3
3
|
* Media Collection Configuration
|
|
4
4
|
* Additional fields will be appended to the media collection.
|
|
5
|
-
*
|
|
6
|
-
* @constructor
|
|
7
|
-
* @param editor
|
|
8
|
-
* @param additionalFields
|
|
9
5
|
*/
|
|
10
6
|
export declare const Media: (additionalFields?: Field[]) => CollectionConfig;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// LexicalEditorProps,
|
|
4
|
-
// } from '@payloadcms/richtext-lexical';
|
|
1
|
+
import { lexicalEditor } from '@payloadcms/richtext-lexical';
|
|
2
|
+
import * as mime from 'mime-types';
|
|
5
3
|
/**
|
|
6
4
|
* Media Collection Configuration
|
|
7
5
|
* Additional fields will be appended to the media collection.
|
|
8
|
-
|
|
9
|
-
* @constructor
|
|
10
|
-
* @param editor
|
|
11
|
-
* @param additionalFields
|
|
12
|
-
*/ export const Media = (//editor?: (props?: LexicalEditorProps) => LexicalRichTextAdapterProvider,
|
|
13
|
-
additionalFields)=>{
|
|
6
|
+
*/ export const Media = (additionalFields)=>{
|
|
14
7
|
return {
|
|
15
8
|
slug: 'media',
|
|
16
9
|
access: {
|
|
@@ -25,12 +18,38 @@ additionalFields)=>{
|
|
|
25
18
|
{
|
|
26
19
|
name: 'caption',
|
|
27
20
|
type: 'richText',
|
|
28
|
-
required: false
|
|
21
|
+
required: false,
|
|
22
|
+
editor: lexicalEditor({
|
|
23
|
+
features: ({ defaultFeatures })=>{
|
|
24
|
+
return defaultFeatures.filter((feature)=>{
|
|
25
|
+
return feature.key === 'paragraph' || feature.key === 'link';
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
29
|
},
|
|
30
30
|
...additionalFields ? additionalFields : []
|
|
31
31
|
],
|
|
32
32
|
upload: {
|
|
33
33
|
staticDir: 'media',
|
|
34
|
+
handlers: [
|
|
35
|
+
async (req, args)=>{
|
|
36
|
+
const logger = req.payload.logger;
|
|
37
|
+
const { params } = args;
|
|
38
|
+
const { collection, filename } = params;
|
|
39
|
+
if (collection !== 'media') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const contentType = mime.lookup(filename);
|
|
43
|
+
if (!contentType) {
|
|
44
|
+
logger.error(`Unable to find mime type for file: ${filename}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const headers = new Headers();
|
|
48
|
+
headers.set('Content-Type', contentType);
|
|
49
|
+
headers.set('Cache-Control', 'public, max-age=31536000');
|
|
50
|
+
req.responseHeaders = headers;
|
|
51
|
+
}
|
|
52
|
+
],
|
|
34
53
|
imageSizes: [
|
|
35
54
|
// Original Size (for WebP & Avif)
|
|
36
55
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Media.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/collections/Media.ts"],"sourcesContent":["import { lexicalEditor } from '@payloadcms/richtext-lexical';\nimport * as mime from 'mime-types';\nimport type { CollectionConfig, Field, PayloadRequest } from 'payload';\n\n/**\n * Media Collection Configuration\n * Additional fields will be appended to the media collection.\n */\nexport const Media = (additionalFields?: Field[]): CollectionConfig => {\n\treturn {\n\t\tslug: 'media',\n\t\taccess: {\n\t\t\tread: () => true,\n\t\t},\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'alt',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'caption',\n\t\t\t\ttype: 'richText',\n\t\t\t\trequired: false,\n\t\t\t\teditor: lexicalEditor({\n\t\t\t\t\tfeatures: ({ defaultFeatures }) => {\n\t\t\t\t\t\treturn defaultFeatures.filter((feature) => {\n\t\t\t\t\t\t\treturn feature.key === 'paragraph' || feature.key === 'link';\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t\t...(additionalFields ? additionalFields : []),\n\t\t],\n\t\tupload: {\n\t\t\tstaticDir: 'media',\n\t\t\thandlers: [\n\t\t\t\tasync (req: PayloadRequest, args) => {\n\t\t\t\t\tconst logger = req.payload.logger;\n\t\t\t\t\tconst { params } = args;\n\t\t\t\t\tconst { collection, filename } = params;\n\n\t\t\t\t\tif (collection !== 'media') {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst contentType = mime.lookup(filename);\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tlogger.error(`Unable to find mime type for file: ${filename}`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst headers = new Headers();\n\t\t\t\t\theaders.set('Content-Type', contentType);\n\t\t\t\t\theaders.set('Cache-Control', 'public, max-age=31536000');\n\n\t\t\t\t\treq.responseHeaders = headers;\n\t\t\t\t},\n\t\t\t],\n\t\t\timageSizes: [\n\t\t\t\t// Original Size (for WebP & Avif)\n\t\t\t\t{\n\t\t\t\t\tname: 'webp',\n\t\t\t\t\twidth: undefined,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'webp',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'avif',\n\t\t\t\t\twidth: undefined,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'avif',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// Thumbnail Sizes\n\t\t\t\t{\n\t\t\t\t\tname: 'thumbnail',\n\t\t\t\t\twidth: 400,\n\t\t\t\t\theight: 300,\n\t\t\t\t\tposition: 'centre',\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'thumbnail_webp',\n\t\t\t\t\twidth: 400,\n\t\t\t\t\theight: 300,\n\t\t\t\t\tposition: 'centre',\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'webp',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'thumbnail_avif',\n\t\t\t\t\twidth: 400,\n\t\t\t\t\theight: 300,\n\t\t\t\t\tposition: 'centre',\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'avif',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// Mobile Sizes\n\t\t\t\t{\n\t\t\t\t\tname: 'mobile',\n\t\t\t\t\twidth: 768,\n\t\t\t\t\theight: undefined,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'mobile_webp',\n\t\t\t\t\twidth: 768,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'webp',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'mobile_avif',\n\t\t\t\t\twidth: 768,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'avif',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// Tablet Sizes\n\t\t\t\t{\n\t\t\t\t\tname: 'tablet',\n\t\t\t\t\twidth: 1024,\n\t\t\t\t\theight: undefined,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'tablet_webp',\n\t\t\t\t\twidth: 1024,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'webp',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'tablet_avif',\n\t\t\t\t\twidth: 1024,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'avif',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// Desktop Sizes\n\t\t\t\t{\n\t\t\t\t\tname: 'desktop',\n\t\t\t\t\twidth: 1440,\n\t\t\t\t\theight: undefined,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'desktop_webp',\n\t\t\t\t\twidth: 1440,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'webp',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: 'desktop_avif',\n\t\t\t\t\twidth: 1440,\n\t\t\t\t\theight: undefined,\n\t\t\t\t\tformatOptions: {\n\t\t\t\t\t\tformat: 'avif',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tquality: 80,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t};\n};\n"],"names":["lexicalEditor","mime","Media","additionalFields","slug","access","read","fields","name","type","required","editor","features","defaultFeatures","filter","feature","key","upload","staticDir","handlers","req","args","logger","payload","params","collection","filename","contentType","lookup","error","headers","Headers","set","responseHeaders","imageSizes","width","undefined","height","formatOptions","format","options","quality","position"],"mappings":"AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAC7D,YAAYC,UAAU,aAAa;AAGnC;;;CAGC,GACD,OAAO,MAAMC,QAAQ,CAACC;IACrB,OAAO;QACNC,MAAM;QACNC,QAAQ;YACPC,MAAM,IAAM;QACb;QACAC,QAAQ;YACP;gBACCC,MAAM;gBACNC,MAAM;gBACNC,UAAU;YACX;YACA;gBACCF,MAAM;gBACNC,MAAM;gBACNC,UAAU;gBACVC,QAAQX,cAAc;oBACrBY,UAAU,CAAC,EAAEC,eAAe,EAAE;wBAC7B,OAAOA,gBAAgBC,MAAM,CAAC,CAACC;4BAC9B,OAAOA,QAAQC,GAAG,KAAK,eAAeD,QAAQC,GAAG,KAAK;wBACvD;oBACD;gBACD;YACD;eACIb,mBAAmBA,mBAAmB,EAAE;SAC5C;QACDc,QAAQ;YACPC,WAAW;YACXC,UAAU;gBACT,OAAOC,KAAqBC;oBAC3B,MAAMC,SAASF,IAAIG,OAAO,CAACD,MAAM;oBACjC,MAAM,EAAEE,MAAM,EAAE,GAAGH;oBACnB,MAAM,EAAEI,UAAU,EAAEC,QAAQ,EAAE,GAAGF;oBAEjC,IAAIC,eAAe,SAAS;wBAC3B;oBACD;oBAEA,MAAME,cAAc1B,KAAK2B,MAAM,CAACF;oBAChC,IAAI,CAACC,aAAa;wBACjBL,OAAOO,KAAK,CAAC,CAAC,mCAAmC,EAAEH,SAAS,CAAC;wBAC7D;oBACD;oBAEA,MAAMI,UAAU,IAAIC;oBACpBD,QAAQE,GAAG,CAAC,gBAAgBL;oBAC5BG,QAAQE,GAAG,CAAC,iBAAiB;oBAE7BZ,IAAIa,eAAe,GAAGH;gBACvB;aACA;YACDI,YAAY;gBACX,kCAAkC;gBAClC;oBACC1B,MAAM;oBACN2B,OAAOC;oBACPC,QAAQD;oBACRE,eAAe;wBACdC,QAAQ;wBACRC,SAAS;4BACRC,SA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,QAAQD;oBACRE,eAAe;wBACdC,QAAQ;wBACRC,SAAS;4BACRC,SAAS;wBACV;oBACD;gBACD;gBACA;oBACCjC,MAAM;oBACN2B,OAAO;oBACPE,QAAQD;oBACRE,eAAe;wBACdC,QAAQ;wBACRC,SAAS;4BACRC,SAAS;wBACV;oBACD;gBACD;aACA;QACF;IACD;AACD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsleydev/payload-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,12 +37,14 @@
|
|
|
37
37
|
"@nouance/payload-better-fields-plugin": "^1.4.1",
|
|
38
38
|
"@payloadcms/db-sqlite": "3.0.0-canary.2c2c95f",
|
|
39
39
|
"@payloadcms/richtext-lexical": "3.0.0-beta.73",
|
|
40
|
+
"@payloadcms/storage-s3": "3.0.0-beta.29",
|
|
40
41
|
"@types/json-schema": "^7.0.15",
|
|
41
42
|
"chalk": "^5.3.0",
|
|
42
43
|
"commander": "^12.1.0",
|
|
43
44
|
"dotenv": "^16.4.5",
|
|
44
45
|
"jsdom": "^24.1.1",
|
|
45
46
|
"lexical": "^0.16.1",
|
|
47
|
+
"mime-types": "^2.1.35",
|
|
46
48
|
"payload": "3.0.0-beta.73"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
@@ -52,6 +54,7 @@
|
|
|
52
54
|
"@swc/core": "^1.7.2",
|
|
53
55
|
"@types/jest": "^29.5.12",
|
|
54
56
|
"@types/jsdom": "^21.1.7",
|
|
57
|
+
"@types/mime-types": "^2.1.4",
|
|
55
58
|
"jest": "^29.7.0",
|
|
56
59
|
"json-schema": "^0.4.0",
|
|
57
60
|
"rimraf": "3.0.2",
|