Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on node-v11.9.0-win-x64 #26

Closed
ProjectAGM opened this issue Feb 28, 2019 · 8 comments
Closed

Error on node-v11.9.0-win-x64 #26

ProjectAGM opened this issue Feb 28, 2019 · 8 comments
Assignees
Labels

Comments

@ProjectAGM
Copy link

ProjectAGM commented Feb 28, 2019

Failing to get images using const e9 = await Booru.search('e9', [tag]);.
Always returns this error:
TypeError: tags[i].toLowerCase is not a function at expandTags (E:\files\db indexing node js\@njs_api\node_modules\booru\src\Constants.js:85:37) at Object.module.exports.searchURI (E:\files\db indexing node js\@njs_api\node_modules\booru\src\Constants.js:68:9) at Booru._doSearchRequest (E:\files\db indexing node js\@njs_api\node_modules\booru\src\boorus\Booru.js:109:31) at Booru.search (E:\files\db indexing node js\@njs_api\node_modules\booru\src\boorus\Booru.js:75:17) at Function.search (E:\files\db indexing node js\@njs_api\node_modules\booru\index.js:77:28) at getImages (E:\files\db indexing node js\@njs_api\dscBot.js:244:28) at DCIE (E:\files\db indexing node js\@njs_api\dscBot.js:132:11) at Client.client.on.message (E:\files\db indexing node js\@njs_api\dscBot.js:32:7) at Client.emit (events.js:197:13) at MessageCreateHandler.handle (E:\files\db indexing node js\@njs_api\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)

I have also tested the same code on other versions of node js and it worked perfectly.
Sorry if this issue is already reported, but I havent been able to get it to work.

@ProjectAGM ProjectAGM changed the title Error on node-v11.9.0-win-x64 Error on node-v11.9.0-win-x64 Feb 28, 2019
@AtoraSuunva
Copy link
Owner

Can you provide a full snippet that causes the error? I can't reproduce it.

const booru = require('booru')

;(async () => {  
  const res = await booru.search('e9', ['cat'])
  console.log(res[0].postView)
})()
> .\node-v11.9.0-win-x64\node.exe .\index.js
https://e926.net/post/show/1803860

> .\node-v11.9.0-win-x64\node.exe -v
v11.9.0

On a (semi-related) note, nvm doesn't seem to be able to install node v11.9?

@AtoraSuunva AtoraSuunva self-assigned this Feb 28, 2019
@ProjectAGM
Copy link
Author

ProjectAGM commented Feb 28, 2019

