mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 01:02:51 +00:00
Move filename prefix to configurable item in config/default.json
This commit is contained in:
14
server.js
14
server.js
@@ -111,17 +111,18 @@ app.get('/source/:id', (req, res)=>{
|
|||||||
|
|
||||||
//Download brew source page
|
//Download brew source page
|
||||||
app.get('/download/:id', (req, res)=>{
|
app.get('/download/:id', (req, res)=>{
|
||||||
|
const prefix = config.get('filename-prefix');
|
||||||
if(req.params.id.length > 12) {
|
if(req.params.id.length > 12) {
|
||||||
const googleId = req.params.id.slice(0, -12);
|
const googleId = req.params.id.slice(0, -12);
|
||||||
const shareId = req.params.id.slice(-12);
|
const shareId = req.params.id.slice(-12);
|
||||||
GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share')
|
GoogleActions.readFileMetadata(config.get('google_api_key'), googleId, shareId, 'share')
|
||||||
.then((brew)=>{
|
.then((brew)=>{
|
||||||
let fileName = sanitizeFilename(title).replaceAll(' ', '-');
|
let fileName = sanitizeFilename(prefix + title).replaceAll(' ', '-');
|
||||||
if(!fileName || !fileName.length) { fileName = 'Untitled-Brew'; };
|
if(!title || !title.length) { fileName = prefix + 'Untitled-Brew'; };
|
||||||
res.set({
|
res.set({
|
||||||
'Cache-Control' : 'no-cache',
|
'Cache-Control' : 'no-cache',
|
||||||
'Content-Type' : 'text/plain',
|
'Content-Type' : 'text/plain',
|
||||||
'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
|
'Content-Disposition' : `attachment; filename="${fileName}.txt"`
|
||||||
});
|
});
|
||||||
res.status(200).send(brew.text);
|
res.status(200).send(brew.text);
|
||||||
})
|
})
|
||||||
@@ -132,12 +133,13 @@ app.get('/download/:id', (req, res)=>{
|
|||||||
} else {
|
} else {
|
||||||
HomebrewModel.get({ shareId: req.params.id })
|
HomebrewModel.get({ shareId: req.params.id })
|
||||||
.then((brew)=>{
|
.then((brew)=>{
|
||||||
let fileName = sanitizeFilename(title).replaceAll(' ', '-');
|
let fileName = sanitizeFilename(prefix + title).replaceAll(' ', '-');
|
||||||
if(!fileName || !fileName.length) { fileName = 'Untitled-Brew'; };
|
console.log(title);
|
||||||
|
if(!title || !title.length) { fileName = prefix + 'Untitled-Brew'; };
|
||||||
res.set({
|
res.set({
|
||||||
'Cache-Control' : 'no-cache',
|
'Cache-Control' : 'no-cache',
|
||||||
'Content-Type' : 'text/plain',
|
'Content-Type' : 'text/plain',
|
||||||
'Content-Disposition' : `attachment; filename="HomeBrewery-${fileName}.txt"`
|
'Content-Disposition' : `attachment; filename="${fileName}.txt"`
|
||||||
});
|
});
|
||||||
res.status(200).send(brew.text);
|
res.status(200).send(brew.text);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user