0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00
Stop view count being reduced by an open Edit page
This commit is contained in:
Trevor Buckner
2021-08-27 23:04:30 -04:00
committed by GitHub
2 changed files with 28 additions and 17 deletions

View File

@@ -154,21 +154,22 @@ GoogleActions = {
if(await GoogleActions.existsGoogleBrew(auth, brew.googleId) == true) {
await drive.files.update({
fileId : brew.googleId,
resource : { name : `${brew.title}.txt`,
description : `${brew.description}`,
properties : { title : brew.title,
published : brew.published,
lastViewed : brew.lastViewed,
views : brew.views,
version : brew.version,
renderer : brew.renderer,
tags : brew.tags,
systems : brew.systems.join(),
pageCount : brew.pageCount
}
},
media : { mimeType : 'text/plain',
body : brew.text }
resource : {
name : `${brew.title}.txt`,
description : `${brew.description}`,
properties : {
title : brew.title,
published : brew.published,
version : brew.version,
renderer : brew.renderer,
tags : brew.tags,
systems : brew.systems.join()
}
},
media : {
mimeType : 'text/plain',
body : brew.text
}
})
.catch((err)=>{
console.log('Error saving to google');

View File

@@ -19,6 +19,15 @@ const getGoodBrewTitle = (text)=>{
.slice(0, MAX_TITLE_LENGTH);
};
const excludePropsFromUpdate = (brew)=>{
// Remove undesired properties
const propsToExclude = ['views', 'lastViewed'];
for (const prop of propsToExclude) {
delete brew[prop];
};
return brew;
};
const mergeBrewText = (text, style)=>{
if(typeof style !== 'undefined') {
text = `\`\`\`css\n` +
@@ -64,7 +73,8 @@ const newBrew = (req, res)=>{
const updateBrew = (req, res)=>{
HomebrewModel.get({ editId: req.params.id })
.then((brew)=>{
brew = _.merge(brew, req.body);
const updateBrew = excludePropsFromUpdate(req.body);
brew = _.merge(brew, updateBrew);
brew.text = mergeBrewText(brew.text, brew.style);
// Compress brew text to binary before saving
@@ -154,7 +164,7 @@ const updateGoogleBrew = async (req, res, next)=>{
try { oAuth2Client = GoogleActions.authCheck(req.account, res); } catch (err) { return res.status(err.status).send(err.message); }
const brew = req.body;
const brew = excludePropsFromUpdate(req.body);
brew.text = mergeBrewText(brew.text, brew.style);
try {