@jrmc/adonis-attachment 3.2.2 → 3.2.4
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) {
|
|
@@ -30,6 +30,10 @@ export default class PdfThumbnailConverter extends Converter {
|
|
|
30
30
|
binPath = this.binPaths.pdftocairoBasePath;
|
|
31
31
|
}
|
|
32
32
|
const poppler = new Poppler(binPath);
|
|
33
|
+
const pdfInfo = await poppler.pdfInfo(input);
|
|
34
|
+
const pagesMatch = pdfInfo.match(/Pages:\s*(\d+)/);
|
|
35
|
+
const pageCount = pagesMatch ? parseInt(pagesMatch[1]) : 1;
|
|
36
|
+
const pageNumberFormat = '0'.repeat(String(pageCount).length - 1);
|
|
33
37
|
const options = {
|
|
34
38
|
// firstPageToConvert: 1,
|
|
35
39
|
lastPageToConvert: 1,
|
|
@@ -37,6 +41,6 @@ export default class PdfThumbnailConverter extends Converter {
|
|
|
37
41
|
};
|
|
38
42
|
const filePath = path.join(os.tmpdir(), cuid());
|
|
39
43
|
await poppler.pdfToCairo(input, filePath, options);
|
|
40
|
-
return filePath
|
|
44
|
+
return `${filePath}-${pageNumberFormat}1.jpg`;
|
|
41
45
|
}
|
|
42
46
|
}
|
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jrmc/adonis-attachment",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Turn any field on your Lucid model to an attachment data type",
|
|
6
6
|
"engines": {
|
|
@@ -114,8 +114,7 @@
|
|
|
114
114
|
]
|
|
115
115
|
},
|
|
116
116
|
"publishConfig": {
|
|
117
|
-
"access": "public"
|
|
118
|
-
"tag": "latest"
|
|
117
|
+
"access": "public"
|
|
119
118
|
},
|
|
120
119
|
"volta": {
|
|
121
120
|
"node": "20.17.0"
|