@jrmc/adonis-attachment 3.2.1 → 3.2.3
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.
|
@@ -42,8 +42,8 @@ export class AttachmentManager {
|
|
|
42
42
|
async createFromFile(input) {
|
|
43
43
|
const attributes = {
|
|
44
44
|
originalName: input.clientName,
|
|
45
|
-
extname: input.extname,
|
|
46
|
-
mimeType: `${input.type}/${input.subtype}
|
|
45
|
+
extname: input.extname || '',
|
|
46
|
+
mimeType: input.type && input.subtype ? `${input.type}/${input.subtype}` : '',
|
|
47
47
|
size: input.size,
|
|
48
48
|
};
|
|
49
49
|
if (!input.tmpPath) {
|
|
@@ -142,15 +142,11 @@ export class AttachmentManager {
|
|
|
142
142
|
await attachment.getDisk().delete(attachment.path);
|
|
143
143
|
if (attachment instanceof Attachment) {
|
|
144
144
|
if (attachment.variants) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
}
|
|
145
|
+
const variantPath = attachment.variants[0].folder;
|
|
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);
|
|
154
150
|
}
|
|
155
151
|
}
|
|
156
152
|
}
|
|
@@ -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) {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
|
|
6
6
|
*/
|
|
7
|
+
import logger from '@adonisjs/core/services/logger';
|
|
7
8
|
import attachmentManager from '../../services/main.js';
|
|
8
9
|
import { getOptions } from './helpers.js';
|
|
9
10
|
import { ConverterManager } from '../converter_manager.js';
|
|
@@ -75,16 +76,19 @@ export async function generateVariants(modelInstance, attributeName) {
|
|
|
75
76
|
attachmentManager.queue.push({
|
|
76
77
|
name: `${modelInstance.constructor.name}-${attributeName}`,
|
|
77
78
|
async run() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
await converterManager.save();
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
throw new E_CANNOT_CREATE_VARIANT([err.message]);
|
|
87
|
-
}
|
|
79
|
+
const converterManager = new ConverterManager({
|
|
80
|
+
record: modelInstance,
|
|
81
|
+
attributeName,
|
|
82
|
+
});
|
|
83
|
+
await converterManager.save();
|
|
88
84
|
},
|
|
89
|
-
})
|
|
85
|
+
})
|
|
86
|
+
.onError = function (error) {
|
|
87
|
+
if (error.message) {
|
|
88
|
+
logger.error(error.message);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new E_CANNOT_CREATE_VARIANT([error]);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
90
94
|
}
|