import { CSVRow } from "./../../common/Objects/CSVRow" ; import { HTAccessConf } from "./../../culturize.conf" ; /**
 * This class manages the HTAccess file creation
 * process from a CSVRow[]
 */ export class ApacheConverter { private csvArray : CSVRow [ ] ; constructor param { CSVRow [ ] } csvArray constructor ( csvArray ) { this . csvArray = csvArray ; } returns public makeHTAccessFile ( ) { let data = this . getHeader ( ) + "\n\n" ; for ( const row of this . csvArray ) { if ( row . isValidAndEnabled ( ) ) { data += this . getRewriteRule ( row ) + "\n" ; } } return data ; } returns private getHeader ( ) { return "Options +FollowSymLinks\nRewriteEngine on" ; } param { CSVRow } row returns private getRewriteRule ( row ) { if ( row . pid === "" || row . url === "" ) { return "" ; } let options = "R=" + HTAccessConf . redirectionCode ; if ( HTAccessConf . caseInsensitiveRedirs ) { options += ",NC" ; } if ( HTAccessConf . noEscape ) { options += ",NE" ; } options += ",L" ; let redir = "" ; if ( row . docType !== "" ) { redir = row . docType + "/" + row . pid ; } else { redir = row . pid ; } const url = row . url . replace ( "%" , "\\%" ) ; return `RewriteRule ${ redir }$ ${ url } [${ options }]` ; } }