I am using grpc-dynamic-gateway package and it uses the grpc package as a client. Im trying to figure out how I can set max_receive_message_length globally on the grpc object I require in my script?
const grpc = require('grpc');
grpc.max_receive_message_length = 1024 * 1024 * 100; // <-- this does not work, how can I do this?
app.use('/', grpcGateway(
['api.proto'],
'0.0.0.0:5051',
grpc.credentials.createInsecure(),
true,
process.cwd(),
grpc // This is being passed to the middleware..id like it to have the option above set on it
));
I figured this out. The change needs to be made directly in the grpc-dynamic-gateway package. In index.js on line 77 change:
getPkg(clients, pkg, true)[svc] = new (getPkg(protos[si], pkg, false))[svc](grpcLocation, credentials)
to
getPkg(clients, pkg, true)[svc] = new (getPkg(protos[si], pkg, false))[svc](grpcLocation, credentials, {
"grpc.max_receive_message_length": 1024 * 1024 * 1000,
"grpc.max_send_message_length": 1024 * 1024 * 1000
})
Im not sure if this is the only way to fix this but it worked for me. Also obviously adjust the message sizes to a more appropriate value for yourself. 1000mb is probably excessive.
According to this response in their github issues, you have to set this when you instantiate the server, as it is a server option:
var server = new grpc.Server({'grpc.max_receive_message_length': 1024*1024*100})
Related
I've gotten this IPFS info such as "/ipfs://QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE" as API response.
I want to display this file(image) on my page, but I can't find out the correct solution.
How can I get the image URL from this info in react app?
Please help with my concern.
Try adding https://ipfs.io in the beginning of your ipfs info as suggested in this document https://docs.ipfs.io/concepts/what-is-ipfs/
i.e
ipfs://QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE
becomes
https://ipfs.io/ipfs/QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE
If you're using js-ipfs, you can retrieve the image over IPFS, and display it:
/** Uses `URL.createObjectURL` free returned ObjectURL with `URL.RevokeObjectURL` when done with it.
*
* #param {string} cid CID you want to retrieve
* #param {string} mime mimetype of image
* #param {number} limit size limit of image in bytes
* #returns ObjectURL
*/
async function loadImgURL(cid, mime, limit) {
if (cid == "" || cid == null || cid == undefined) {
return;
}
const content = [];
for await (const chunk of ipfs.cat(cid, {length:limit})) {
content.push(chunk);
}
return URL.createObjectURL(new Blob(content, {type: mime}));
}
Then you can display it with something like:
<body>
<img id="myImage" />
<script>
async function setImage() {
// just an example, make sure to free the resulting ObjectURL when you're done with it
//
// if your CID doesn't work, try this one: Qmcm32sVsMYhURY3gqH7vSQ76492t5Rfxb3vsWCb35gVme
// that's a popular CID, which should resolve every time
document.getElementById("myImage").src = await loadImgURL("QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE", "image/png", 524288);
}
setImage();
</script>
</body>
The big advantage of this is you're using the IPFS network itself, and not relying on a public HTTP gateway (the recommended way).
You can do something like that:
tokenURI.replace("ipfs://", "https://ipfs.io/ipfs/");
One thing to note here about fetching images from IPFS that I think isn't being discussed sufficiently in these answers is that you will need to either
Run your own node of IPFS, or
Get a hosted IPFS node through a service like Infura
I have spent a little bit of time working through this in the last couple of days, and it will always come back to you having to have direct access to your own node.
There are "Gateways," which are nodes hosted by the community, and you can read more about them in the IPFS docs here: https://docs.ipfs.io/concepts/ipfs-gateway/#limitations-and-potential-workarounds
The thing with the gateways is that they are not meant to be relied upon for production sites, as you can see below. It's possible that there is some hosted node out there that somebody is giving out for free, but I doubt it, and you wouldn't want to rely on that anyways.
I think that other questions above have elaborated how you actually process the responses once you get it, but I wanted to cover this extra ground in my answer.
ipfs docs
let imgUrl = url?.slice(url.indexOf(":"),url?.lastIndexOf("/"));
let slice = url?.slice(url.lastIndexOf("/"),url?.length)
let renderURL = `https${imgUrl}.ipfs.dweb.link${slice}`;
console.log(renderURL);
I would like to send a message from a text file every 24 hours to a channel in my server (discord.js).
I think it would be like "appendFile" or something like that. If you know how to do this I would appreciate it!
The way I am looking to use this is every morning with a random good morning message.
You can use setInterval , here is what you can do -
var fs = require("fs"); // require fs
var file = fs.readFileSync("./path/to/file"); // read file
setInterval(()=>{
MessageChannel.send(file); // the `TextChannel` class
},86400000) // setting the time to 24 hours in ms
What you need is a cron job.
This is the one i use.
Install
npm install cron
var CronJob = require('cron').CronJob;
var job = new CronJob('* * * * * *', function() {
console.log('You will see this message every second');
}, null, true, 'America/Los_Angeles');
job.start();
You can read about cron patterns here
I want to launch the Firefox browser through selenium-webdriver 3.6.0 with some of the default settings of the browser changed. Specifically, I want Firefox to download files, during automated testing, without prompting whether to save or not and to download to a predefined directory other than the default, which is the downloads folder.
The way to do it on google chrome is this:
if (this.bName === 'chrome') {
var cap = Capabilities.chrome();
var options = {
'prefs': {
profile: {
default_content_settings: {
popups: 0,
},
},
download: {
default_directory: path.join(__dirname,
'/../Downloads For Testing'),
}
}
};
var cap = cap.set('chromeOptions', options);
this.browser = new Builder().withCapabilities(cap).build();
}
A relevant try on Firefox, by setting the preferences after creating a new profile, didn't work.
I include the Profile from Firefox folder
firefoxProfile = require('selenium-webdriver/firefox').Profile;
and I build with new capabilities
else if (this.bName === 'firefox') {
var cap = Capabilities.firefox();
var profile = new firefoxProfile;
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir", path.join(__dirname, '/../Downloads For Testing'));
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/html");
cap.set('firefox_profile', profile);
console.log(profile);
this.browser = new Builder().withCapabilities(cap).build();
}
This is the printout of the new profile object:
Profile {
preferences_:
{ 'browser.download.folderList': 2,
'browser.download.manager.showWhenStarting': false,
'browser.download.dir': 'C:\\path\\Downloads For Testing',
'browser.helperApps.neverAsk.saveToDisk': 'text/html' },
template_: undefined,
extensions_: []
}
The browser is initiated with no errors and all promises are returned correctly by mocha, the test framework, until pressing the button to download a file and the normal dialog shows up, so no success.
The index.js file in selenium-webdriver\firefox states clearly how to create a new profile dynamically and set the preferences.
* The {#linkplain Profile} class may be used to configure the browser profile
* used with WebDriver, with functions to install additional
* {#linkplain Profile#addExtension extensions}, configure browser
* {#linkplain Profile#setPreference preferences}, and more. For example, you
* may wish to include Firebug:
*
* const {Builder} = require('selenium-webdriver');
* const firefox = require('selenium-webdriver/firefox');
*
* let profile = new firefox.Profile();
* profile.addExtension('/path/to/firebug.xpi');
* profile.setPreference('extensions.firebug.showChromeErrors', true);
*
* let options = new firefox.Options().setProfile(profile);
* let driver = new Builder()
* .forBrowser('firefox')
* .setFirefoxOptions(options)
* .build();
It tried it and it didn't work. Obviously I didn't try to add the extension but only to set the 4 preferences written in my question.
What did the trick for me, as a workaround though, was to create a new profile by executing firefox.exe -p on the windows' Run dialog. (Press the windows icon key and R on keyboard to get the run dialog)
After that, I used this new "testing" profile as a template to create a new temporary one dynamically through selenium.
var profile = new firefox.Profile('/pathTo/firefox profile for testing/');
And here is the trick. It appears to be a thing with Firefox and mime types. If the server, sending the file to download, names the file's content-type differently as the Firefox would, the auto save won't happen and the 'save or open file' dialog will appear. Probably for security reasons. The content type can be found here
In my case it's about a csv file and setting profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv") while the server sends a content-type of text/html and firefox identifies it as TXT file didn't work.
So I edited the handlers.json file inside /pathTo/firefox profile for testing/ by setting the attribute 'ask' of 'text/plain' inside 'mimeTypes' from true to false.
And of course I set as an only preference the path for the file to get downloaded to. Btw this will also create the path, at least the last folder. So my code is:
else if (this.bName === 'firefox') {
var cap = Capabilities.firefox();
var profile = new firefox.Profile('/pathTo/firefox profile for testing/');
profile.setPreference("browser.download.dir", '/pathTo/Downloads For Testing');
let options = new firefox.Options().setProfile(profile);
this.browser = new Builder().forBrowser(this.bName).setFirefoxOptions(options).build();
}
You can also try this and not mess with the handler.json (end of page) but didn't work for me.
Or just go brute force, this didn't either.
Hello I want to use persistencejs in my angularjs/ionic mobile application. I use a sqlite database on the device.
I used this example to use persistencejs in my application but I get an error:
undefined is not an object (evaluating 'persistence.store.cordovasql.config')
In my index.html I bind the js files like this:
<script src="lib/persistencejs/persistence.js"></script>
<script src="lib/persistencejs/persistence.store.sql.js"></script>
<script src="lib/persistencejs/persistence.store.sqlite.js"></script>
And in my controller I use:
persistence.store.cordovasql.config(
persistence,
'testdb',
'0.0.1', // DB version
'DB', // DB display name
5 * 1024 * 1024, // DB size
0 // SQLitePlugin Background processing disabled
);
persistence.define('Page', {
path: "TEXT",
data: "TEXT"
});
persistence.schemaSync();
What am I missing?
Do you include the cordovasql script?
<script src="lib/persistencejs/persistence.store.cordovasql.js"></script>
PS. For some reason installing persistencejs with bower didnt work for me. I manually downloaded the github repo from https://github.com/coresmart/persistencejs
I need to read data from a GPSMap 62 device using the device control Javascript library. Problem is, unlike older devices, this device stores its waypoints in separate .GPX files every day. The javascript library expects all tracks and waypoints to be in the current.gpx file, but the 62 stores them in e.g. Waypoints_06-MAY-14.gpx and so on each day.
Short of requiring users to manually upload the appropriate file, has anyone gotten the DeviceControl library to actually support the newer devices with separate GPX files?
As an added bonus, the Garmin Device Control library is deprecated, so no updates are forthcoming.
Some code
startReadFromGps: function(deviceNumber) {
this.plugin.StartReadFromGps( deviceNumber ); //invokes the external plugin
},
I've checked out plugin in version 2.3-RC1 (I do not know, which version do you use).
Indeed there is startReadFromGps method:
/** Initiates the read from the gps device conneted. Use finishReadFromGps and getGpsProgressXml to
* determine when the plugin is done with this operation. Also, use getGpsXml to extract the
* actual data from the device. <br/>
* <br/>
* Minimum plugin version 2.0.0.4
*
* #param deviceNumber {Number} assigned by the plugin, see getDevicesXml for
* assignment of that number.
* #see #finishReadFromGps
* #see #cancelReadFromGps
* #see #getDevicesXml
*/
startReadFromGps: function(deviceNumber) {
this.plugin.StartReadFromGps( deviceNumber );
},
So it uses getGpsXml. I assume that it uses specified filename that is read and method returns file's content. My first thought is to change the filename - it is possible with:
/** This the filename that wil contain the gps xml once the transfer is complete. Use with
* setWriteGpsXml to set what the file contents will be. Also, use startWriteToGps to
* actually make the write happen.
*
* #private
* #param filename {String} the actual filename that will end up on the device. Should only be the
* name and not the extension. The plugin will append the extension portion to the file name--typically .gpx.
* #see #setWriteGpsXml, #startWriteToGps, #startWriteFitnessData
*/
_setWriteFilename: function(filename) {
this.plugin.FileName = filename;
},
But _setWriteFilename is private method. However called by
startWriteToGps: function(gpsXml, filename, deviceNumber)
and
startWriteFitnessData: function(tcdXml, deviceNumber, filename, dataTypeName)
Since now I will check if calling those methods with your specified filename will override filename value permanently and further calling of startReadFromGps will use new filename.
I cannot test it, I didn't use this library but you can give a shot.