Closed AtoraSuunva closed 6 years ago
https://github.com/AtlasTheBot/booru/tree/classes holds the in-dev version
Also, if someone knows how to refer to @typedef in other files help
nvm I fixy
// Another example, where we instantiate a booru and then use it
// instantiating a booru allows for you to do more complex things,
// like favoriting a post (if you provide an api token) or posting/viewing comments, etc.
async function example() {
const e9 = new Booru('e9', {token: 'goes here'})
let imgs = await e9.search(['cat', 'cute'], {limit: 1, random: true})
// Log the post url to the first image
console.log(imgs[0].postView)
// In the future, things like `e9.favorite(BooruImage)` or `e9.fetchComments(BooruImage)`
// Will be available (and maybe even <BooruImage>.favorite())
}
That was fast
Creating Boorus and .postView on BooruImages might be the only really new things, but with the new structure for the module get ready to see some cool features :)
resolveSite(site)
now returns null if it cannot resolvesites.json
is now formatted differently, .api
now maps to an object representing a site's API, instead of being the path for the search api. (Shouldn't break anything though, unless you relied on it)Booru.search(site, [tags], {opts})
still remains (with minor improvements)
tags
can now a be a stringPost
objects, which now have both JSDoc for properties and don't need .common
(No .commonfy()
anymore!), and can now have other methods/getters attached to them
<Post>.file_url
, <Post>.tags
, etc... Props are now there without having to run .commonfy
<Post>.postView
getter, which returns the post view url for that imageSearchResults
object, which extends an array and mostly acts like an array of Post
.first
& .last
getters for the first and last results.nextPage()
to search the next page of results.tagged(tags)
to only get posts tagged with 1 or more tags specified.blacklist(tags)
to remove posts tagged with 1 or more tags specifiedThis update is only really exciting if you love JSDoc or are me, because now I can fix bugs and tweak parts more easily and stay sane :)
I won't be releasing this until I test it out for a while.
For the curious (or adventurous), you can install the dev version (this one) with npm install --save booru@dev
Nothing should break, but it's better to be careful
this is done heck yea
Essentially rewrite the whole thing to make it more easily extensible in terms of supporting different boorus, with the final goal of adding more functionality than just searching boorus (Things like fetching the comments or allowing for login use to favorite pics or whatever.)
Backwards compatibility will still remain in some form, but might be removed in later releases so don't depend on it.
If you have any questions/comments/suggestions reply to this issue and I'll get back to you.
A very basic schema of what is going to happen is here:
[x] index.js // just requires/exports the required things
.postView(site, id)BooruImagesPosts have a .postView prop now!<Post>.common
getter to images/posts instead[x] src/
[X] new Post
[X] Constructor, params => data:Object, booru:IBooru
[X] .common, get that replicates old .commonfy() function
[X] Utils
[X] .jsonfy([images])
[X] .shuffle([arr])
[X] .randInt(min, max)
[X] .resolveSite(site/alias)
[X] Constants
[X] .sites
[X] .BooruError
[X] .userAgent
[X] .searchURI(site, tags, limit) =>
http://${site}${sites[site].api}${(sites[site].tagQuery) ? sites[site].tagQuery : 'tags'}=${tags.join('+')}&limit=${limit}
[X] sites.json
[X] src/booru
(site, [credentials])
Also coming is better JSDoc, for better intellisense :)