Is there a native function for downloading a file in neutralinojs that I can use? - neutralinojs

When you right click on a download link in a neutralino app, there is a "download linked file" option which one selects then their file is downloaded.
How can I call that function to download a file in my app.

One method I've been working with (which comes along with its own pitfalls) is using Powershell. The pitfall is that each user may have different versions of Powershell or different environment settings.
This method works on my development computer, but when testing on my laptop as a new user, it fails. But I have very little knowledge of Powershell and I think there is a way to make it work.
My progress so far:
// Create message for Neutralino to execute
let message ='powershell $download = Invoke-WebRequest -UseBasicParsing -Uri "'+insertCleanedURI+'" -OutFile Downloads/'+cleanName+'.fileExtension';
//Next run Neutralino's command execution method
let response = await Neutralino.os.execCommand({
command: message
});
// Capture the response from powershell which Neutralino will receive, and continue with logic
If (response.output.includes("Example Server Response") {
// success, the file has downloaded to the folder & file name specified, do further stuff
} else {
// failed, try to debug the issue
}
Edit: Realized you asked specifically for a native function, not using Powershell. This is how I found you question because I was wondering if I was doing this the hard way.

Related

Google Drive UI Integration Issue: "Open with ..." suggestion is missing for my app's files

I recently launched a Marketplace app with a Google Drive UI Integration.
And I'm experiencing an issue where Google Drive fails to give users, who don't have my application installed in their Drive, a suggestion to "Open with ..." when previewing our third-party shortcut file.
A file's mimeType is used by Drive to make suggestions for applications compatible with the mimeType. Therefore it seems that Google Drive is unable to connect the mimeType that I am setting on my app's files to the mimeType in it's internal records.
The mimeType I set on my app's files is application/vnd.google-apps.drive-sdk (third party shortcut file) as instructed by docs [1]. Upon inspecting the html of the page, we see that Drive does in fact have the correct mimeType
<span class="a-q-Jc-wg" data-tooltip="application/vnd.google-apps.drive-sdk.6964198....." aria-label="application/vnd.google-apps.drive-sdk.6964198....." data-tooltip-align="b,c" data-tooltip-delay="500" data-tooltip-unhoverable="true">my app</span>
Those numbers (6964198.....) appended at the end make up my Google Cloud Project Id. Upon inspecting another marketplace app, Lucidchart, their mimeType is application/vnd.google-apps.drive-sdk.7081045131. If someone shares a Lucidchart shortcut with another person that does not have lucidchart installed, upon opening, they get the "Open with Lucidchart suggestion" Their app is working as expected, my isn't, and comparing the third-party shortcut file properties shows no difference.
Looking at one of our file's properties via "Get Details" in Drive shows that Google Drive is able to recognize the fileType as my app's file.
Once the user does install my application, they are able to see "Open with..." upon previewing the file. This gives the impression that mimeType is set correctly and available to drive, but GDrive is not properly using it before installation.
I have spent quite a lot of time trying to figure out what could be causing this issue, but I am stuck. I triple checked my configuration and everything seems to be set up correctly as directed by the docs [2].
I have 2 tickets opened to Google support on this matter, I even got on a call with them, but eventually they said that it seems like I'm doing everything correctly, but they can't help me any further and suggested to post a question on StackOverflow... So I'm asking for your help here.
My app's backend is written in Node.js and uses googleapis:51.0.0 module.
Here is a piece of my code that saves a file:
const gDrivePayload = {
requestBody: {
name: presentation.name,
mimeType: "application/vnd.google-apps.drive-sdk",
parents: [folderId],
properties: { presentationId }
}
};
if (thumbnailData) {
gDrivePayload.requestBody.contentHints = { thumbnail: { image: thumbnailData } };
}
const drive = google.drive({ version: "v3", auth: gAuthClient });
const gDriveResp = await drive.files.create(gDrivePayload);
gAuthClient is an instance of google.auth.OAuth2 with provided user tokens that were obtained via an oauth2 flow that was performed by the user.
thumbnailData is a base64 encoded jpeg image.
[1] https://developers.google.com/drive/api/v3/third-party-shortcuts
[2] https://developers.google.com/drive/api/v3/enable-sdk?hl=sk

How to get a variable which can be viewed from console

I'm coding an extension which downloads a file, before downloading the file, I need to get a token which is already generated from the website on loading.
This token can be viewed from the console by typing >GetPublicTokenResult
How can I read this variable into my content script?
I've tried the following:
chrome.storage.local.get(["GetPublicTokenResult"], function(items){ items = [ { "yourBody": "myBody" } ]
console.log(items);
});
but it seems that this variable is not stored in Storage, but it can be viewed in Memory snap
Content scripts run in an isolated environment from the page. They can only interact with the DOM, javascript code can't be accesed. You need to inject your code directly in the page. Check out Insert code into the page context using a content script for a detailed tutorial.

Docusign eventNotification is failing with error 400

I am using Docusign's REST API to create and send envelopes. I've included eventNotifications with requireAcknowledgment as true to get requests from Docusign whenever there's status change. I used ngrok while development and testing and everything worked as expected.
I've moved the project online and have edited the eventNotification's url to live url with https and that's when all the callbacks are getting logged in failed section in Docusign's admin panel.
The error message shown in admin panel is -
'https://xxx.xxxxxxx.com/webhook.php :: Error - The remote server
returned an error: (400) Bad Request.'
I've downloaded the failed request's xml body and tried sending a request through postman and it worked as expected. Iv'e tried everything to debug this error and have not found error at my end.
Edit:
The code that I've tried with is the same code from DocuSign's webhook sample page -
$data = file_get_contents('php://input');
$xml = simplexml_load_string ($data, "SimpleXMLElement", LIBXML_PARSEHUGE);
$envelope_id = (string)$xml->EnvelopeStatus->EnvelopeID;
$time_generated = (string)$xml->EnvelopeStatus->TimeGenerated;
$files_dir = getcwd() . '/' . $this->xml_file_dir;
if(! is_dir($files_dir)) {mkdir ($files_dir, 0755);}
$envelope_dir = $files_dir . "E" . $envelope_id;
if(! is_dir($envelope_dir)) {mkdir ($envelope_dir, 0755);}
$filename = $envelope_dir . "/T" .
str_replace (':' , '_' , $time_generated) . ".xml"; // substitute _ for : for windows-land
$ok = file_put_contents ($filename, $data);
if ($ok === false) {
error_log ("!!!!!! PROBLEM DocuSign Webhook: Couldn't store $filename !");
exit (1);
}
// log the event
error_log ("DocuSign Webhook: created $filename");
if ((string)$xml->EnvelopeStatus->Status === "Completed") {
// Loop through the DocumentPDFs element, storing each document.
foreach ($xml->DocumentPDFs->DocumentPDF as $pdf) {
$filename = $this->doc_prefix . (string)$pdf->DocumentID . '.pdf';
$full_filename = $envelope_dir . "/" . $filename;
file_put_contents($full_filename, base64_decode ( (string)$pdf->PDFBytes ));
}
}
I've also tried with simple code that just sets header to 200
http_response_code(200);
Sorry you're having so much trouble with the webhook feature. Hopefully this answer will be of assistance.
1. Try a test PHP program to check connectivity, etc:
<?php
header('Content-Type: text/html');
echo "OK!";
$h = fopen('/tmp/listener_access.log', 'a');
if ($h) {
$now = DateTime::createFromFormat('U.u', microtime(true), new DateTimeZone('UTC'));
fwrite ($h, $now->format ("Y-m-d_l.h.i.s.v "));
fwrite($h, $_SERVER["REMOTE_ADDR"] . " " . $msg . "\n");
fclose($h);
} else {
error_log ("### Could not open log file!");
}
Store it as ok.php in your web server directory. Then try (from a browser on a different network) to reach https://yourserver.company.com/ok.php You should see "ok" in the browser window.
Then use the same url in your eventNotification section of your Envelopes::create call to see if it all works. You should see a success in the Connect log, etc.
2. Stepwise debugging of your PHP listener
There are a number of issues to rule-out (as diagnosticians say) with your php listener app.
Basic connectivity with the listener. Since DocuSign is receiving a 400 error from your app, connectivity is ok.
Platform errors with your app. This is a problem with your PHP software stack setup that is causing the stack (not your PHP app, per se) to reject the request.
The usual indicator for this is your web server's error log. Have you looked at it? What is on the logging line where you see the 400 response from your server to DocuSign? If you don't see the 400 response to DocuSign then something is wrong with your web server's setup.
A common platform error with PHP and other stacks when default settings are used is maximum_post_size_exceeded. This is happens if you have requested that DocuSign include your envelope's documents in the notification message.
A good test is to temporarily change your envelope create code to not include documents in the notification messages.
Fixes: a good fix is to not include the envelope documents in the notification message. Instead, after the message is received, make separate API calls to retrieve the documents.
The other fix is to increase the maximum post body size. You may need to increase it both in the PHP settings and in the underlying web server's settings too. (By the way, which web server are you using?)
You are processing the incoming notification in the response thread of your server/php app. This really isn't the best technique (I will be updating the DocuSign example page in the future with this information.)
The best technique is to use the following pattern:
1. Receive the incoming notification message from DocuSign
2. Put the message onto a reliable FIFO queue
3. Respond to DocuSign with a 200 response.
Then, in a separate thread of execution, a
different software application "works off" the
entries in the queue.
Your web server, for example, may be timing out your PHP program. This probably isn't happening in your case, but others may experience this.
I think I would, next, add more debugging statements to your PHP program to try and understand what is happening to it. You can either do this with error-log
or copy the technique from my example (above) and write to a file in /tmp. (Assuming a Linux server.)
The other option is to increase the debugging level of the php stack itself, or of your web server, or both.
3. Last thoughts
400 in the DocuSign logs usually indicates that DocuSign reached your server and it returned a 400 status code. This can be confirmed by examining your server log (regular or error), there should be a matching entry.
If there isn't an entry in your server log, but the "ok.php" program from above does work, then it would be time to comment out big chunks of code from your PHP program, and then do another test from DocuSign. Eventually, using a binary-search technique (See step 8 in the article), you find the code that is causing the problem.
Commenting out code as part of a binary-search to find the bug is a very common, and powerful debugging technique.
HTH, Larry

how to run agents in xpages from a web browser?

I got this problem and started googling about it, but no direct answer were pulled out. My query problem is, I'm doing an xpage project and I need to run an agent that uses lotusscript as a language. The agent is used to read a TSV text file and create notes document from each record there. Independently running the agent went very good, no problem. But when I tried to run it from xpage using this script :
var doc = database.createDocument();
var field = getComponent("filePath");
var agent:NotesAgent = database.getAgent("UploadTSV");
if (agent != null) {
agent.runWithDocumentContext(doc);
TSVDoc.setValue("filePath","Agent run");
}
else{
TSVDoc.setValue("filePath","Agent did not run");
}
it did not run. I'm just wondering what I did wrong. Thank you in advance.
My way to do this would be to trigger the agent (either it's based on a page load event or on a user click event) via client Javascript. The URL to run an agent is nothing more than
http://yourhost/yourapp.nsf/youagent?openagent
So I'd just make a AJAX call to that URL to run the agent. To get return values (errors of anything else) I'd add some code to the agent's print output. Print statements (in Lotusscript) in agents called from the browser produce a HTTP response. Similar for agents written in Java but there you have to do more than simple sysouts.

Change a document's permissions via Google Apps Script

I'm looking for sample script that resets the default permissions on an external spreadsheet based on the email address and DocumentID passed to the script. I intent to create a script that can parse information from an email message to acquire the DocumentID and email, execute the permission change from default to anyone with a link, then email the passed address with that link.
It appears that perms are controlled by the DocList API and I'm not finding samples of GAS interacting with that API.
At Google I/O 2013, DriveApp was launched. This allows developers to build use cases like Sharing to Anyone with link
https://developers.google.com/apps-script/reference/drive/
Sample code -
var quizTemplate = DriveApp.getFileById(QUIZ_TEMPLATE_ID);
quizTemplate.setSharing(DriveApp.Access.DOMAIN_WITH_LINK, DriveApp.Permission.VIEW);
or
var openFile = DriveApp.getFileById(WIDE_OPEN_ID)
openFile.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.COMMENT);
AFAIK DocsList Services does not have a function to change the sharing mode, between private/anyone with a link/public, only to add/remove editors and viewers. But we can still achieve this by previously setting manually the share settings of a specific folder to "anyone with a link". Then, we have just to add the file to that folder to have it shared.
A script to do that is particularly simple. e.g.
function shareWithAnyoneAndEmail(documentID,email) {
var sharedFolder = DocsList.getFolderById('id-to-your-previously-shared-folder');
var file = DocsList.getFileById(documentID);
file.addToFolder(sharedFolder);
MailApp.sendEmail(email, 'Here is your file', file.getName()+'\n'+file.getUrl());
}

Resources