Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Save as jpeg on edit if > limit. (#3943) (#3999)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba authored and jaredhirsch committed Jan 25, 2018
1 parent 31bbfb4 commit 4fae01f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
14 changes: 14 additions & 0 deletions server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ var conf = convict({
env: "LOCALHOST_SSL",
arg: "localhost-ssl"
},
pngToJpegCutoff: {
doc: "The limit at which a PNG is converted to a JPEG during an edit save, in bytes. It should match the setting in the addon",
format: "int",
default: 2500000,
env: "PNG_TO_JPEG_CUTOFF",
arg: "pngToJpegCutoff"
},
requestBodySizeLimit: {
doc: "The maximum allowed body size of a request. It needs to be a format that the 'bytes' node module accepts",
format: String,
default: "25mb",
env: "REQUEST_BODY_SIZE_LIMIT",
arg: "requestBodySizeLimit"
},
useS3: {
doc: "If true, store files in s3. If false, store them locally",
format: Boolean,
Expand Down
8 changes: 8 additions & 0 deletions server/src/pages/shot/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ exports.Editor = class Editor extends React.Component {
this.imageContext.drawImage(this.highlighter, 0, 0);
this.highlightContext.clearRect(0, 0, this.imageCanvas.width, this.imageCanvas.height);
let dataUrl = this.imageCanvas.toDataURL();

if (this.props.pngToJpegCutoff && dataUrl.length > this.props.pngToJpegCutoff) {
let jpegDataUrl = this.imageCanvas.toDataURL("image/jpeg");
if (jpegDataUrl.length < dataUrl.length) {
dataUrl = jpegDataUrl;
}
}

let dimensions = {x: this.canvasWidth, y: this.canvasHeight};
this.props.onClickSave(dataUrl, dimensions);
}
Expand Down
1 change: 1 addition & 0 deletions server/src/pages/shot/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ exports.createModel = function(req) {
simple: false,
retentionTime: req.config.expiredRetentionTime * 1000,
defaultExpiration: req.config.defaultExpiration * 1000,
pngToJpegCutoff: req.config.pngToJpegCutoff,
hashAnalytics: true,
userAgent: req.headers['user-agent'],
blockType: req.shot.blockType,
Expand Down
2 changes: 1 addition & 1 deletion server/src/pages/shot/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Body extends React.Component {
let clipNames = shot.clipNames();
let clip = shot.getClip(clipNames[0]);
return <reactruntime.BodyTemplate {...this.props}>
<Editor clip={clip} onCancelEdit={this.onCancelEdit.bind(this)} onClickSave={this.onClickSave.bind(this)}></Editor>
<Editor clip={clip} pngToJpegCutoff={this.props.pngToJpegCutoff} onCancelEdit={this.onCancelEdit.bind(this)} onClickSave={this.onClickSave.bind(this)}></Editor>
</reactruntime.BodyTemplate>;
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ app.use((req, res, next) => {
});

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json({limit: '25mb'}));
app.use(bodyParser.json({limit: config.requestBodySizeLimit}));

app.use("/static", express.static(path.join(__dirname, "static"), {
index: false,
Expand Down

0 comments on commit 4fae01f

Please # to comment.