0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-27 18:02:42 +00:00

Gzip brew object when sending for save update

This commit is contained in:
Trevor Buckner
2025-07-11 16:55:30 +00:00
parent 9da8a17053
commit 22ef3cbebc
4 changed files with 28 additions and 2 deletions

View File

@@ -24,6 +24,18 @@ const isStaticTheme = (renderer, themeName)=>{
return Themes[renderer]?.[themeName] !== undefined;
};
const uncompressBrew = (input, encoding)=> {
try {
const jsonStr = encoding === 'gzip'
? zlib.gunzipSync(input).toString('utf-8')
: input.toString('utf-8');
return JSON.parse(jsonStr);
} catch (err) {
throw new Error('Failed to parse JSON: ' + err.message);
}
}
// const getTopBrews = (cb) => {
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
// cb(brews);
@@ -337,7 +349,7 @@ const api = {
},
updateBrew : async (req, res)=>{
// Initialize brew from request and body, destructure query params, and set the initial value for the after-save method
const brewFromClient = api.excludePropsFromUpdate(req.body);
const brewFromClient = api.excludePropsFromUpdate(uncompressBrew(req.body, req.headers['content-encoding']));
const brewFromServer = req.brew;
splitTextStyleAndMetadata(brewFromServer);