Skip to content

Commit

Permalink
adding support to open-in-gimp
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-portmen committed Dec 26, 2016
1 parent 70ccad7 commit b1785cb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ exports.ids = {
'noedpljikmfalclpadmnjbabbignpfge', // Open in IE (Opera)
'ocnfecjfebnllnapjjoncgjnnkfmobjc', // Media Converter (Chrome)
'fabccabfpmdadbhljpcmcbmepepfllnb', // Media Converter (Opera)
'jgpghknlbaljigdhcjimjnkkjniiipmm', // Open in GIMP (Chrome)
'cmjahocdpafkodabbojjaebogoigcipj', // Open in GIMP (Opera)
],
firefox: [
'{5610edea-88c1-4370-b93d-86aa131971d1}', // Open in IE
Expand Down
45 changes: 44 additions & 1 deletion host.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var https = lazyRequire('./follow-redirects').https;
var server, files = [];

var config = {
version: '0.1.6'
version: '0.1.7'
};
// closing node when parent process is killed
process.stdin.resume();
Expand Down Expand Up @@ -163,6 +163,7 @@ function observe (msg, push, done) {
else {
push({
files,
folders: files.filter(file => fs.statSync(path.join(msg.path, file)).isDirectory()),
separator: path.sep
});
}
Expand Down Expand Up @@ -214,6 +215,48 @@ function observe (msg, push, done) {
socket.on('timeout', () => request.abort());
});
}
else if (msg.cmd === 'save-data') {
let matches = msg.data.match(/^data:.+\/(.+);base64,(.*)$/);
if (matches && matches.length) {
let ext = matches[1];
let data = matches[2];
let buffer = new Buffer(data, 'base64');

fs.mkdtemp(os.tmpdir(), (err, folder) => {
if (err) {
push({
error: err.message,
code: 1007
});
done();
}
let file = path.join(folder, 'image.' + ext);
fs.writeFile(file, buffer, (err) => {
if (err) {
push({
error: err.message,
code: 1006
});
done();
}
else {
push({
code: 0,
file
});
done();
}
});
});
}
else {
push({
error: 'cannot parse data-uri',
code: 1005
});
done();
}
}
else {
push({
error: 'cmd is unknown',
Expand Down

0 comments on commit b1785cb

Please sign in to comment.