@adminforth/upload 2.3.5 → 2.3.6
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/build.log +1 -1
- package/dist/index.js +7 -5
- package/index.ts +3 -1
- package/package.json +1 -1
package/build.log
CHANGED
package/dist/index.js
CHANGED
|
@@ -13,13 +13,15 @@ import { RateLimiter } from "adminforth";
|
|
|
13
13
|
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
|
|
14
14
|
export default class UploadPlugin extends AdminForthPlugin {
|
|
15
15
|
constructor(options) {
|
|
16
|
-
var _a;
|
|
16
|
+
var _a, _b, _c;
|
|
17
17
|
super(options, import.meta.url);
|
|
18
18
|
this.options = options;
|
|
19
19
|
// for calcualting average time
|
|
20
20
|
this.totalCalls = 0;
|
|
21
21
|
this.totalDuration = 0;
|
|
22
|
-
|
|
22
|
+
if ((_b = (_a = this.options.generation) === null || _a === void 0 ? void 0 : _a.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
|
|
23
|
+
this.rateLimiter = new RateLimiter((_c = this.options.generation.rateLimit) === null || _c === void 0 ? void 0 : _c.limit);
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
26
|
instanceUniqueRepresentation(pluginOptions) {
|
|
25
27
|
return `${pluginOptions.pathColumnName}`;
|
|
@@ -305,9 +307,9 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
305
307
|
method: 'POST',
|
|
306
308
|
path: `/plugin/${this.pluginInstanceId}/generate_images`,
|
|
307
309
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
|
|
308
|
-
var _b
|
|
310
|
+
var _b;
|
|
309
311
|
const { prompt, recordId } = body;
|
|
310
|
-
if (
|
|
312
|
+
if (this.rateLimiter) {
|
|
311
313
|
// rate limit
|
|
312
314
|
// const { error } = RateLimiter.checkRateLimit(
|
|
313
315
|
// this.pluginInstanceId,
|
|
@@ -322,7 +324,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
322
324
|
if (this.options.generation.attachFiles) {
|
|
323
325
|
// TODO - does it require additional allowed action to check this record id has access to get the image?
|
|
324
326
|
// or should we mention in docs that user should do validation in method itself
|
|
325
|
-
const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ((
|
|
327
|
+
const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ((_b = this.resourceConfig.columns.find((column) => column.primaryKey)) === null || _b === void 0 ? void 0 : _b.name, recordId)]);
|
|
326
328
|
if (!record) {
|
|
327
329
|
return { error: `Record with id ${recordId} not found` };
|
|
328
330
|
}
|
package/index.ts
CHANGED
|
@@ -25,7 +25,9 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
25
25
|
// for calcualting average time
|
|
26
26
|
this.totalCalls = 0;
|
|
27
27
|
this.totalDuration = 0;
|
|
28
|
+
if (this.options.generation?.rateLimit?.limit) {
|
|
28
29
|
this.rateLimiter = new RateLimiter(this.options.generation.rateLimit?.limit)
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
instanceUniqueRepresentation(pluginOptions: any) : string {
|
|
@@ -347,7 +349,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
347
349
|
path: `/plugin/${this.pluginInstanceId}/generate_images`,
|
|
348
350
|
handler: async ({ body, adminUser, headers }) => {
|
|
349
351
|
const { prompt, recordId } = body;
|
|
350
|
-
if (this.
|
|
352
|
+
if (this.rateLimiter) {
|
|
351
353
|
// rate limit
|
|
352
354
|
// const { error } = RateLimiter.checkRateLimit(
|
|
353
355
|
// this.pluginInstanceId,
|