0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +00:00

Changed uses of the 'raw' brew access type to 'view' and update uses of mergeBrewText as a result

#1838
This commit is contained in:
Charlie Humphreys
2021-11-25 22:44:59 -06:00
parent ef433bbbe2
commit 5ffdd022c2
2 changed files with 8 additions and 6 deletions

View File

@@ -12,7 +12,7 @@ const serveCompressedStaticAssets = require('./server/static-assets.mv.js');
const sanitizeFilename = require('sanitize-filename');
const asyncHandler = require('express-async-handler');
const brewAccessTypes = ['edit', 'share', 'raw'];
const brewAccessTypes = ['edit', 'share', 'raw', 'view'];
//Get the brew object from the HB database or Google Drive
const getBrewFromId = asyncHandler(async (id, accessType)=>{
@@ -167,10 +167,10 @@ app.get('/faq', async (req, res, next)=>{
//Source page
app.get('/source/:id', asyncHandler(async (req, res)=>{
const brew = await getBrewFromId(req.params.id, 'raw');
const brew = await getBrewFromId(req.params.id, 'view');
const replaceStrings = { '&': '&amp;', '<': '&lt;', '>': '&gt;' };
let text = brewUtils.mergeBrewText(brew, { metadata: true, fullMetadata: true });
let text = brewUtils.mergeBrewText(brew, { style: true, metadata: true, fullMetadata: true });
for (const replaceStr in replaceStrings) {
text = text.replaceAll(replaceStr, replaceStrings[replaceStr]);
}
@@ -180,7 +180,7 @@ app.get('/source/:id', asyncHandler(async (req, res)=>{
//Download brew source page
app.get('/download/:id', asyncHandler(async (req, res)=>{
const brew = await getBrewFromId(req.params.id, 'raw');
const brew = await getBrewFromId(req.params.id, 'view');
const prefix = 'HB - ';
let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', '');
@@ -190,7 +190,8 @@ app.get('/download/:id', asyncHandler(async (req, res)=>{
'Content-Type' : 'text/plain',
'Content-Disposition' : `attachment; filename="${fileName}.txt"`
});
res.status(200).send(brewUtils.mergeBrewText(brew, { metadata: true, fullMetadata: true }));
const text = brewUtils.mergeBrewText(brew, { style: true, metadata: true, fullMetadata: true });
res.status(200).send(text);
}));
//User Page