mirror of
https://github.com/strapi/strapi.git
synced 2025-11-25 22:51:33 +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 _ = 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;
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
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