mirror of
https://github.com/Metastem/wikiless
synced 2024-12-06 19:16:58 +01:00
fix download as PDF feature (#9)
This commit is contained in:
+4
-2
@@ -106,11 +106,13 @@ module.exports = (app, utils) => {
|
||||
return res.redirect(back)
|
||||
})
|
||||
|
||||
app.post('/wiki/Special::DownloadAsPdf', (req, res, next) => {
|
||||
app.post(/DownloadAsPdf/, (req, res, next) => {
|
||||
if(!req.body.page) {
|
||||
return res.redirect('/')
|
||||
}
|
||||
|
||||
return res.redirect(`/w/index.php?title=Special%3ADownloadAsPdf&page=${req.body.page}&action=redirect-to-electron`)
|
||||
let lang = req.body.lang || req.cookies.default_lang || config.default_lang
|
||||
|
||||
return res.redirect(`/w/index.php?title=Special%3ADownloadAsPdf&page=${req.body.page}&action=redirect-to-electron&lang=${lang}`)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -171,6 +171,18 @@ module.exports = function(redis) {
|
||||
const wiki_href_regx = /(href=\"(https:|http:|)\/\/([A-z.-]+\.)?(wikipedia.org|wikimedia.org|wikidata.org|mediawiki.org))/gm
|
||||
data.html = data.html.replace(wiki_href_regx, `href="${protocol}${config.domain}`)
|
||||
|
||||
/**
|
||||
* If we are on DownloadAsPdf page, we have to inject a input which
|
||||
* holds the language value. Without this input, we can't access the
|
||||
* language (not avail from the POST data).
|
||||
* See more on https://codeberg.org/orenom/Wikiless/issues/9
|
||||
*/
|
||||
if(url.includes('%3ADownloadAsPdf')) {
|
||||
let lang_input = `<input type='hidden' name='lang' value='${lang}'>`
|
||||
let replace_str = `<input type='hidden' name='page'`
|
||||
data.html = data.html.replace(replace_str, `${lang_input}${replace_str}`)
|
||||
}
|
||||
|
||||
redis.setex(url, config.setexs.wikipage, data.html, (error) => {
|
||||
if(error) {
|
||||
console.log(`Error setting the ${url} key to Redis. Error: ${error}`)
|
||||
|
||||
Reference in New Issue
Block a user