I can't provide the snippet as of right now (I don't have access to a computer currently). What I can say about the Issue is that this error occurs when I attempt to search for images on this node version. I know this because I usually run the exact same script (not a single change) on another node version and it works without a single error and gets images as reqeusted. About the code im using it in, its inside a discord bot (btw. this bot isn't related to the one you made) as an command. The command calls a function and this function then gets the images as specified in the other comment. There isnt really much code to getting the images themselves and I also tried running this function (slightly modified) outside of this script without success. About the node version - 11.9.0 is the one I use on my usb stick, and its the one causing the error. I don't know if the fact that its running off a usb stick could be causing the problem (when the script was working it was running with node normally installed, I dont know which exact version though).

I'll post the function as soon as I can (2-3 days).

@AtoraSuunva
Copy link
Owner

I can wait until then

@ProjectAGM
Copy link
Author

ProjectAGM commented Mar 4, 2019

I just looked into the issue on my laptop (node.js v10.15.0) ... and interestingly enough it now seems that my function doesn't work here anymore either. (At this point it could be that i'm just to incompetent to use the module and not that its a bug (which still doesn't explain why it worked before)) This is wierd, because the last time I ran it, it was working perfectly fine. Anyways, this is the code (that was working before, i haven't changed anything):

const Booru = require('booru');
async function getImages (tagF,msg) {
  //HQE 1.1
  const tag = tagF.split("+");
  try {
    const e9 = await Booru.search('e9', [tag]);
    f1 = new Discord.RichEmbed()
    .setImage(e9[0].file_url);
    msg.channel.send(f1)
  } catch (e) {console.log(e);}
  try {
    const hh = await Booru.search('hh', [tag]);
    f2 = new Discord.RichEmbed()
    .setImage(hh[0].file_url);
    msg.channel.send(f2)
  } catch (e) {}
  try {
    const db = await Booru.search('db', [tag]);
    f3 = new Discord.RichEmbed()
    .setImage(db[0].file_url);
    msg.channel.send(f3);
  } catch (e) {}
  try {
    const kc = await Booru.search('kc', [tag]);
    f4 = new Discord.RichEmbed()
    .setImage(kc[0].file_url);
  msg.channel.send(f4);
  } catch (e) {}
  try {
    const kn = await Booru.search('kn', [tag]);
    f5 = new Discord.RichEmbed()
    .setImage(kn[0].file_url);
    msg.channel.send(f5);
  } catch (e) {}
  try {
    const yd = await Booru.search('yd', [tag]);
    f6 = new Discord.RichEmbed()
    .setImage(yd[0].file_url);
    msg.channel.send(f6);
  } catch (e) {}
  try {
    const gb = await Booru.search('gb', [tag]);
    f7 = new Discord.RichEmbed()
    .setImage(gb[0].file_url);
    msg.channel.send(f7);
  } catch (e) {}
  try {
    const r34 = await Booru.search('r34', [tag]);
    f8 = new Discord.RichEmbed()
    .setImage(r34[0].file_url);
    msg.channel.send(f8);
  } catch (e) {}
  try {
    const sb = await Booru.search('sb', [tag]);
    f9 = new Discord.RichEmbed()
    .setImage(sb[0].file_url);
    msg.channel.send(f9);
  } catch (e) {}
  try {
    const tb = await Booru.search('tb', [tag]);
    f10 = new Discord.RichEmbed()
    .setImage(tb[0].file_url);
    msg.channel.send(f10);
  } catch (e) {}
  try {
    const xb = await Booru.search('xb', [tag]);
    f11 = new Discord.RichEmbed()
    .setImage(xb[0].file_url);
    msg.channel.send(f11);
  } catch (e) {}
  try {
    const yh = await Booru.search('yh', [tag]);
    f12 = new Discord.RichEmbed()
    .setImage(yh[0].file_url);
    msg.channel.send(f12);
  } catch (e) {}
  try {
    const lb = await Booru.search('lb', [tag]);
    f13 = new Discord.RichEmbed()
    .setImage(lb[0].file_url);
    msg.channel.send(f13);
  } catch (e) {}
  try {
    const pa = await Booru.search('pa', [tag]);
    f14 = new Discord.RichEmbed()
    .setImage(pa[0].file_url);
    msg.channel.send(f14);
  } catch (e) {}
  try {
    const dp = await Booru.search('dp', [tag]);
    f15 = new Discord.RichEmbed()
    .setImage(dp[0].file_url);
    msg.channel.send(f15);
  } catch (e) {}
  try {
    const fb = await Booru.search('fb', [tag]);
    f16 = new Discord.RichEmbed()
    .setImage(fb[0].file_url);
    msg.channel.send(f16);
  } catch (e) {}
  try {
    const rb = await Booru.search('rb', [tag]);
    f17 = new Discord.RichEmbed()
    .setImage(rb[0].file_url);
    msg.channel.send(f17);
  } catch (e) {}
}

Note: the code is inside a try because some sites sometimes don't react which causes problems.
A similar code I was using in another function, slightly different:

//It's essentially the same function but the "try" contains this:
try {
    const e9 = await booru.search('e9', [tag]);
    Stream.write(e9[0].file_url+"\n");
    console.log(e9);
  } catch (e) {console.log(e)}

@ProjectAGM
Copy link
Author

ProjectAGM commented Mar 4, 2019

UPDATE: I am simply just to incompetent to use the module... I managed to fix my code. What I don't get is why it sometimes was/wasn't working before...

//this is the code I use now
try {
    const e9 = await booru.search('e9',tag, {limit: 1, random: false});
    e9.forEach(i => {Stream.write(i.common.file_url+"\n")})
  } catch (e) {console.log(e)}

@ProjectAGM
Copy link
Author

ProjectAGM commented Mar 4, 2019

By the way... (I know this isn't related but I couldn't find any info elsewhere) since I haven't found a way, is there a way to query all sites at once?

@AtoraSuunva
Copy link
Owner

I'm also confused as to why it worked before, since [tag] should've never worked because that makes an array inside an array, which the module isn't designed to work with.

There also isn't a built-in way to search every booru at once in parallel, mostly because it's not something I thought someone would do (I do have some code that searches every booru, although in serial.)

You could try something like this (although you'd want to maybe wrap it in a function that returns a Promise that resolves with null/undefined instead of rejecting, in case of an error)

return Promise.all(
    Object.keys(Booru.sites).map(s => Booru.search(s, tags, opts))
)

also .common is deprecated, just use i.file_url directly

@ProjectAGM
Copy link
Author

ProjectAGM commented Mar 4, 2019

I'm actually working on this right now, and I actually ended up with a similar Promise-based setup for running them in parallel. The only other problem I have encountered is that (as I said before) some sites don't respond, so I have to set a timeout, or else I have to wait literally forever for it to continue. Problem here is that I can't find a simple way to end the main function from inside a nested function.

Edit: Restructuring my code solved the problem. Its working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants