Skip to content

Commit

Permalink
Merge pull request #42 from publiclab/jpg-saving
Browse files Browse the repository at this point in the history
direct JPG saving
  • Loading branch information
jywarren authored Apr 20, 2020
2 parents b194b7f + 544f27a commit fad302f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "is",
"version": "1.1.0",
"version": "1.1.1",
"description": "",
"main": "src/server.js",
"scripts": {
Expand Down
32 changes: 17 additions & 15 deletions src/api/v2/util/process-multisequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ let cb = (out) => {
} else {
changeStatus("uploading");
console.log("Done processing for " + pid);
var html = `<html>`
html += `<img width="100%" src= "${out}">`
html += `</html>`
fs.writeFileSync(path.join(__dirname, `../../../../temp/export${pid}.html`), html);
mapknitterBucket.upload(path.join(__dirname, `../../../../temp/export${pid}.html`), {
gzip: true
}).then(() => {
mapknitterBucket
.file(`export${pid}.html`)
.makePublic();
fs.unlinkSync(path.join(__dirname, `../../../../temp/export${pid}.html`));
mapknitterBucket.file(`export${pid}.html`)
.getMetadata()
.then((data) => changeStatus("uploaded", data[0].mediaLink));
var data = out.replace(/^data:image\/\w+;base64,/, ""); // strip off the data: url prefix to get just the base64-encoded bytes
var buf = new Buffer(data, 'base64');
var filename = `export${pid}.jpg`
var imgPath = path.join(__dirname, `../../../../temp/${filename}`);
fs.writeFile(imgPath, buf, onWrote() {
mapknitterBucket.upload(imgPath, {
gzip: true
}).then(() => {
mapknitterBucket
.file(filename)
.makePublic();
fs.unlinkSync(path.join(__dirname, imgPath));
mapknitterBucket.file(filename)
.getMetadata()
.then((data) => changeStatus("uploaded", data[0].mediaLink));
});
});
}
}
Expand Down Expand Up @@ -105,4 +107,4 @@ function changeStatus(newStatus, exportLink) {
console.log("Successfully removed local files!");
});
});
}
}

0 comments on commit fad302f

Please sign in to comment.