@ -1,4 +1,4 @@
var myVersion = "0.7. 8 ", myProductName = "PagePark" ;
var myVersion = "0.7. 9 ", myProductName = "PagePark" ;
/ * T h e M I T L i c e n s e ( M I T )
Copyright ( c ) 2014 - 2017 Dave Winer
@ -47,7 +47,8 @@ var pageparkPrefs = {
flCacheTemplatesLocally : true , //6/17/17 by DW -- preserve the original behavior
urlDefaultMarkdownTemplate : "http://fargo.io/code/pagepark/defaultmarkdowntemplate.txt" , //6/17/17 by DW
urlDefaultOpmlTemplate : "http://fargo.io/code/pagepark/templates/opml/template.txt" , //6/17/17 by DW
urlDefaultErrorPage : "http://fargo.io/code/pagepark/prefs/error.html" //6/17/17 by DW
urlDefaultErrorPage : "http://fargo.io/code/pagepark/prefs/error.html" , //6/17/17 by DW
flUnicasePaths : false //11/7/17 by DW
} ;
var pageparkStats = {
ctStarts : 0 ,
@ -451,6 +452,60 @@ function handleHttpRequest (httpRequest, httpResponse) {
}
callback ( undefined ) ; //it's one of our domains, handle it here
}
function pathParse ( domainfolder , path , callback ) { //11/7/17 by DW
if ( pageparkPrefs . flUnicasePaths ) {
var nomad = domainfolder , steps , flSlashAtEnd = false ;
if ( utils . beginsWith ( path , "/" ) ) {
path = utils . stringDelete ( path , 1 , 1 ) ;
}
steps = path . split ( "/" ) ;
if ( steps [ steps . length - 1 ] . length == 0 ) {
steps . pop ( ) ;
flSlashAtEnd = true ;
}
function doStep ( ix ) {
if ( ix < steps . length ) {
var lowerstep = utils . stringLower ( steps [ ix ] ) , flfound = false ;
if ( ! utils . endsWith ( nomad , "/" ) ) {
nomad += "/" ;
}
fs . readdir ( nomad , function ( err , list ) {
if ( err ) {
callback ( err ) ;
}
else {
for ( var i = 0 ; i < list . length ; i ++ ) {
var fname = utils . stringLower ( list [ i ] ) ;
if ( fname == lowerstep ) {
nomad += list [ i ] ;
doStep ( ix + 1 ) ;
flfound = true ;
break ;
}
}
if ( ! flfound ) {
var err = {
} ;
callback ( err ) ;
}
}
} ) ;
}
else {
if ( flSlashAtEnd ) {
nomad += "/" ;
}
callback ( undefined , nomad ) ;
}
}
doStep ( 0 ) ;
}
else {
callback ( undefined , domainfolder + path ) ;
}
}
try {
var parsedUrl = urlpack . parse ( httpRequest . url , true ) , host , lowerhost , port , referrer ;
@ -533,7 +588,10 @@ function handleHttpRequest (httpRequest, httpResponse) {
}
else { //no mapping, we handle the request
getDomainFolder ( host , function ( domainfolder , actualhost ) { //might be a wildcard folder
var f = domainfolder + parsedUrl . pathname ;
pathParse ( domainfolder , parsedUrl . pathname , function ( err , f ) {
if ( f === undefined ) {
f = domainfolder + parsedUrl . pathname ;
}
if ( checkPathForIllegalChars ( f ) ) {
utils . sureFilePath ( domainsPath , function ( ) { //make sure domains folder exists
getConfigFile ( actualhost , function ( config ) { //get config.json, if it exists -- 1/18/15 by DW
@ -641,9 +699,10 @@ function handleHttpRequest (httpRequest, httpResponse) {
} ) ;
}
else {
httpRespond ( 5 00, "text/plain" , "The file name contains illegal characters." ) ;
httpRespond ( 4 00, "text/plain" , "The file name contains illegal characters." ) ;
}
} ) ;
} ) ;
}
} ) ;
}