mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
Move util out of service
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
c567616ba8
commit
607e87431a
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -84,7 +84,6 @@ describe('Upload plugin end to end tests', () => {
|
||||
height: expect.any(Number),
|
||||
url: expect.any(String),
|
||||
provider: 'local',
|
||||
thumbnail: null,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
10
packages/strapi-plugin-upload/utils/file.js
Normal file
10
packages/strapi-plugin-upload/utils/file.js
Normal 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,
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user