mirror of
https://github.com/frappe/books.git
synced 2024-12-23 19:39:07 +00:00
Cleanup styles and path name
This commit is contained in:
parent
7f3fb7713a
commit
8765c60ef3
@ -1,6 +1,7 @@
|
||||
const mkdirp = require('mkdirp');
|
||||
const fs = require('fs');
|
||||
const getDirName = require('path').dirname;
|
||||
const path = require('path');
|
||||
const getDirName = path.dirname;
|
||||
const os = require('os');
|
||||
const sharp = require('sharp');
|
||||
|
||||
@ -29,9 +30,9 @@ module.exports = {
|
||||
|
||||
return function (req, res, next) {
|
||||
|
||||
const file = (req.url).toString().replace(/\?.*/, "");
|
||||
const dimension = req.query.size || ""
|
||||
const staticFile = staticPath + file
|
||||
const filename = req.path.split(path.sep).slice(-1)[0]
|
||||
const dimension = req.query.size || null
|
||||
const staticFile = path.join(staticPath, filename)
|
||||
|
||||
fs.exists(staticFile, (exists) => {
|
||||
if (!exists) {
|
||||
@ -47,10 +48,17 @@ module.exports = {
|
||||
if (stats.isFile()) {
|
||||
|
||||
// Check if url has dimension parameters
|
||||
if(dimension != ""){
|
||||
const width = parseInt(dimension.split('x')[0])
|
||||
const height = parseInt(dimension.split('x')[1])
|
||||
const destination = staticPath + '/.thumbnails/' + width + 'x' + height + file.replace('/', '')
|
||||
if (dimension) {
|
||||
let [width, height] = dimension.split('x');
|
||||
width = +width;
|
||||
height = +height;
|
||||
const thumbnailPath = path.join(staticPath, 'thumbnails');
|
||||
const destination = path.join(thumbnailPath, `${width}x${height}-${filename}`)
|
||||
|
||||
// create thumbnails folder if not exists
|
||||
if (!fs.existsSync(thumbnailPath)) {
|
||||
fs.mkdirSync(thumbnailPath);
|
||||
}
|
||||
|
||||
// Check if thumbnail already present
|
||||
fs.existsSync(destination, (exists) => {
|
||||
@ -73,7 +81,7 @@ module.exports = {
|
||||
return res.sendFile(staticFile)
|
||||
}
|
||||
} else {
|
||||
console.log('File is not static.')
|
||||
// File is not static
|
||||
return next()
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user