@jrmc/adonis-attachment 2.3.1 → 2.3.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.
- package/build/src/adapters/exif.js +1 -1
- package/build/src/attachments/attachment.js +1 -1
- package/build/src/attachments/attachment_base.js +1 -1
- package/build/src/converters/autodetect_converter.js +1 -1
- package/build/src/converters/document_thumbnail_converter.js +2 -2
- package/build/src/converters/pdf_thumbnail_converter.js +1 -1
- package/build/src/converters/video_thumbnail_converter.js +2 -3
- package/build/src/decorators/attachment.js +3 -1
- package/build/src/errors.d.ts +1 -5
- package/build/src/mixins/attachmentable.js +5 -9
- package/build/src/utils/default_values.js +1 -1
- package/build/src/utils/helpers.d.ts +1 -0
- package/build/src/utils/helpers.js +4 -0
- package/package.json +2 -2
|
@@ -18,7 +18,7 @@ export default class DocumentThumbnailConverter extends Converter {
|
|
|
18
18
|
const converter = new ImageConverter();
|
|
19
19
|
return await converter.handle({
|
|
20
20
|
input: outputBuffer,
|
|
21
|
-
options
|
|
21
|
+
options,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
return outputBuffer;
|
|
@@ -36,7 +36,7 @@ export default class DocumentThumbnailConverter extends Converter {
|
|
|
36
36
|
childProcessOptions: {
|
|
37
37
|
timeout: 60 * 1000,
|
|
38
38
|
},
|
|
39
|
-
binaryPaths
|
|
39
|
+
binaryPaths,
|
|
40
40
|
});
|
|
41
41
|
if (Buffer.isBuffer(input)) {
|
|
42
42
|
const output = await libreOfficeFileConverter.convert({
|
|
@@ -20,7 +20,7 @@ export default class VideoThumbnailConvert extends Converter {
|
|
|
20
20
|
const converter = new ImageConverter();
|
|
21
21
|
return await converter.handle({
|
|
22
22
|
input: filePath,
|
|
23
|
-
options
|
|
23
|
+
options,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
@@ -49,8 +49,7 @@ export default class VideoThumbnailConvert extends Converter {
|
|
|
49
49
|
count: 1,
|
|
50
50
|
filename,
|
|
51
51
|
folder,
|
|
52
|
-
})
|
|
53
|
-
.on('end', () => {
|
|
52
|
+
}).on('end', () => {
|
|
54
53
|
resolve(path.join(folder, filename));
|
|
55
54
|
});
|
|
56
55
|
});
|
|
@@ -16,7 +16,9 @@ export const attachment = (options) => {
|
|
|
16
16
|
const defaultOptions = {
|
|
17
17
|
meta: defaultConfig.meta !== undefined ? defaultConfig.meta : defaultOptionsDecorator.meta,
|
|
18
18
|
rename: defaultConfig.rename !== undefined ? defaultConfig.rename : defaultOptionsDecorator.rename,
|
|
19
|
-
preComputeUrl: defaultConfig.preComputeUrl !== undefined
|
|
19
|
+
preComputeUrl: defaultConfig.preComputeUrl !== undefined
|
|
20
|
+
? defaultConfig.preComputeUrl
|
|
21
|
+
: defaultOptionsDecorator.preComputeUrl,
|
|
20
22
|
};
|
|
21
23
|
if (!options || options?.meta === undefined) {
|
|
22
24
|
options.meta = defaultOptions.meta;
|
package/build/src/errors.d.ts
CHANGED
|
@@ -23,11 +23,7 @@ export declare const E_CANNOT_DELETE_FILE: new (args: [key: string], options?: E
|
|
|
23
23
|
/**
|
|
24
24
|
* Unable to set file visibility
|
|
25
25
|
*/
|
|
26
|
-
export declare const E_CANNOT_SET_VISIBILITY: new (args: [key: string], options?: ErrorOptions) => import(
|
|
27
|
-
/**
|
|
28
|
-
* Unable to read file
|
|
29
|
-
*/
|
|
30
|
-
"@adonisjs/core/exceptions").Exception;
|
|
26
|
+
export declare const E_CANNOT_SET_VISIBILITY: new (args: [key: string], options?: ErrorOptions) => import("@adonisjs/core/exceptions").Exception;
|
|
31
27
|
/**
|
|
32
28
|
* Unable to generate URL for a file
|
|
33
29
|
*/
|
|
@@ -10,9 +10,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
10
10
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
11
11
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
12
12
|
};
|
|
13
|
-
import { beforeSave, afterSave, beforeDelete, afterFind, afterFetch, afterPaginate } from '@adonisjs/lucid/orm';
|
|
14
|
-
import { persistAttachment, commit, rollback, generateVariants, preComputeUrl } from '../utils/actions.js';
|
|
15
|
-
import { clone, getAttachmentAttributeNames } from '../utils/helpers.js';
|
|
13
|
+
import { beforeSave, afterSave, beforeDelete, afterFind, afterFetch, afterPaginate, } from '@adonisjs/lucid/orm';
|
|
14
|
+
import { persistAttachment, commit, rollback, generateVariants, preComputeUrl, } from '../utils/actions.js';
|
|
15
|
+
import { clone, getAttachmentAttributeNames, getDirtyAttachmentAttributeNames, } from '../utils/helpers.js';
|
|
16
16
|
import { defaultStateAttributeMixin } from '../utils/default_values.js';
|
|
17
17
|
export const Attachmentable = (superclass) => {
|
|
18
18
|
class ModelWithAttachment extends superclass {
|
|
@@ -27,7 +27,7 @@ export const Attachmentable = (superclass) => {
|
|
|
27
27
|
await Promise.all(modelInstances.map((row) => this.afterFindHook(row)));
|
|
28
28
|
}
|
|
29
29
|
static async beforeSaveHook(modelInstance) {
|
|
30
|
-
const attachmentAttributeNames =
|
|
30
|
+
const attachmentAttributeNames = getDirtyAttachmentAttributeNames(modelInstance);
|
|
31
31
|
/**
|
|
32
32
|
* Empty previous $attachments
|
|
33
33
|
*/
|
|
@@ -35,11 +35,7 @@ export const Attachmentable = (superclass) => {
|
|
|
35
35
|
/**
|
|
36
36
|
* Set attributes Attachment type modified
|
|
37
37
|
*/
|
|
38
|
-
attachmentAttributeNames.forEach((attributeName) =>
|
|
39
|
-
if (modelInstance.$dirty[attributeName]) {
|
|
40
|
-
modelInstance.$attachments.attributesModified.push(attributeName);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
38
|
+
attachmentAttributeNames.forEach((attributeName) => modelInstance.$attachments.attributesModified.push(attributeName));
|
|
43
39
|
/**
|
|
44
40
|
* Persist attachments before saving the model to the database. This
|
|
45
41
|
* way if file saving fails we will not write anything to the
|
|
@@ -8,6 +8,7 @@ import type { LucidOptions } from '../types/attachment.js';
|
|
|
8
8
|
import type { Input } from '../types/input.js';
|
|
9
9
|
import type { ModelWithAttachment } from '../types/mixin.js';
|
|
10
10
|
export declare function getAttachmentAttributeNames(modelInstance: ModelWithAttachment): string[];
|
|
11
|
+
export declare function getDirtyAttachmentAttributeNames(modelInstance: ModelWithAttachment): string[];
|
|
11
12
|
export declare function getOptions(modelInstance: ModelWithAttachment, attributeName: string): LucidOptions;
|
|
12
13
|
export declare function createAttachmentAttributes(input: Input, name?: string): Promise<{
|
|
13
14
|
originalName: string;
|
|
@@ -16,6 +16,10 @@ import { optionsSym } from './symbols.js';
|
|
|
16
16
|
export function getAttachmentAttributeNames(modelInstance) {
|
|
17
17
|
return Object.keys(modelInstance.$attributes).filter((attr) => modelInstance.$attributes[attr] instanceof Attachment);
|
|
18
18
|
}
|
|
19
|
+
export function getDirtyAttachmentAttributeNames(modelInstance) {
|
|
20
|
+
return Object.keys(modelInstance.$dirty).filter((attr) => modelInstance.$dirty[attr] instanceof Attachment ||
|
|
21
|
+
modelInstance.$original[attr] instanceof Attachment);
|
|
22
|
+
}
|
|
19
23
|
export function getOptions(modelInstance, attributeName) {
|
|
20
24
|
return modelInstance.constructor.prototype[optionsSym]?.[attributeName];
|
|
21
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jrmc/adonis-attachment",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Turn any field on your Lucid model to an attachment data type",
|
|
6
6
|
"engines": {
|
|
@@ -86,4 +86,4 @@
|
|
|
86
86
|
"volta": {
|
|
87
87
|
"node": "20.17.0"
|
|
88
88
|
}
|
|
89
|
-
}
|
|
89
|
+
}
|