@adminforth/rich-editor 1.0.15 → 1.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.
- package/dist/index.js +4 -2
- package/index.ts +6 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { AdminForthPlugin, Filters,
|
|
10
|
+
import { AdminForthPlugin, Filters, RateLimiter } from "adminforth";
|
|
11
11
|
import * as cheerio from 'cheerio';
|
|
12
12
|
// options:
|
|
13
13
|
// attachments: {
|
|
@@ -31,6 +31,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
var _a, _b, _c;
|
|
33
33
|
_super.modifyResourceConfig.call(this, adminforth, resourceConfig);
|
|
34
|
+
this.adminforth = adminforth;
|
|
34
35
|
const c = resourceConfig.columns.find(c => c.name === this.options.htmlFieldName);
|
|
35
36
|
if (!c) {
|
|
36
37
|
throw new Error(`Column ${this.options.htmlFieldName} not found in resource ${resourceConfig.label}`);
|
|
@@ -160,6 +161,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
validateConfigAfterDiscover(adminforth, resourceConfig) {
|
|
164
|
+
this.adminforth = adminforth;
|
|
163
165
|
// optional method where you can safely check field types after database discovery was performed
|
|
164
166
|
if (this.options.completion && this.options.completion.provider !== 'openai-chat-gpt') {
|
|
165
167
|
throw new Error(`Invalid provider ${this.options.completion.provider}`);
|
|
@@ -208,7 +210,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
208
210
|
const { record } = body;
|
|
209
211
|
if ((_b = this.options.completion.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
|
|
210
212
|
// rate limit
|
|
211
|
-
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_c = this.options.completion.rateLimit) === null || _c === void 0 ? void 0 : _c.limit, getClientIp(headers));
|
|
213
|
+
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_c = this.options.completion.rateLimit) === null || _c === void 0 ? void 0 : _c.limit, this.adminforth.auth.getClientIp(headers));
|
|
212
214
|
if (error) {
|
|
213
215
|
return {
|
|
214
216
|
completion: [],
|
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import type { IAdminForth, IHttpServer, AdminForthResource, AdminUser, AfterSaveFunction } from "adminforth";
|
|
3
3
|
import type { PluginOptions } from './types.js';
|
|
4
|
-
import { AdminForthPlugin, Filters,
|
|
4
|
+
import { AdminForthPlugin, Filters, RateLimiter } from "adminforth";
|
|
5
5
|
import * as cheerio from 'cheerio';
|
|
6
6
|
|
|
7
7
|
|
|
@@ -22,6 +22,8 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
22
22
|
activationOrder: number = 100000;
|
|
23
23
|
|
|
24
24
|
attachmentResource: AdminForthResource = undefined;
|
|
25
|
+
|
|
26
|
+
adminforth: IAdminForth;
|
|
25
27
|
|
|
26
28
|
constructor(options: PluginOptions) {
|
|
27
29
|
super(options, import.meta.url);
|
|
@@ -30,6 +32,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
30
32
|
|
|
31
33
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
32
34
|
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
35
|
+
this.adminforth = adminforth;
|
|
33
36
|
|
|
34
37
|
const c = resourceConfig.columns.find(c => c.name === this.options.htmlFieldName);
|
|
35
38
|
if (!c) {
|
|
@@ -204,6 +207,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
validateConfigAfterDiscover(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
210
|
+
this.adminforth = adminforth;
|
|
207
211
|
// optional method where you can safely check field types after database discovery was performed
|
|
208
212
|
if (this.options.completion && this.options.completion.provider !== 'openai-chat-gpt') {
|
|
209
213
|
throw new Error(`Invalid provider ${this.options.completion.provider}`);
|
|
@@ -265,7 +269,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
265
269
|
const { error } = RateLimiter.checkRateLimit(
|
|
266
270
|
this.pluginInstanceId,
|
|
267
271
|
this.options.completion.rateLimit?.limit,
|
|
268
|
-
getClientIp(headers),
|
|
272
|
+
this.adminforth.auth.getClientIp(headers),
|
|
269
273
|
);
|
|
270
274
|
if (error) {
|
|
271
275
|
return {
|