@adminforth/upload 2.3.3 → 2.3.5

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,954 bytes received 134 bytes 94,176.00 bytes/sec
14
+ sent 46,947 bytes received 134 bytes 94,162.00 bytes/sec
15
15
  total size is 46,465 speedup is 0.99
package/dist/index.js CHANGED
@@ -13,11 +13,13 @@ 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
17
  super(options, import.meta.url);
17
18
  this.options = options;
18
19
  // for calcualting average time
19
20
  this.totalCalls = 0;
20
21
  this.totalDuration = 0;
22
+ this.rateLimiter = new RateLimiter((_a = this.options.generation.rateLimit) === null || _a === void 0 ? void 0 : _a.limit);
21
23
  }
22
24
  instanceUniqueRepresentation(pluginOptions) {
23
25
  return `${pluginOptions.pathColumnName}`;
@@ -303,7 +305,7 @@ export default class UploadPlugin extends AdminForthPlugin {
303
305
  method: 'POST',
304
306
  path: `/plugin/${this.pluginInstanceId}/generate_images`,
305
307
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
306
- var _b, _c, _d;
308
+ var _b, _c;
307
309
  const { prompt, recordId } = body;
308
310
  if ((_b = this.options.generation.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
309
311
  // rate limit
@@ -312,8 +314,7 @@ export default class UploadPlugin extends AdminForthPlugin {
312
314
  // this.options.generation.rateLimit?.limit,
313
315
  // this.adminforth.auth.getClientIp(headers),
314
316
  // );
315
- const rateLimiter = new RateLimiter((_c = this.options.generation.rateLimit) === null || _c === void 0 ? void 0 : _c.limit);
316
- if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
317
+ if (!(yield this.rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`))) {
317
318
  return { error: this.options.generation.rateLimit.errorMessage };
318
319
  }
319
320
  }
@@ -321,7 +322,7 @@ export default class UploadPlugin extends AdminForthPlugin {
321
322
  if (this.options.generation.attachFiles) {
322
323
  // TODO - does it require additional allowed action to check this record id has access to get the image?
323
324
  // or should we mention in docs that user should do validation in method itself
324
- const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ((_d = this.resourceConfig.columns.find((column) => column.primaryKey)) === null || _d === void 0 ? void 0 : _d.name, recordId)]);
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)]);
325
326
  if (!record) {
326
327
  return { error: `Record with id ${recordId} not found` };
327
328
  }
package/index.ts CHANGED
@@ -16,6 +16,8 @@ export default class UploadPlugin extends AdminForthPlugin {
16
16
 
17
17
  resourceConfig: AdminForthResource;
18
18
 
19
+ rateLimiter: RateLimiter;
20
+
19
21
  constructor(options: PluginOptions) {
20
22
  super(options, import.meta.url);
21
23
  this.options = options;
@@ -23,6 +25,7 @@ export default class UploadPlugin extends AdminForthPlugin {
23
25
  // for calcualting average time
24
26
  this.totalCalls = 0;
25
27
  this.totalDuration = 0;
28
+ this.rateLimiter = new RateLimiter(this.options.generation.rateLimit?.limit)
26
29
  }
27
30
 
28
31
  instanceUniqueRepresentation(pluginOptions: any) : string {
@@ -351,8 +354,7 @@ export default class UploadPlugin extends AdminForthPlugin {
351
354
  // this.options.generation.rateLimit?.limit,
352
355
  // this.adminforth.auth.getClientIp(headers),
353
356
  // );
354
- const rateLimiter = new RateLimiter(this.options.generation.rateLimit?.limit);
355
- if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
357
+ if (!await this.rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
356
358
  return { error: this.options.generation.rateLimit.errorMessage };
357
359
  }
358
360
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@aws-sdk/client-s3": "^3.629.0",
24
24
  "@aws-sdk/s3-request-presigner": "^3.629.0",
25
- "adminforth": "^2.4.0-next.222"
25
+ "adminforth": "^2.4.0-next.237"
26
26
  },
27
27
  "keywords": [
28
28
  "adminforth",