@jrmc/adonis-attachment 3.2.0 → 3.2.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.
@@ -142,8 +142,17 @@ export class AttachmentManager {
142
142
  await attachment.getDisk().delete(attachment.path);
143
143
  if (attachment instanceof Attachment) {
144
144
  if (attachment.variants) {
145
- const variantPath = attachment.variants[0].folder;
146
- await attachment.getDisk().deleteAll(variantPath);
145
+ if (attachment.options?.disk == 'fs') {
146
+ const variantPath = attachment.variants[0].folder;
147
+ await attachment.getDisk().deleteAll(variantPath);
148
+ }
149
+ else {
150
+ for (const key in attachment.variants) {
151
+ if (Object.prototype.hasOwnProperty.call(attachment.variants, key)) {
152
+ await attachment.getDisk().delete(attachment.variants[key].path);
153
+ }
154
+ }
155
+ }
147
156
  }
148
157
  }
149
158
  }
@@ -64,8 +64,6 @@ export async function bufferToTempFile(input) {
64
64
  await fs.writeFile(tempFilePath, input);
65
65
  return tempFilePath;
66
66
  }
67
- // TODO
68
- // gestion des erreurs
69
67
  export async function streamToTempFile(input) {
70
68
  const folder = os.tmpdir();
71
69
  const tempFilePath = path.join(folder, `tempfile-${Date.now()}.tmp`);
@@ -71,6 +71,10 @@ export const afterSaveHook = async (instance) => {
71
71
  export const beforeDeleteHook = async (instance) => {
72
72
  const modelInstance = instance;
73
73
  const attachmentAttributeNames = getAttachmentAttributeNames(modelInstance);
74
+ /**
75
+ * create $attachments
76
+ */
77
+ modelInstance.$attachments = clone(defaultStateAttributeMixin);
74
78
  /**
75
79
  * Mark all attachments for deletion
76
80
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jrmc/adonis-attachment",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "type": "module",
5
5
  "description": "Turn any field on your Lucid model to an attachment data type",
6
6
  "engines": {