payload-ai 0.0.54 → 0.0.71
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.
- package/README.md +58 -224
- package/dev/package.json +1 -1
- package/dev/src/collections/Examples.ts +3 -0
- package/dev/src/collections/Media.ts +44 -0
- package/dev/src/media/IMG_3624-1024x768.jpg +0 -0
- package/dev/src/media/IMG_3624.jpeg +0 -0
- package/dev/src/payload.config.ts +18 -1
- package/dist/access/admins.d.ts +4 -0
- package/dist/access/admins.js +12 -0
- package/dist/access/admins.js.map +1 -0
- package/dist/access/adminsOrPublished.d.ts +2 -0
- package/dist/access/adminsOrPublished.js +18 -0
- package/dist/access/adminsOrPublished.js.map +1 -0
- package/dist/access/anyone.d.ts +2 -0
- package/dist/access/anyone.js +6 -0
- package/dist/access/anyone.js.map +1 -0
- package/dist/access/checkRole.d.ts +1 -0
- package/dist/access/checkRole.js +18 -0
- package/dist/access/checkRole.js.map +1 -0
- package/dist/access/validateAccess.d.ts +1 -0
- package/dist/access/validateAccess.js +14 -0
- package/dist/access/validateAccess.js.map +1 -0
- package/dist/aiCaption.d.ts +8 -0
- package/dist/aiCaption.js +145 -0
- package/dist/aiCaption.js.map +1 -0
- package/dist/aiTranslate.d.ts +8 -0
- package/dist/aiTranslate.js +166 -0
- package/dist/aiTranslate.js.map +1 -0
- package/dist/components/AfterDashboard/index.d.ts +3 -0
- package/dist/components/AfterDashboard/index.js +17 -0
- package/dist/components/AfterDashboard/index.js.map +1 -0
- package/dist/components/AfterDashboard/index.scss +10 -0
- package/dist/components/Metadata/index.d.ts +2 -0
- package/dist/components/Metadata/index.js +101 -0
- package/dist/components/Metadata/index.js.map +1 -0
- package/dist/components/Metadata/index.scss +10 -0
- package/dist/components/Translator/Translator.scss +6 -0
- package/dist/components/Translator/index.d.ts +4 -0
- package/dist/components/Translator/index.js +222 -0
- package/dist/components/Translator/index.js.map +1 -0
- package/dist/deepCompareAndMerge.d.ts +5 -0
- package/dist/deepCompareAndMerge.js +102 -0
- package/dist/deepCompareAndMerge.js.map +1 -0
- package/dist/fsMock.d.ts +3 -0
- package/dist/fsMock.js +3 -0
- package/dist/fsMock.js.map +1 -0
- package/dist/generateImage.d.ts +1 -0
- package/dist/generateImage.js +80 -0
- package/dist/generateImage.js.map +1 -0
- package/dist/generateText.d.ts +5 -0
- package/dist/generateText.js +93 -0
- package/dist/generateText.js.map +1 -0
- package/dist/handleMissingTranslate.d.ts +3 -0
- package/dist/handleMissingTranslate.js +114 -0
- package/dist/handleMissingTranslate.js.map +1 -0
- package/dist/handleTranslate.d.ts +3 -0
- package/dist/handleTranslate.js +101 -0
- package/dist/handleTranslate.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mocks/mockFile.d.ts +1 -0
- package/dist/mocks/mockFile.js +3 -0
- package/dist/mocks/mockFile.js.map +1 -0
- package/dist/onInitExtension.d.ts +3 -0
- package/dist/onInitExtension.js +17 -0
- package/dist/onInitExtension.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.js +186 -0
- package/dist/plugin.js.map +1 -0
- package/dist/seoTools.d.ts +2 -0
- package/dist/seoTools.js +135 -0
- package/dist/seoTools.js.map +1 -0
- package/dist/stringTranslations.d.ts +3 -0
- package/dist/stringTranslations.js +208 -0
- package/dist/stringTranslations.js.map +1 -0
- package/dist/translateTextAndObjects.d.ts +1 -0
- package/dist/translateTextAndObjects.js +288 -0
- package/dist/translateTextAndObjects.js.map +1 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/webpack.d.ts +3 -0
- package/dist/webpack.js +32 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +6 -2
- package/src/access/validateAccess.ts +13 -0
- package/src/aiCaption.ts +90 -0
- package/src/aiTranslate.ts +19 -11
- package/src/components/Translator/index.tsx +49 -12
- package/src/countries.json +193 -0
- package/src/deepCompareAndMerge.ts +7 -2
- package/src/fsMock.js +1 -0
- package/src/generateText.ts +3 -3
- package/src/handleMissingTranslate.ts +52 -0
- package/src/handleTranslate.ts +12 -6
- package/src/plugin.ts +30 -2
- package/src/seoTools.ts +2 -2
- package/src/stringTranslations.ts +35 -1
- package/src/translateTextAndObjects.ts +85 -23
- package/src/webpack.ts +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Payload AI
|
|
2
2
|
|
|
3
|
-
Translate content to different languages using OpenAI's GPT.
|
|
3
|
+
Translate content to different languages using [OpenAI's GPT](https://openai.com/).
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
### How to install the plugin
|
|
@@ -32,7 +32,7 @@ export const config = buildConfig({
|
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
### Collection translation
|
|
35
|
+
### Collection translation 📦
|
|
36
36
|
|
|
37
37
|
Add the `collections` where you want to enable the translation and the `fields`. It will translate each field (also nested fields) on every update of the default language.
|
|
38
38
|
|
|
@@ -41,15 +41,10 @@ plugins: [
|
|
|
41
41
|
aiTranslatorPlugin({
|
|
42
42
|
enabled: true,
|
|
43
43
|
collections: {
|
|
44
|
-
examples: {
|
|
45
|
-
// prompts: [myCollectionPrompt]
|
|
44
|
+
examples: { // Name of the collection you want to add translations
|
|
46
45
|
fields: [
|
|
47
|
-
'stringText',
|
|
46
|
+
'stringText', // Keys of fields you want to translate (wil also translate nested fields)
|
|
48
47
|
'richText',
|
|
49
|
-
{
|
|
50
|
-
"fieldWithCustomPrompt":
|
|
51
|
-
{prompt: myPromptFunction}
|
|
52
|
-
}
|
|
53
48
|
],
|
|
54
49
|
},
|
|
55
50
|
},
|
|
@@ -57,21 +52,38 @@ plugins: [
|
|
|
57
52
|
],
|
|
58
53
|
```
|
|
59
54
|
|
|
60
|
-
#### Use in hooks
|
|
61
55
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
myCollectionPrompt = ({source}) => {
|
|
56
|
+
#### Custom prompts by Field
|
|
65
57
|
|
|
66
|
-
|
|
58
|
+
Use `promptFunc` for each field to customize the prompt.
|
|
67
59
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
```jsx
|
|
61
|
+
plugins: [
|
|
62
|
+
aiTranslatorPlugin({
|
|
63
|
+
enabled: true,
|
|
64
|
+
collections: {
|
|
65
|
+
examples: {
|
|
66
|
+
settings: {
|
|
67
|
+
model: 'gpt-4',
|
|
68
|
+
promptFunc: ({ messages, namespace }) => {
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
role: 'system',
|
|
72
|
+
content:
|
|
73
|
+
'Important: Add a smily face at the end of the message to make the AI more friendly. 😊',
|
|
74
|
+
},
|
|
75
|
+
...messages,
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
```
|
|
72
84
|
|
|
73
|
-
Use the `prompt` function for each field to use a customized prompt. The function will allow you to use the following
|
|
74
85
|
|
|
86
|
+
The function will allow you to use the following
|
|
75
87
|
|
|
76
88
|
- `req`: Request
|
|
77
89
|
- `doc` Document in languages
|
|
@@ -87,9 +99,6 @@ Use the `prompt` function for each field to use a customized prompt. The functio
|
|
|
87
99
|
- sourceField
|
|
88
100
|
|
|
89
101
|
|
|
90
|
-
```jsx
|
|
91
|
-
customPrompt = ({sourceField}) => `Translate ${sourceField} to ${targetLanguage}.`
|
|
92
|
-
```
|
|
93
102
|
|
|
94
103
|
### Use with [payload-seo](https://payloadcms.com/docs/plugins/seo)
|
|
95
104
|
|
|
@@ -143,11 +152,31 @@ plugins: [
|
|
|
143
152
|
],
|
|
144
153
|
```
|
|
145
154
|
|
|
155
|
+
### Access control
|
|
146
156
|
|
|
147
|
-
|
|
157
|
+
By default the plugin will use the [update](https://payloadcms.com/docs/access-control/collections#update) access control of the collection.
|
|
148
158
|
|
|
159
|
+
To overwrite that behaviour you can add `access` to the collections configuration.
|
|
149
160
|
|
|
150
|
-
|
|
161
|
+
|
|
162
|
+
```jsx
|
|
163
|
+
plugins: [
|
|
164
|
+
aiTranslatorPlugin({
|
|
165
|
+
enabled: true,
|
|
166
|
+
stringTranslation: {
|
|
167
|
+
enabled: true
|
|
168
|
+
}
|
|
169
|
+
collections: {
|
|
170
|
+
examples: {
|
|
171
|
+
access: () => true,
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
### Planned features 🧭
|
|
151
180
|
|
|
152
181
|
- generate image alt text from GPT
|
|
153
182
|
- generate SEO Text
|
|
@@ -157,208 +186,13 @@ plugins: [
|
|
|
157
186
|
- generate images based on input
|
|
158
187
|
- generate Open Graph based on content
|
|
159
188
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
To build your own Payload plugin, all you need is:
|
|
163
|
-
|
|
164
|
-
* An understanding of the basic Payload concepts
|
|
165
|
-
* And some JavaScript/Typescript experience
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
### Initialization
|
|
172
|
-
|
|
173
|
-
The initialization process goes in the following order:
|
|
174
|
-
|
|
175
|
-
1. Incoming config is validated
|
|
176
|
-
2. **Plugins execute**
|
|
177
|
-
3. Default options are integrated
|
|
178
|
-
4. Sanitization cleans and validates data
|
|
179
|
-
5. Final config gets initialized
|
|
180
|
-
|
|
181
|
-
## Building the Plugin
|
|
182
|
-
|
|
183
|
-
When you build a plugin, you are purely building a feature for your project and then abstracting it outside of the project.
|
|
184
|
-
|
|
185
|
-
### Template Files
|
|
186
|
-
|
|
187
|
-
In the [payload-plugin-template](https://github.com/payloadcms/payload-plugin-template), you will see a common file structure that is used across all plugins:
|
|
188
|
-
|
|
189
|
-
1. root folder
|
|
190
|
-
2. /src folder
|
|
191
|
-
3. /dev folder
|
|
192
|
-
|
|
193
|
-
#### Root
|
|
194
|
-
|
|
195
|
-
In the root folder, you will see various files that relate to the configuration of the plugin. We set up our environment in a similar manner in Payload core and across other projects, so hopefully these will look familiar:
|
|
196
|
-
|
|
197
|
-
* **README**.md* - This contains instructions on how to use the template. When you are ready, update this to contain instructions on how to use your Plugin.
|
|
198
|
-
* **package**.json* - Contains necessary scripts and dependencies. Overwrite the metadata in this file to describe your Plugin.
|
|
199
|
-
* .**editorconfig** - Defines settings to maintain consistent coding styles.
|
|
200
|
-
* .**eslintrc**.js - Eslint configuration for reporting on problematic patterns.
|
|
201
|
-
* .**gitignore** - List specific untracked files to omit from Git.
|
|
202
|
-
* .**prettierrc**.js - Configuration for Prettier code formatting.
|
|
203
|
-
* **LICENSE** - As part of the open-source community, we ship all plugins with an MIT license but it is not required.
|
|
204
|
-
* **tsconfig**.json - Configures the compiler options for TypeScript
|
|
205
|
-
|
|
206
|
-
**IMPORTANT***: You will need to modify these files.
|
|
207
|
-
|
|
208
|
-
#### Dev
|
|
209
|
-
|
|
210
|
-
In the dev folder, you’ll find a basic payload project, created with `npx create-payload-app` and the blank template.
|
|
211
|
-
|
|
212
|
-
The `samplePlugin` has already been installed to the `payload.config()` file in this project.
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
plugins: [
|
|
216
|
-
samplePlugin({
|
|
217
|
-
enabled: false,
|
|
218
|
-
})
|
|
219
|
-
]
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Later when you rename the plugin or add additional options, make sure to update them here.
|
|
223
|
-
|
|
224
|
-
You may wish to add collections or expand the test project depending on the purpose of your plugin. Just make sure to keep this dev environment as simplified as possible - users should be able to install your plugin without additional configuration required.
|
|
225
|
-
|
|
226
|
-
When you’re ready to start development, navigate into this folder with `cd dev`
|
|
227
|
-
|
|
228
|
-
And then start the project with `yarn dev` and pull up [http://localhost:3000/](http://localhost:3000/) in your browser.
|
|
229
|
-
|
|
230
|
-
#### Src
|
|
231
|
-
|
|
232
|
-
Now that we have our environment setup and we have a dev project ready to - it’s time to build the plugin!
|
|
233
|
-
|
|
234
|
-
**index.ts**
|
|
235
|
-
|
|
236
|
-
First up, the `src/index.ts` file. It is best practice not to build the plugin directly in this file, instead we use this to export the plugin and types from separate files.
|
|
237
|
-
|
|
238
|
-
**Plugin.ts**
|
|
239
|
-
|
|
240
|
-
To reiterate, the essence of a payload plugin is simply to extend the payload config - and that is exactly what we are doing in this file.
|
|
241
|
-
|
|
242
|
-
```ts
|
|
243
|
-
export const samplePlugin =
|
|
244
|
-
(pluginOptions: PluginTypes) =>
|
|
245
|
-
(incomingConfig: Config): Config => {
|
|
246
|
-
let config = { ...incomingConfig }
|
|
247
|
-
|
|
248
|
-
// do something cool with the config here
|
|
249
|
-
|
|
250
|
-
return config
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
First, we receive the existing payload config along with any plugin options.
|
|
256
|
-
|
|
257
|
-
Then we set the variable `config` to be equal to the existing config.
|
|
258
|
-
|
|
259
|
-
From here, you can extend the config as you wish.
|
|
260
|
-
|
|
261
|
-
Finally, you return the config and that is it!
|
|
262
|
-
|
|
263
|
-
##### Spread Syntax
|
|
264
|
-
|
|
265
|
-
Spread syntax (or the spread operator) is a feature in JavaScript that uses the dot notation **(...)** to spread elements from arrays, strings, or objects into various contexts.
|
|
266
|
-
|
|
267
|
-
We are going to use spread syntax to allow us to add data to existing arrays without losing the existing data. It is crucial to spread the existing data correctly – else this can cause adverse behavior and conflicts with Payload config and other plugins.
|
|
268
|
-
|
|
269
|
-
Let’s say you want to build a plugin that adds a new collection:
|
|
270
|
-
|
|
271
|
-
```ts
|
|
272
|
-
config.collections = [
|
|
273
|
-
...(config.collections || []),
|
|
274
|
-
// Add additional collections here
|
|
275
|
-
]
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
First we spread the `config.collections` to ensure that we don’t lose the existing collections, then you can add any additional collections just as you would in a regular payload config.
|
|
279
|
-
|
|
280
|
-
This same logic is applied to other properties like admin, hooks, globals:
|
|
281
|
-
|
|
282
|
-
```ts
|
|
283
|
-
config.globals = [
|
|
284
|
-
...(config.globals || []),
|
|
285
|
-
// Add additional globals here
|
|
286
|
-
]
|
|
287
|
-
|
|
288
|
-
config.hooks = {
|
|
289
|
-
...(incomingConfig.hooks || {}),
|
|
290
|
-
// Add additional hooks here
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
Some properties will be slightly different to extend, for instance the onInit property:
|
|
295
|
-
|
|
296
|
-
```ts
|
|
297
|
-
import { onInitExtension } from './onInitExtension' // example file
|
|
298
|
-
|
|
299
|
-
config.onInit = async payload => {
|
|
300
|
-
if (incomingConfig.onInit) await incomingConfig.onInit(payload)
|
|
301
|
-
// Add additional onInit code by defining an onInitExtension function
|
|
302
|
-
onInitExtension(pluginOptions, payload)
|
|
303
|
-
}
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
If you wish to add to the onInit, you must include the async/await. We don’t use spread syntax in this case, instead you must await the existing onInit before running additional functionality.
|
|
307
|
-
|
|
308
|
-
In the template, we have stubbed out a basic `onInitExtension` file that you can use, if not needed feel free to delete it.
|
|
309
|
-
|
|
310
|
-
##### File Aliasing
|
|
311
|
-
|
|
312
|
-
If your plugin uses packages or dependencies that are not browser compatible (fs, stripe, nodemailer, etc), you will need to alias them using your bundler to prevent getting errors in build.
|
|
189
|
+
#### Use in hooks
|
|
313
190
|
|
|
314
|
-
|
|
191
|
+
TODO: add documentation
|
|
315
192
|
|
|
316
|
-
|
|
193
|
+
myCollectionPrompt = ({source}) => {
|
|
317
194
|
|
|
318
|
-
|
|
195
|
+
source()
|
|
319
196
|
|
|
320
|
-
|
|
321
|
-
export interface PluginTypes {
|
|
322
|
-
/**
|
|
323
|
-
* Enable or disable plugin
|
|
324
|
-
* @default false
|
|
325
|
-
*/
|
|
326
|
-
enabled?: boolean
|
|
197
|
+
return
|
|
327
198
|
}
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
If possible, include JSDoc comments to describe the options and their types. This allows a developer to see details about the options in their editor.
|
|
331
|
-
|
|
332
|
-
##### Testing
|
|
333
|
-
|
|
334
|
-
Having a test suite for your plugin is essential to ensure quality and stability. Jest is a popular testing framework, widely used for testing JavaScript and particularly for applications built with React.
|
|
335
|
-
|
|
336
|
-
Jest organizes tests into test suites and cases. We recommend creating individual tests based on the expected behavior of your plugin from start to finish.
|
|
337
|
-
|
|
338
|
-
Writing tests with Jest is very straightforward and you can learn more about how it works in the [Jest documentation.](https://jestjs.io/)
|
|
339
|
-
|
|
340
|
-
For this template, we stubbed out `plugin.spec.ts` in the `dev` folder where you can write your tests.
|
|
341
|
-
|
|
342
|
-
```ts
|
|
343
|
-
describe('Plugin tests', () => {
|
|
344
|
-
// Create tests to ensure expected behavior from the plugin
|
|
345
|
-
it('some condition that must be met', () => {
|
|
346
|
-
// Write your test logic here
|
|
347
|
-
expect(...)
|
|
348
|
-
})
|
|
349
|
-
})
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
## Best practices
|
|
353
|
-
|
|
354
|
-
With this tutorial and the `payload-plugin-template`, you should have everything you need to start building your own plugin.
|
|
355
|
-
In addition to the setup, here are other best practices aim we follow:
|
|
356
|
-
|
|
357
|
-
* **Providing an enable / disable option:** For a better user experience, provide a way to disable the plugin without uninstalling it. This is especially important if your plugin adds additional webpack aliases, this will allow you to still let the webpack run to prevent errors.
|
|
358
|
-
* **Include tests in your GitHub CI workflow**: If you’ve configured tests for your package, integrate them into your workflow to run the tests each time you commit to the plugin repository. Learn more about [how to configure tests into your GitHub CI workflow.](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs)
|
|
359
|
-
* **Publish your finished plugin to NPM**: The best way to share and allow others to use your plugin once it is complete is to publish an NPM package. This process is straightforward and well documented, find out more [creating and publishing a NPM package here.](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages/).
|
|
360
|
-
* **Add payload-plugin topic tag**: Apply the tag **payload-plugin **to your GitHub repository. This will boost the visibility of your plugin and ensure it gets listed with [existing payload plugins](https://github.com/topics/payload-plugin).
|
|
361
|
-
* **Use [Semantic Versioning](https://semver.org/) (SemVar)** - With the SemVar system you release version numbers that reflect the nature of changes (major, minor, patch). Ensure all major versions reference their Payload compatibility.
|
|
362
|
-
|
|
363
|
-
# Questions
|
|
364
|
-
Please contact [Payload](mailto:dev@payloadcms.com) with any questions about using this plugin template.
|
package/dev/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CollectionConfig } from 'payload/types'
|
|
2
|
+
|
|
3
|
+
export const Media: CollectionConfig = {
|
|
4
|
+
slug: 'media',
|
|
5
|
+
access: {
|
|
6
|
+
read: () => true,
|
|
7
|
+
},
|
|
8
|
+
upload: {
|
|
9
|
+
staticURL: '/media',
|
|
10
|
+
staticDir: 'media',
|
|
11
|
+
imageSizes: [
|
|
12
|
+
{
|
|
13
|
+
name: 'thumbnail',
|
|
14
|
+
width: 400,
|
|
15
|
+
height: 300,
|
|
16
|
+
position: 'centre',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'card',
|
|
20
|
+
width: 768,
|
|
21
|
+
height: 1024,
|
|
22
|
+
position: 'centre',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'tablet',
|
|
26
|
+
width: 1024,
|
|
27
|
+
// By specifying `undefined` or leaving a height undefined,
|
|
28
|
+
// the image will be sized to a certain width,
|
|
29
|
+
// but it will retain its original aspect ratio
|
|
30
|
+
// and calculate a height automatically.
|
|
31
|
+
height: undefined,
|
|
32
|
+
position: 'centre',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
adminThumbnail: 'thumbnail',
|
|
36
|
+
mimeTypes: ['image/*'],
|
|
37
|
+
},
|
|
38
|
+
fields: [
|
|
39
|
+
{
|
|
40
|
+
name: 'alt',
|
|
41
|
+
type: 'text',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -2,6 +2,7 @@ import { buildConfig } from 'payload/config'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import Users from './collections/Users'
|
|
4
4
|
import Examples from './collections/Examples'
|
|
5
|
+
import { Media } from './collections/Media'
|
|
5
6
|
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
|
6
7
|
import { webpackBundler } from '@payloadcms/bundler-webpack'
|
|
7
8
|
//import { slateEditor } from '@payloadcms/richtext-slate'
|
|
@@ -39,7 +40,7 @@ export default buildConfig({
|
|
|
39
40
|
return newConfig
|
|
40
41
|
},
|
|
41
42
|
},
|
|
42
|
-
collections: [Examples, ExamplesWithVersions, Users],
|
|
43
|
+
collections: [Examples, ExamplesWithVersions, Users, Media],
|
|
43
44
|
//editor: slateEditor({}),
|
|
44
45
|
|
|
45
46
|
editor: lexicalEditor({
|
|
@@ -89,9 +90,25 @@ export default buildConfig({
|
|
|
89
90
|
'examples-with-versions': {
|
|
90
91
|
fields: ['title', 'longText', 'jsonContent'],
|
|
91
92
|
},
|
|
93
|
+
media: {
|
|
94
|
+
fields: ['alt'],
|
|
95
|
+
},
|
|
92
96
|
translations: {
|
|
97
|
+
access: () => true,
|
|
93
98
|
settings: {
|
|
94
99
|
model: 'gpt-4',
|
|
100
|
+
promptFunc: ({ messages, namespace }) => {
|
|
101
|
+
console.log('promptFunc', messages, namespace)
|
|
102
|
+
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
role: 'system',
|
|
106
|
+
content:
|
|
107
|
+
'Important: Add a smily face at the end of the message to make the AI more friendly. 😊',
|
|
108
|
+
},
|
|
109
|
+
...messages,
|
|
110
|
+
]
|
|
111
|
+
},
|
|
95
112
|
},
|
|
96
113
|
},
|
|
97
114
|
},
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.admins = void 0;
|
|
4
|
+
var checkRole_1 = require("./checkRole");
|
|
5
|
+
var admins = function (_a) {
|
|
6
|
+
var user = _a.req.user;
|
|
7
|
+
if (!user)
|
|
8
|
+
return false;
|
|
9
|
+
return (0, checkRole_1.checkRole)(['admin'], user);
|
|
10
|
+
};
|
|
11
|
+
exports.admins = admins;
|
|
12
|
+
//# sourceMappingURL=admins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admins.js","sourceRoot":"","sources":["../../src/access/admins.ts"],"names":[],"mappings":";;;AAEA,yCAAuC;AAKhC,IAAM,MAAM,GAAY,UAAC,EAAiB;QAAR,IAAI,cAAA;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAA;IACvB,OAAO,IAAA,qBAAS,EAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;AACnC,CAAC,CAAA;AAHY,QAAA,MAAM,UAGlB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adminsOrPublished = void 0;
|
|
4
|
+
var checkRole_1 = require("./checkRole");
|
|
5
|
+
var adminsOrPublished = function (_a) {
|
|
6
|
+
var user = _a.req.user;
|
|
7
|
+
if (user && (0, checkRole_1.checkRole)(['admin'], user)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
return {
|
|
12
|
+
_status: {
|
|
13
|
+
equals: 'published',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.adminsOrPublished = adminsOrPublished;
|
|
18
|
+
//# sourceMappingURL=adminsOrPublished.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adminsOrPublished.js","sourceRoot":"","sources":["../../src/access/adminsOrPublished.ts"],"names":[],"mappings":";;;AAEA,yCAAuC;AAEhC,IAAM,iBAAiB,GAAW,UAAC,EAAiB;QAAR,IAAI,cAAA;IACrD,IAAI,IAAI,IAAI,IAAA,qBAAS,EAAC,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE;QACtC,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAI,CAAA;IACX,OAAO;QACL,OAAO,EAAE;YACP,MAAM,EAAE,WAAW;SACpB;KACF,CAAA;AACH,CAAC,CAAA;AAXY,QAAA,iBAAiB,qBAW7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anyone.js","sourceRoot":"","sources":["../../src/access/anyone.ts"],"names":[],"mappings":";;;AAEO,IAAM,MAAM,GAAW,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAA;AAA3B,QAAA,MAAM,UAAqB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const checkRole: (allRoles: any, user?: any) => boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//import type { User } from '../../payload-types'
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.checkRole = void 0;
|
|
5
|
+
var checkRole = function (allRoles /* User['roles'] = [] */, user) {
|
|
6
|
+
if (user) {
|
|
7
|
+
if (allRoles.some(function (role) {
|
|
8
|
+
var _a;
|
|
9
|
+
return (_a = user === null || user === void 0 ? void 0 : user.roles) === null || _a === void 0 ? void 0 : _a.some(function (individualRole) {
|
|
10
|
+
return individualRole === role;
|
|
11
|
+
});
|
|
12
|
+
}))
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
exports.checkRole = checkRole;
|
|
18
|
+
//# sourceMappingURL=checkRole.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkRole.js","sourceRoot":"","sources":["../../src/access/checkRole.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAE1C,IAAM,SAAS,GAAG,UAAC,QAAa,CAAC,wBAAwB,EAAE,IAAU;IAC1E,IAAI,IAAI,EAAE;QACR,IACE,QAAQ,CAAC,IAAI,CAAC,UAAC,IAAS;;YACtB,OAAO,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,0CAAE,IAAI,CAAC,UAAC,cAAmB;gBAC3C,OAAO,cAAc,KAAK,IAAI,CAAA;YAChC,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC;YAEF,OAAO,IAAI,CAAA;KACd;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAbY,QAAA,SAAS,aAarB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateAccess: (req: any, res: any, pluginOptions: any) => any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateAccess = void 0;
|
|
4
|
+
var validateAccess = function (req, res, pluginOptions) {
|
|
5
|
+
var collectionOptions = pluginOptions.collections[req.collection.config.slug];
|
|
6
|
+
var accessControl = collectionOptions.access || req.collection.config.access.update;
|
|
7
|
+
var access = accessControl({ req: req });
|
|
8
|
+
if (!access) {
|
|
9
|
+
res.status(403).send({ error: 'not allowed' });
|
|
10
|
+
}
|
|
11
|
+
return access;
|
|
12
|
+
};
|
|
13
|
+
exports.validateAccess = validateAccess;
|
|
14
|
+
//# sourceMappingURL=validateAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAccess.js","sourceRoot":"","sources":["../../src/access/validateAccess.ts"],"names":[],"mappings":";;;AAEO,IAAM,cAAc,GAAG,UAAC,GAAQ,EAAE,GAAQ,EAAE,aAAkB;IACnE,IAAM,iBAAiB,GAAG,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAE/E,IAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAA;IACrF,IAAM,MAAM,GAAG,aAAa,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC,CAAA;IAErC,IAAI,CAAC,MAAM,EAAE;QACX,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAA;KAC/C;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAVY,QAAA,cAAc,kBAU1B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CollectionAfterChangeHook } from 'payload/types';
|
|
2
|
+
declare const aiCaptionHook: ({ collectionOptions, collection, pluginOptions, }: {
|
|
3
|
+
collectionOptions: any;
|
|
4
|
+
collection: object;
|
|
5
|
+
pluginOptions: any;
|
|
6
|
+
}, fallback?: string) => CollectionAfterChangeHook;
|
|
7
|
+
export default aiCaptionHook;
|
|
8
|
+
export declare function translateCollection({ req, doc, collection, previousDoc, context, collectionOptions, onlyMissing, codes, settings, sourceLanguage, }: any): Promise<void>;
|