Move util out of service

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-03-06 18:41:48 +01:00
parent c567616ba8
commit 607e87431a
4 changed files with 14 additions and 6 deletions

View File

@ -12,6 +12,7 @@ const crypto = require('crypto');
const _ = require('lodash'); const _ = require('lodash');
const toArray = require('stream-to-array'); const toArray = require('stream-to-array');
const filenamify = require('filenamify'); const filenamify = require('filenamify');
const { bytesToKbytes } = require('../utils/file');
const randomSuffix = () => crypto.randomBytes(5).toString('hex'); const randomSuffix = () => crypto.randomBytes(5).toString('hex');
const generateFileName = name => { const generateFileName = name => {
@ -27,8 +28,6 @@ module.exports = {
const usedName = fileInfo.name || baseName; const usedName = fileInfo.name || baseName;
const imageManipulator = strapi.plugins.upload.services['image-manipulation'];
const entity = { const entity = {
name: usedName, name: usedName,
alternativeText: fileInfo.alternativeText, alternativeText: fileInfo.alternativeText,
@ -37,7 +36,8 @@ module.exports = {
hash: generateFileName(usedName), hash: generateFileName(usedName),
ext, ext,
mime: type, mime: type,
size: imageManipulator.bytesToKbytes(size), size: bytesToKbytes(size),
thumbnail: null,
}; };
const { refId, ref, source, field } = metas; const { refId, ref, source, field } = metas;

View File

@ -2,10 +2,9 @@
/** /**
* Image manipulation functions * Image manipulation functions
*/ */
const sharp = require('sharp'); const sharp = require('sharp');
const bytesToKbytes = bytes => Math.round((bytes / 1000) * 100) / 100; const { bytesToKbytes } = require('../utils/file');
const getMetadatas = buffer => const getMetadatas = buffer =>
sharp(buffer) sharp(buffer)

View File

@ -84,7 +84,6 @@ describe('Upload plugin end to end tests', () => {
height: expect.any(Number), height: expect.any(Number),
url: expect.any(String), url: expect.any(String),
provider: 'local', provider: 'local',
thumbnail: null,
}) })
); );
}); });

View File

@ -0,0 +1,10 @@
'use strict';
/**
* Utils file containing file treatment utils
*/
const bytesToKbytes = bytes => Math.round((bytes / 1000) * 100) / 100;
module.exports = {
bytesToKbytes,
};