@ainsleydev/payload-helper 0.0.21 → 0.0.23
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { lexicalEditor } from '@payloadcms/richtext-lexical';
|
|
2
2
|
import * as mime from 'mime-types';
|
|
3
|
+
import env from '../util/env.js';
|
|
3
4
|
/**
|
|
4
5
|
* Media Collection Configuration
|
|
5
6
|
* Additional fields will be appended to the media collection.
|
|
@@ -31,6 +32,8 @@ import * as mime from 'mime-types';
|
|
|
31
32
|
],
|
|
32
33
|
upload: {
|
|
33
34
|
staticDir: 'media',
|
|
35
|
+
adminThumbnail: 'thumbnail',
|
|
36
|
+
disableLocalStorage: env.isProduction,
|
|
34
37
|
handlers: [
|
|
35
38
|
async (req, args)=>{
|
|
36
39
|
const logger = req.payload.logger;
|
|
@@ -70,7 +73,11 @@ import * as mime from 'mime-types';
|
|
|
70
73
|
formatOptions: {
|
|
71
74
|
format: 'avif',
|
|
72
75
|
options: {
|
|
73
|
-
quality:
|
|
76
|
+
quality: 60,
|
|
77
|
+
effort: 1,
|
|
78
|
+
chromaSubsampling: '4:4:4',
|
|
79
|
+
bitdepth: 8,
|
|
80
|
+
lossless: false
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
},
|
|
@@ -101,7 +108,11 @@ import * as mime from 'mime-types';
|
|
|
101
108
|
formatOptions: {
|
|
102
109
|
format: 'avif',
|
|
103
110
|
options: {
|
|
104
|
-
quality:
|
|
111
|
+
quality: 60,
|
|
112
|
+
effort: 1,
|
|
113
|
+
chromaSubsampling: '4:4:4',
|
|
114
|
+
bitdepth: 8,
|
|
115
|
+
lossless: false
|
|
105
116
|
}
|
|
106
117
|
}
|
|
107
118
|
},
|
|
@@ -129,7 +140,11 @@ import * as mime from 'mime-types';
|
|
|
129
140
|
formatOptions: {
|
|
130
141
|
format: 'avif',
|
|
131
142
|
options: {
|
|
132
|
-
quality:
|
|
143
|
+
quality: 60,
|
|
144
|
+
effort: 1,
|
|
145
|
+
chromaSubsampling: '4:4:4',
|
|
146
|
+
bitdepth: 8,
|
|
147
|
+
lossless: false
|
|
133
148
|
}
|
|
134
149
|
}
|
|
135
150
|
},
|
|
@@ -157,7 +172,11 @@ import * as mime from 'mime-types';
|
|
|
157
172
|
formatOptions: {
|
|
158
173
|
format: 'avif',
|
|
159
174
|
options: {
|
|
160
|
-
quality:
|
|
175
|
+
quality: 60,
|
|
176
|
+
effort: 1,
|
|
177
|
+
chromaSubsampling: '4:4:4',
|
|
178
|
+
bitdepth: 8,
|
|
179
|
+
lossless: false
|
|
161
180
|
}
|
|
162
181
|
}
|
|
163
182
|
}
|
|
@@ -1 +1 @@
|
|
|
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:
|
|
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';\nimport env from '../util/env.js';\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\tadminThumbnail: 'thumbnail',\n\t\t\tdisableLocalStorage: env.isProduction,\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: 60,\n\t\t\t\t\t\t\teffort: 1,\n\t\t\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\t\t\tlossless: false,\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: 200,\n\t\t\t\t\theight: undefined,\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: 200,\n\t\t\t\t\theight: undefined,\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: 200,\n\t\t\t\t\theight: undefined,\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: 60,\n\t\t\t\t\t\t\teffort: 1,\n\t\t\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\t\t\tlossless: false,\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: 500,\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: 500,\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: 500,\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: 60,\n\t\t\t\t\t\t\teffort: 1,\n\t\t\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\t\t\tlossless: false,\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: 800,\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: 800,\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: 800,\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: 60,\n\t\t\t\t\t\t\teffort: 1,\n\t\t\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\t\t\tlossless: false,\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: 1200,\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: 1200,\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: 1200,\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","env","Media","additionalFields","slug","access","read","fields","name","type","required","editor","features","defaultFeatures","filter","feature","key","upload","staticDir","adminThumbnail","disableLocalStorage","isProduction","handlers","req","args","logger","payload","params","collection","filename","contentType","lookup","error","headers","Headers","set","responseHeaders","imageSizes","width","undefined","height","formatOptions","format","options","quality","effort","chromaSubsampling","bitdepth","lossless","position"],"mappings":"AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAC7D,YAAYC,UAAU,aAAa;AAEnC,OAAOC,SAAS,iBAAiB;AAEjC;;;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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