mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Use actual hash instead of randomly generated string
This commit is contained in:
parent
8f2c285cb0
commit
2ad3121494
@ -9,7 +9,16 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const toArray = require('stream-to-array');
|
const toArray = require('stream-to-array');
|
||||||
const uuid = require('uuid/v4');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
function niceHash(buffer) {
|
||||||
|
return crypto.createHash('sha256')
|
||||||
|
.update(buffer)
|
||||||
|
.digest('base64')
|
||||||
|
.replace(/=/g, '')
|
||||||
|
.replace(/\//g, '-')
|
||||||
|
.replace(/\+/, '_')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
bufferize: async files => {
|
bufferize: async files => {
|
||||||
@ -28,11 +37,13 @@ module.exports = {
|
|||||||
part => _.isBuffer(part) ? part : Buffer.from(part)
|
part => _.isBuffer(part) ? part : Buffer.from(part)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const buffer = Buffer.concat(buffers);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: stream.name,
|
name: stream.name,
|
||||||
hash: uuid().replace(/-/g, ''),
|
hash: niceHash(buffer),
|
||||||
ext: stream.name.split('.').length > 1 ? `.${_.last(stream.name.split('.'))}` : '',
|
ext: stream.name.split('.').length > 1 ? `.${_.last(stream.name.split('.'))}` : '',
|
||||||
buffer: Buffer.concat(buffers),
|
buffer,
|
||||||
mime: stream.type,
|
mime: stream.type,
|
||||||
size: (stream.size / 1000).toFixed(2)
|
size: (stream.size / 1000).toFixed(2)
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user