|
|
|
@ -21,8 +21,8 @@ const configStore = require('./../config.js')
|
|
|
|
|
|
|
|
|
|
class Media {
|
|
|
|
|
|
|
|
|
|
constructor(path = NULL) {
|
|
|
|
|
this._path = path
|
|
|
|
|
constructor(dirPath = NULL) {
|
|
|
|
|
this._path = dirPath
|
|
|
|
|
this._DIR_ASSETS = '/assets/'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -43,11 +43,7 @@ class Media {
|
|
|
|
|
const filename = slugify(path.basename(src, extension))
|
|
|
|
|
|
|
|
|
|
// check for images in path
|
|
|
|
|
if (this._path && fs.existsSync(configStore.get('source') + this._path + '/' + src)) {
|
|
|
|
|
sourcePath = configStore.get('source') + this._path + '/' + src
|
|
|
|
|
} else {
|
|
|
|
|
sourcePath = configStore.get('source') + '/' + src
|
|
|
|
|
}
|
|
|
|
|
sourcePath = this._getSourcePath(src)
|
|
|
|
|
|
|
|
|
|
// getting sharp
|
|
|
|
|
const process = sharp(sourcePath)
|
|
|
|
@ -92,6 +88,30 @@ class Media {
|
|
|
|
|
return this._reduce(results)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get source path
|
|
|
|
|
*
|
|
|
|
|
* @param {String} src
|
|
|
|
|
* @return {String}
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
_getSourcePath(src) {
|
|
|
|
|
|
|
|
|
|
let sourcePath = configStore.get('source') + '/' + src
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(this._path)) {
|
|
|
|
|
if (fs.existsSync(configStore.get('source') + this._path[0] + '/' + src)) {
|
|
|
|
|
sourcePath = configStore.get('source') + this._path[0] + '/' + src
|
|
|
|
|
} else if (fs.existsSync(configStore.get('source') + this._path[1] + '/' + src)) {
|
|
|
|
|
sourcePath = configStore.get('source') + this._path[1] + '/' + src
|
|
|
|
|
}
|
|
|
|
|
} else if (this._path && fs.existsSync(configStore.get('source') + this._path + '/' + src)) {
|
|
|
|
|
sourcePath = configStore.get('source') + this._path + '/' + src
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sourcePath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* if only full is in results, reduce object to string
|
|
|
|
|
*
|
|
|
|
|