AtoraSuunva / booru

Searches boorus for images using some js magic
https://www.npmjs.com/package/booru
MIT License
75 stars 18 forks source link

Copy tags argument so it's not modified #103

Closed iguessthislldo closed 3 months ago

iguessthislldo commented 3 months ago

I was passing the tags array from this object into search with random: true periodically and noticed order:random was being appended each time. With unauthenticated Danbooru, this quickly leads to hitting the tag limit.

[17.03.2024 18:07.02.955] [LOG]   {
  weight: 1,
  site: 'danbooru.donmai.us',
  tags: [ 'hatsune_miku', 'rating:general' ]
}

...

[17.03.2024 18:07.20.369] [LOG]   {
  weight: 1,
  site: 'danbooru.donmai.us',
  tags: [ 'hatsune_miku', 'rating:general', 'order:random' ]
}
[17.03.2024 18:07.20.786] [ERROR] ERROR: Getting posts BooruError: Received HTTP 422 from booru: 'PostQuery::TagLimitError'

...

[17.03.2024 18:07.25.787] [LOG]   {
  weight: 1,
  site: 'danbooru.donmai.us',
  tags: [ 'hatsune_miku', 'rating:general', 'order:random', 'order:random' ]
}
[17.03.2024 18:07.25.932] [ERROR] ERROR: Getting posts BooruError: Received HTTP 422 from booru: 'PostQuery::TagLimitError'

This could be worked around easily by passing in a copy of tags into search, but I'd like to contribute some features, so this seemed like a good place to start.

I changed search to copy the tags array instead of modifying it directly. Other changes were prompted by the typescript compiler and trying to guess what it wanted. This is my very first time doing anything typescript, so if there's something wrong here, that's why.

AtoraSuunva commented 3 months ago

Oh whoops, never caught this.

I'll make a release for it.

AtoraSuunva commented 3 months ago

Released https://www.npmjs.com/package/booru/v/2.6.5