mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
Add zlib compression to the "text" field. Now, when a file is saved, the original text field is blanked out and the "compressed" binary version is saved instead. Viewing files in Edit page unzips and views them just fine.
Does not compress old files unless they are opened and resaved by someone. Have not tested on the "share" or "print" pages yet, but should work.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const _ = require('lodash');
|
||||
const HomebrewModel = require('./homebrew.model.js').model;
|
||||
const router = require('express').Router();
|
||||
const zlib = require('zlib');
|
||||
|
||||
// const getTopBrews = (cb)=>{
|
||||
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
|
||||
@@ -47,6 +48,9 @@ router.put('/api/update/:id', (req, res)=>{
|
||||
HomebrewModel.get({ editId: req.params.id })
|
||||
.then((brew)=>{
|
||||
brew = _.merge(brew, req.body);
|
||||
brew.textBin = zlib.deflateSync(req.body.text); // Compress brew text to binary before saving
|
||||
brew.text = ''; // Clear out the non-binary text field so its not saved twice
|
||||
|
||||
brew.updatedAt = new Date();
|
||||
if(req.account) brew.authors = _.uniq(_.concat(brew.authors, req.account.username));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user