@jrmc/adonis-attachment 3.2.0 → 3.2.2
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.
|
@@ -143,7 +143,12 @@ export class AttachmentManager {
|
|
|
143
143
|
if (attachment instanceof Attachment) {
|
|
144
144
|
if (attachment.variants) {
|
|
145
145
|
const variantPath = attachment.variants[0].folder;
|
|
146
|
-
await attachment.getDisk().deleteAll(variantPath);
|
|
146
|
+
await attachment.getDisk().deleteAll(variantPath); // not compatible Minio, necessary for fs as not to leave an empty directory
|
|
147
|
+
for (const key in attachment.variants) {
|
|
148
|
+
if (Object.prototype.hasOwnProperty.call(attachment.variants, key)) {
|
|
149
|
+
await attachment.getDisk().delete(attachment.variants[key].path);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import string from '@adonisjs/core/helpers/string';
|
|
1
2
|
import db from '@adonisjs/lucid/services/db';
|
|
2
3
|
import attachmentManager from '../services/main.js';
|
|
3
4
|
import * as errors from './errors.js';
|
|
@@ -32,7 +33,7 @@ export class ConverterManager {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
data[this.#attributeName] = JSON.stringify(attachment.toObject());
|
|
36
|
+
data[string.snakeCase(this.#attributeName)] = JSON.stringify(attachment.toObject());
|
|
36
37
|
const trx = await db.transaction();
|
|
37
38
|
trx.after('rollback', () => {
|
|
38
39
|
for (const variant of attachment.variants) {
|
|
@@ -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`);
|
package/build/src/utils/hooks.js
CHANGED
|
@@ -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
|
*/
|