@empty-complete-org/medusa-product-attributes 0.14.0 → 0.14.1

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.
@@ -372,15 +372,19 @@ const ProductAttributeValuesWidget = ({
372
372
  const attrId = attr.id;
373
373
  setUploadingId(attrId);
374
374
  try {
375
- const dot = file.name.lastIndexOf(".");
376
- const ext = dot > -1 ? file.name.slice(dot) : "";
377
- const renamed = new File(
378
- [file],
379
- `${productHandle}_${attr.key}${ext}`,
380
- { type: file.type }
381
- );
375
+ const isImage = file.type.startsWith("image/");
376
+ let toUpload = file;
377
+ if (isImage) {
378
+ const dot = file.name.lastIndexOf(".");
379
+ const ext = dot > -1 ? file.name.slice(dot) : "";
380
+ toUpload = new File(
381
+ [file],
382
+ `${productHandle}_${attr.key}${ext}`,
383
+ { type: file.type }
384
+ );
385
+ }
382
386
  const formData = new FormData();
383
- formData.append("files", renamed);
387
+ formData.append("files", toUpload);
384
388
  const response = await fetch(`/admin/uploads`, {
385
389
  method: "POST",
386
390
  credentials: "include",
@@ -352,15 +352,19 @@ const ProductAttributeValuesWidget = ({
352
352
  const attrId = attr.id;
353
353
  setUploadingId(attrId);
354
354
  try {
355
- const dot = file.name.lastIndexOf(".");
356
- const ext = dot > -1 ? file.name.slice(dot) : "";
357
- const renamed = new File(
358
- [file],
359
- `${productHandle}_${attr.key}${ext}`,
360
- { type: file.type }
361
- );
355
+ const isImage = file.type.startsWith("image/");
356
+ let toUpload = file;
357
+ if (isImage) {
358
+ const dot = file.name.lastIndexOf(".");
359
+ const ext = dot > -1 ? file.name.slice(dot) : "";
360
+ toUpload = new File(
361
+ [file],
362
+ `${productHandle}_${attr.key}${ext}`,
363
+ { type: file.type }
364
+ );
365
+ }
362
366
  const formData = new FormData();
363
- formData.append("files", renamed);
367
+ formData.append("files", toUpload);
364
368
  const response = await fetch(`/admin/uploads`, {
365
369
  method: "POST",
366
370
  credentials: "include",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empty-complete-org/medusa-product-attributes",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Custom attributes module for Medusa v2 with support for text, number, file types and units of measurement",
5
5
  "author": "empty-complete",
6
6
  "license": "MIT",