IBitmap servedImage = await BlobCache.Secure.LoadImageFromUrl(url);
While executing above statement I am getting null response. Please suggest.
Akavache version - 6.0.31
Related
let allDB = await this.findAll();
//allDB output in console shows it has everything from db as I want
allDB .forEach(item => {
//item is undefined here
});
async findAll() {
return this.db.find()
}
I'm trying to load everything from a mongo collection and after that do a foreach loop trought it, but item is always undefined.
Thanks for your help
In the code you provided us there is a space between 'allDB' and '.forEach'. Is it the case in your project ? Because it can be the source of your error. Remove it to be sure it's not this.
I don't think that's the problem because it should throw a syntax error but it's still worth trying.
For some odd reason when I try to check if a member is in a guild it throws error
Uncaught TypeError: client.guilds.get is not a function
Here is a section of my code.
//IDS TO BAN
USER_ID = '860926166956769280 // test account' //863609914291388467
USER_ID2 = '863929485845594152'
USER_ID3 = '863572599221256203'
GUILD = '863564803892576276' // guild to ban members in
let guildToCheck = client.guilds.get(GUILD), // line it gets stuck on
server = msg.guild
// Check if forbidden users exist.
if (guildToCheck.member.fetch(USER_ID)) {
server.members.ban(USER_ID)
}
if (guildToCheck.member.fetch(USER_ID2)) {
server.members.ban(USER_ID2)
}
if (guildToCheck.member.fetch(USER_ID3)) {
server.members.ban(USER_ID3)
}
I am using the newest version of Node.js and discord.js.
Any help would be appreciated. Thanks.
As of DJS v12, you have to go through the cache to get a user/channel/guild or use .fetch() to get the user from the API, but be warned the latter returns a Promise.
Basically, as long as the guild is already cached, just do client.guilds.cache.get(GUILD) and that should solve your error.
Im trying to take content of body into a variable but it says 0.
Where is wrong here? :|
var utc = 0;
request.get('http://localhost/actions.php?utc',function(err,response,body) {
utc = body;
});
console.log(utc);
Your log statement is executed earlier than the callback of the request call. Try to put log statement into the callback, right after the assignment.
async changeCarOwner(ctx, carNumber, newOwner) {
const carAsBytes = await ctx.stub.getState(carNumber);
if (!carAsBytes || carAsBytes.length === 0) {
throw new Error(`${carNumber} does not exist`);
}
const car = JSON.parse(carAsBytes.toString());
car.owner = newOwner
await ctx.stub.putState(carNumber, Buffer.from(JSON.stringify(car)));
}
}
I keep getting an error: Unexpected end of JSON input. Why? I am trying to update an existing key-value pair in couchDb using the above code.
This error happens at this line:
const car = JSON.parse(carAsBytes.toString());
It is due to the fact that carAsBytes.toString() does not evaluates to a properly formatted JSON string. The code you show seems fine, but the error is coming from elsewhere in your code.
Debugging tip: use the debugger statement to examine variables before the faulty line, simply add a console.log(carAsBytes.toString()) before it.
i am learning javascript and Node.js and came across this code. I have a user.js representing user schema and server.js that contains my post route.
UserSchema.methods.generateAuthToken = function() {
return user.save().then(()=> { //Return Statement 2
return token; //Return Statement 3
});
};
I want to understand what two return statements mean when user.save() is called and in 'then' we return a token. Why do we need 'return' ahead of 'user.save()'
Here's the 'POST route'
user.save().then(()=>{
return user.generateAuthToken(); //Return Statement 1
}).then((token) =>{
res.header('x-auth', token).send(user);
})
Why do we return 'user.generateAuthToken()' instead of just calling it ? Why are we using three return statements whereas according to my understanding no return statement is required as a promises automatically return something in the 'then' block.
Could someone please explain the flow here ? I would be very thankful to you.
Thanks.
You my friend are working with Promises..
(1st code)
when you call
user.save()
you are returning a Promise..the function may or may not end successfully..Promises have a
Promise.prototype.then
function..the first arg is a success function to be called when the function resolves(the real term)
In 2nd code..inside that 1st function you returned another Promise that's it(the whole then returns another Promise..but only if it resolves)
If you need to beat the crap out of JavaScript try googling Eloquent JavaScript (by Marijn Haverbecke)
Why do we need to 'return' ahead of 'user.save()'
This returns the promise that resolves the token. Without the return we'd have no way of accessing the token outside of the save function.
Why do we return 'user.generateAuthToken()' instead of just calling it?
Again, we need the token. If we just call the function, the save is performed but we don't have the token when the promise resolves (in this case it's used for the header of the response).
Why are we using three return statements whereas according to my understanding no return statement is required as a promises automatically return something in the 'then' block.
Your understanding is wrong. Whatever is returned from the promise is available to then, if nothing is returned, there is no parameter (in this case the token).
In the first function, user.save() will return a promise, and as you are returning the token in the then block of user.save(), promise will resolve the value of token.
In the second function if you haven't used return ahead of user.generateAuthToken();, it will just execute that function and you will be getting the results of user.save() in the then block.