@adminforth/rich-editor 1.0.14 → 1.0.15
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 +6 -6
- package/index.ts +6 -6
- 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, getClientIp, RateLimiter } from "adminforth";
|
|
11
11
|
import * as cheerio from 'cheerio';
|
|
12
12
|
// options:
|
|
13
13
|
// attachments: {
|
|
@@ -127,11 +127,11 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
127
127
|
// field was not changed, do nothing
|
|
128
128
|
return { ok: true };
|
|
129
129
|
}
|
|
130
|
-
const
|
|
130
|
+
const existingAparts = yield adminforth.resource(this.options.attachments.attachmentResource).list([
|
|
131
131
|
Filters.EQ(this.options.attachments.attachmentRecordIdFieldName, recordId),
|
|
132
132
|
Filters.EQ(this.options.attachments.attachmentResourceIdFieldName, resourceConfig.resourceId)
|
|
133
133
|
]);
|
|
134
|
-
const existingS3Paths =
|
|
134
|
+
const existingS3Paths = existingAparts.map((a) => a[this.options.attachments.attachmentFieldName]);
|
|
135
135
|
const newS3Paths = getAttachmentPathes(record[this.options.htmlFieldName]);
|
|
136
136
|
process.env.HEAVY_DEBUG && console.log('📸 Existing s3Paths (from db)', existingS3Paths);
|
|
137
137
|
process.env.HEAVY_DEBUG && console.log('📸 Found new s3Paths (from text)', newS3Paths);
|
|
@@ -147,11 +147,11 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
147
147
|
}));
|
|
148
148
|
// after delete we need to delete all attachments
|
|
149
149
|
resourceConfig.hooks.delete.afterSave.push((_f) => __awaiter(this, [_f], void 0, function* ({ record, adminUser }) {
|
|
150
|
-
const
|
|
150
|
+
const existingAparts = yield adminforth.resource(this.options.attachments.attachmentResource).list([
|
|
151
151
|
Filters.EQ(this.options.attachments.attachmentRecordIdFieldName, record[editorRecordPkField.name]),
|
|
152
152
|
Filters.EQ(this.options.attachments.attachmentResourceIdFieldName, resourceConfig.resourceId)
|
|
153
153
|
]);
|
|
154
|
-
const existingS3Paths =
|
|
154
|
+
const existingS3Paths = existingAparts.map((a) => a[this.options.attachments.attachmentFieldName]);
|
|
155
155
|
process.env.HEAVY_DEBUG && console.log('📸 Found s3Paths to delete', existingS3Paths);
|
|
156
156
|
yield deleteAttachmentRecords(adminforth, this.options, existingS3Paths, adminUser);
|
|
157
157
|
return { ok: true };
|
|
@@ -208,7 +208,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
208
208
|
const { record } = body;
|
|
209
209
|
if ((_b = this.options.completion.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
|
|
210
210
|
// rate limit
|
|
211
|
-
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_c = this.options.completion.rateLimit) === null || _c === void 0 ? void 0 : _c.limit,
|
|
211
|
+
const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_c = this.options.completion.rateLimit) === null || _c === void 0 ? void 0 : _c.limit, getClientIp(headers));
|
|
212
212
|
if (error) {
|
|
213
213
|
return {
|
|
214
214
|
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, getClientIp, RateLimiter } from "adminforth";
|
|
5
5
|
import * as cheerio from 'cheerio';
|
|
6
6
|
|
|
7
7
|
|
|
@@ -161,11 +161,11 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
161
161
|
// field was not changed, do nothing
|
|
162
162
|
return { ok: true };
|
|
163
163
|
}
|
|
164
|
-
const
|
|
164
|
+
const existingAparts = await adminforth.resource(this.options.attachments.attachmentResource).list([
|
|
165
165
|
Filters.EQ(this.options.attachments.attachmentRecordIdFieldName, recordId),
|
|
166
166
|
Filters.EQ(this.options.attachments.attachmentResourceIdFieldName, resourceConfig.resourceId)
|
|
167
167
|
]);
|
|
168
|
-
const existingS3Paths =
|
|
168
|
+
const existingS3Paths = existingAparts.map((a: any) => a[this.options.attachments.attachmentFieldName]);
|
|
169
169
|
const newS3Paths = getAttachmentPathes(record[this.options.htmlFieldName]);
|
|
170
170
|
process.env.HEAVY_DEBUG && console.log('📸 Existing s3Paths (from db)', existingS3Paths)
|
|
171
171
|
process.env.HEAVY_DEBUG && console.log('📸 Found new s3Paths (from text)', newS3Paths);
|
|
@@ -187,13 +187,13 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
187
187
|
// after delete we need to delete all attachments
|
|
188
188
|
(resourceConfig.hooks.delete.afterSave as Array<AfterSaveFunction>).push(
|
|
189
189
|
async ({ record, adminUser }: { record: any, adminUser: AdminUser }) => {
|
|
190
|
-
const
|
|
190
|
+
const existingAparts = await adminforth.resource(this.options.attachments.attachmentResource).list(
|
|
191
191
|
[
|
|
192
192
|
Filters.EQ(this.options.attachments.attachmentRecordIdFieldName, record[editorRecordPkField.name]),
|
|
193
193
|
Filters.EQ(this.options.attachments.attachmentResourceIdFieldName, resourceConfig.resourceId)
|
|
194
194
|
]
|
|
195
195
|
);
|
|
196
|
-
const existingS3Paths =
|
|
196
|
+
const existingS3Paths = existingAparts.map((a: any) => a[this.options.attachments.attachmentFieldName]);
|
|
197
197
|
process.env.HEAVY_DEBUG && console.log('📸 Found s3Paths to delete', existingS3Paths);
|
|
198
198
|
await deleteAttachmentRecords(adminforth, this.options, existingS3Paths, adminUser);
|
|
199
199
|
|
|
@@ -265,7 +265,7 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
265
265
|
const { error } = RateLimiter.checkRateLimit(
|
|
266
266
|
this.pluginInstanceId,
|
|
267
267
|
this.options.completion.rateLimit?.limit,
|
|
268
|
-
|
|
268
|
+
getClientIp(headers),
|
|
269
269
|
);
|
|
270
270
|
if (error) {
|
|
271
271
|
return {
|