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

View File

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

View File

@ -84,7 +84,6 @@ describe('Upload plugin end to end tests', () => {
height: expect.any(Number),
url: expect.any(String),
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,
};