feat: access cached upload file + ignore common page extensions

This commit is contained in:
Nick
2019-05-14 00:53:19 -04:00
parent c2fe9621b9
commit 212286fc4a
5 changed files with 87 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
const qs = require('querystring')
const _ = require('lodash')
const crypto = require('crypto')
const path = require('path')
const localeSegmentRegex = /^[A-Z]{2}(-[A-Z]{2})?$/i
@@ -10,7 +11,7 @@ module.exports = {
/**
* Parse raw url path and make it safe
*/
parsePath (rawPath) {
parsePath (rawPath, opts = {}) {
let pathObj = {
locale: 'en',
path: 'home',
@@ -32,6 +33,17 @@ module.exports = {
pathObj.locale = pathParts[0]
pathParts.shift()
}
// Strip extension
if (opts.stripExt) {
const lastPart = _.last(pathParts)
if (lastPart.indexOf('.') > 0) {
pathParts.pop()
const lastPartMeta = path.parse(lastPart)
pathParts.push(lastPartMeta.name)
}
}
pathObj.path = _.join(pathParts, '/')
return pathObj
},