0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 09:52:48 +00:00

add exclusions for stub props

This commit is contained in:
Charlie Humphreys
2022-04-06 11:11:11 -05:00
parent e5021259bb
commit 4941dbb5bd
2 changed files with 31 additions and 12 deletions

View File

@@ -141,7 +141,14 @@ const GoogleActions = {
name : `${brew.title}.txt`,
description : `${brew.description}`,
properties : {
title : brew.title
'title' : brew.title,
'shareId' : brew.shareId || nanoid(12),
'editId' : brew.editId || nanoid(12),
'views' : brew.views,
'pageCount' : brew.pageCount,
'renderer' : brew.renderer || 'legacy',
'isStubbed' : true,
'updatedAt' : new Date().toISOString(),
}
},
media : {
@@ -173,9 +180,15 @@ const GoogleActions = {
'description' : `${brew.description}`,
'parents' : [folderId],
'properties' : { //AppProperties is not accessible
'shareId' : brew.shareId || nanoid(12),
'editId' : brew.editId || nanoid(12),
'title' : brew.title
'shareId' : brew.shareId || nanoid(12),
'editId' : brew.editId || nanoid(12),
'title' : brew.title,
'views' : '0',
'pageCount' : brew.pageCount,
'renderer' : brew.renderer || 'legacy',
'isStubbed' : true,
'createdAt' : new Date().toISOString(),
'version' : 1
}
};

View File

@@ -92,12 +92,20 @@ const excludePropsFromUpdate = (brew)=>{
return brew;
};
const excludeGoogleProps = (brew)=>{
const propsToExclude = ['views', 'lastViewed', 'pageCount', 'renderer', 'tags', 'systems', 'published', 'version', 'authors'];
const excludeStubProps = (brew)=>{
const propsToExclude = ['text', 'textBin', 'renderer', 'pageCount', 'views', 'version'];
for (const prop of propsToExclude) {
delete brew[prop];
brew[prop] = undefined;
}
return brew;
};
const excludeGoogleProps = (brew)=>{
const modified = brew.toObject ? brew.toObject() : brew;
const propsToExclude = ['tags', 'systems', 'published', 'authors', 'owner'];
for (const prop of propsToExclude) {
delete modified[prop];
}
return modified;
};
const beforeNewSave = (account, brew)=>{
@@ -137,8 +145,7 @@ const newBrew = async (req, res)=>{
.catch((err)=>{
res.status(err?.status || err?.response?.status || 500).send(err?.message || err);
});
newHomebrew.textBin = undefined;
newHomebrew.text = undefined;
excludeStubProps(newHomebrew);
} else {
// Compress brew text to binary before saving
newHomebrew.textBin = zlib.deflateRawSync(newHomebrew.text);
@@ -211,8 +218,7 @@ const updateBrew = async (req, res)=>{
}
if(brew.googleId) {
brew.textBin = undefined;
brew.text = undefined;
excludeStubProps(brew);
} else {
// Compress brew text to binary before saving
brew.textBin = zlib.deflateRawSync(brew.text);