You are not logged in.
I've created a script for KDE Klipper Action to upload an image, that are in the clipper to imgBB.com.
On the CLI it works nice, and shows the "notify-send" messages, I do create out of the script at my desktop.
The Script starts with `#!/usr/bin/node` and is an JS-Script.
If I run it as clipper-action, it doesn't show the message at all, and no image was uploaded.
BUT I've created an additional test as bash-script:
#!/bin/bash
notify-send --expire-time=5000 --icon=dialog-information "Klipper Info:" "TEST 123"this works.
So I think the issue seems to be caused by using node. But I don't have any clue what exactly is the issue here.
I wonder how I could get a usable response from this clipper-action, what happend there.
Offline
Can you post the full Node.js script you mentioned?
Offline
Sure, here it is:
#!/usr/bin/node
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const request = require('request');
const fs = require('fs');
const apiURL = 'api.imgbb.com';
const apiKey = 'xyz123123123';
const apiPath = '/1/upload?key=' + apiKey;
async function clipboard() {
let randomName = 'Screenshot_'+Math.random().toString(36).substring(7);
const imageFileType = '.jpg';
const {
stdout,
stderr
} = await exec(`xclip -selection clipboard -o -t image/jpeg -o > /tmp/${randomName}${imageFileType}`);
let img = new Buffer.from(stdout).toString('base64');
var options = {
url: `https://${apiURL}${apiPath}`,
headers: {
"Content-Type": "multipart/form-data"
},
formData : {
image: {
value: fs.createReadStream(`/tmp/${randomName}${imageFileType}`),
options: {
filename: `${randomName}${imageFileType}`,
contentType: 'image/jpeg'
}
},
}
};
request.post(options, function(err, res, body) {
const parsedBody = JSON.parse(body);
const {status, success} = parsedBody;
if(status===200 && success){
// exec(`echo -n "${parsedBody.data}"`);
exec(`qdbus org.kde.klipper /klipper setClipboardContents '${parsedBody.data.url}'`);
exec(`notify-send --expire-time=5000 --icon=dialog-information "Klipper Info:" "URL des Uploads\n\n${parsedBody.data.url}"`);
}else{
exec(`notify-send --expire-time=5000 --icon=dialog-error "imgBB.com:" "Upload fehlgeschlagen!\n\nMessage: ${parsedBody.error.message}"`);
}
});
}
clipboard();What it does:
Check the Klipper if the current entry is an image
If yes, save the contant as image to /tmp
Send the created Image via API-Request to imgBB
If successfully finished, notify with the url which was generated, if not notify with an error
Last edited by rethus (2021-12-03 14:56:33)
Offline
Few things to check:
Did you chmod +x your script.js?
Does it run correctly if you run "node script.js" from the terminal?
Few unrelated pointers on your script:
You have two -o flags on xclip.
Not a good practice to mix var and const.
If imgbb API returns an error, body parameter will probably be null, JSON.parse(null) is null, and after that deconstructing a null will throw an error.
You are not awaiting the exec calls and thus not handling (however unlikely) errors.
Also, imgbb.com seems down for me at the moment so unable to test your script in action.
Last edited by karabaja4 (2021-12-03 19:32:58)
Offline
Sorry for the Delay, was a bit busy in the last days.
I'd still made it `+x` to be able to execute it in cli.
Yes it works like a charm, if I only execute it (as I have the SHEBANG `#!/bin/node` as first line. But if I remove it, it also work with `node <scriptname`.
Offline