@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 CHANGED
@@ -11,5 +11,5 @@ custom/preview.vue
11
11
  custom/tsconfig.json
12
12
  custom/uploader.vue
13
13
 
14
- sent 46,947 bytes received 134 bytes 94,162.00 bytes/sec
14
+ sent 46,940 bytes received 134 bytes 94,148.00 bytes/sec
15
15
  total size is 46,465 speedup is 0.99
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
- this.rateLimiter = new RateLimiter((_a = this.options.generation.rateLimit) === null || _a === void 0 ? void 0 : _a.limit);
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, _c;
310
+ var _b;
309
311
  const { prompt, recordId } = body;
310
- if ((_b = this.options.generation.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
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((_c = this.resourceConfig.columns.find((column) => column.primaryKey)) === null || _c === void 0 ? void 0 : _c.name, recordId)]);
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.options.generation.rateLimit?.limit) {
352
+ if (this.rateLimiter) {
351
353
  // rate limit
352
354
  // const { error } = RateLimiter.checkRateLimit(
353
355
  // this.pluginInstanceId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",