booru 2.6.9 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/Constants.d.ts +7 -5
- package/dist/Constants.d.ts.map +1 -0
- package/dist/Constants.js +15 -10
- package/dist/Constants.js.map +1 -1
- package/dist/Utils.d.ts +12 -3
- package/dist/Utils.d.ts.map +1 -0
- package/dist/Utils.js +49 -19
- package/dist/Utils.js.map +1 -1
- package/dist/boorus/Booru.d.ts +34 -4
- package/dist/boorus/Booru.d.ts.map +1 -0
- package/dist/boorus/Booru.js +114 -37
- package/dist/boorus/Booru.js.map +1 -1
- package/dist/boorus/Derpibooru.d.ts +4 -10
- package/dist/boorus/Derpibooru.d.ts.map +1 -0
- package/dist/boorus/Derpibooru.js +0 -8
- package/dist/boorus/Derpibooru.js.map +1 -1
- package/dist/boorus/XmlBooru.d.ts +2 -8
- package/dist/boorus/XmlBooru.d.ts.map +1 -0
- package/dist/boorus/XmlBooru.js +0 -8
- package/dist/boorus/XmlBooru.js.map +1 -1
- package/dist/index.d.ts +22 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -5
- package/dist/index.js.map +1 -1
- package/dist/sites.json +231 -1
- package/dist/structures/InternalSearchParameters.d.ts +2 -1
- package/dist/structures/InternalSearchParameters.d.ts.map +1 -0
- package/dist/structures/InternalSearchParameters.js.map +1 -1
- package/dist/structures/Post.d.ts +2 -1
- package/dist/structures/Post.d.ts.map +1 -0
- package/dist/structures/Post.js +46 -44
- package/dist/structures/Post.js.map +1 -1
- package/dist/structures/SearchParameters.d.ts +5 -4
- package/dist/structures/SearchParameters.d.ts.map +1 -0
- package/dist/structures/SearchParameters.js.map +1 -1
- package/dist/structures/SearchResults.d.ts +4 -3
- package/dist/structures/SearchResults.d.ts.map +1 -0
- package/dist/structures/SearchResults.js +20 -12
- package/dist/structures/SearchResults.js.map +1 -1
- package/dist/structures/Site.d.ts +3 -2
- package/dist/structures/Site.d.ts.map +1 -0
- package/dist/structures/Site.js.map +1 -1
- package/dist/structures/SiteApi.d.ts +3 -0
- package/dist/structures/SiteApi.d.ts.map +1 -0
- package/dist/structures/SiteApi.js.map +1 -1
- package/dist/structures/SiteInfo.d.ts +2 -1
- package/dist/structures/SiteInfo.d.ts.map +1 -0
- package/dist/structures/SiteInfo.js.map +1 -1
- package/dist/structures/Tag.d.ts +42 -0
- package/dist/structures/Tag.d.ts.map +1 -0
- package/dist/structures/Tag.js +52 -0
- package/dist/structures/Tag.js.map +1 -0
- package/dist/structures/TagListParameters.d.ts +14 -0
- package/dist/structures/TagListParameters.d.ts.map +1 -0
- package/dist/structures/TagListParameters.js +7 -0
- package/dist/structures/TagListParameters.js.map +1 -0
- package/dist/structures/TagListResults.d.ts +53 -0
- package/dist/structures/TagListResults.d.ts.map +1 -0
- package/dist/structures/TagListResults.js +73 -0
- package/dist/structures/TagListResults.js.map +1 -0
- package/package.json +17 -34
- package/readme.md +22 -5
package/dist/sites.json
CHANGED
|
@@ -1 +1,231 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"e621.net": {
|
|
3
|
+
"domain": "e621.net",
|
|
4
|
+
"aliases": [
|
|
5
|
+
"e6",
|
|
6
|
+
"e621"
|
|
7
|
+
],
|
|
8
|
+
"nsfw": true,
|
|
9
|
+
"api": {
|
|
10
|
+
"search": "/posts.json?",
|
|
11
|
+
"postView": "/post/show/",
|
|
12
|
+
"tagList": "/tags.json?"
|
|
13
|
+
},
|
|
14
|
+
"random": true
|
|
15
|
+
},
|
|
16
|
+
"e926.net": {
|
|
17
|
+
"domain": "e926.net",
|
|
18
|
+
"aliases": [
|
|
19
|
+
"e9",
|
|
20
|
+
"e926"
|
|
21
|
+
],
|
|
22
|
+
"nsfw": false,
|
|
23
|
+
"api": {
|
|
24
|
+
"search": "/posts.json?",
|
|
25
|
+
"postView": "/post/show/",
|
|
26
|
+
"tagList": "/tags.json?"
|
|
27
|
+
},
|
|
28
|
+
"random": true,
|
|
29
|
+
"defaultTags": ["rating:safe"]
|
|
30
|
+
},
|
|
31
|
+
"hypnohub.net": {
|
|
32
|
+
"domain": "hypnohub.net",
|
|
33
|
+
"aliases": [
|
|
34
|
+
"hh",
|
|
35
|
+
"hypno",
|
|
36
|
+
"hypnohub"
|
|
37
|
+
],
|
|
38
|
+
"nsfw": true,
|
|
39
|
+
"api": {
|
|
40
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
41
|
+
"postView": "/post/show/",
|
|
42
|
+
"tagList": "/index.php?page=dapi&s=tag&q=index&json=1&"
|
|
43
|
+
},
|
|
44
|
+
"paginate": "pid",
|
|
45
|
+
"random": false
|
|
46
|
+
},
|
|
47
|
+
"danbooru.donmai.us": {
|
|
48
|
+
"domain": "danbooru.donmai.us",
|
|
49
|
+
"aliases": [
|
|
50
|
+
"db",
|
|
51
|
+
"dan",
|
|
52
|
+
"danbooru"
|
|
53
|
+
],
|
|
54
|
+
"nsfw": true,
|
|
55
|
+
"api": {
|
|
56
|
+
"search": "/posts.json?",
|
|
57
|
+
"postView": "/posts/",
|
|
58
|
+
"tagList": "/tags.json?"
|
|
59
|
+
},
|
|
60
|
+
"random": true
|
|
61
|
+
},
|
|
62
|
+
"konachan.com": {
|
|
63
|
+
"domain": "konachan.com",
|
|
64
|
+
"aliases": [
|
|
65
|
+
"kc",
|
|
66
|
+
"konac",
|
|
67
|
+
"kcom"
|
|
68
|
+
],
|
|
69
|
+
"nsfw": true,
|
|
70
|
+
"api": {
|
|
71
|
+
"search": "/post.json?",
|
|
72
|
+
"postView": "/post/show/",
|
|
73
|
+
"tagList": "/tag.json?"
|
|
74
|
+
},
|
|
75
|
+
"random": true
|
|
76
|
+
},
|
|
77
|
+
"konachan.net": {
|
|
78
|
+
"domain": "konachan.net",
|
|
79
|
+
"aliases": [
|
|
80
|
+
"kn",
|
|
81
|
+
"konan",
|
|
82
|
+
"knet"
|
|
83
|
+
],
|
|
84
|
+
"nsfw": false,
|
|
85
|
+
"api": {
|
|
86
|
+
"search": "/post.json?",
|
|
87
|
+
"postView": "/post/show/",
|
|
88
|
+
"tagList": "/tag.json?"
|
|
89
|
+
},
|
|
90
|
+
"random": true
|
|
91
|
+
},
|
|
92
|
+
"yande.re": {
|
|
93
|
+
"domain": "yande.re",
|
|
94
|
+
"aliases": [
|
|
95
|
+
"yd",
|
|
96
|
+
"yand",
|
|
97
|
+
"yandere"
|
|
98
|
+
],
|
|
99
|
+
"nsfw": true,
|
|
100
|
+
"api": {
|
|
101
|
+
"search": "/post.json?",
|
|
102
|
+
"postView": "/post/show/",
|
|
103
|
+
"tagList": "/tag.json?"
|
|
104
|
+
},
|
|
105
|
+
"random": true
|
|
106
|
+
},
|
|
107
|
+
"gelbooru.com": {
|
|
108
|
+
"domain": "gelbooru.com",
|
|
109
|
+
"aliases": [
|
|
110
|
+
"gb",
|
|
111
|
+
"gel",
|
|
112
|
+
"gelbooru"
|
|
113
|
+
],
|
|
114
|
+
"nsfw": true,
|
|
115
|
+
"api": {
|
|
116
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
117
|
+
"postView": "/index.php?page=post&s=view&json=1&id=",
|
|
118
|
+
"tagList": "/index.php?page=dapi&s=tag&q=index&json=1&"
|
|
119
|
+
},
|
|
120
|
+
"paginate": "pid",
|
|
121
|
+
"random": false
|
|
122
|
+
},
|
|
123
|
+
"rule34.xxx": {
|
|
124
|
+
"domain": "api.rule34.xxx",
|
|
125
|
+
"aliases": [
|
|
126
|
+
"r34",
|
|
127
|
+
"rule34"
|
|
128
|
+
],
|
|
129
|
+
"nsfw": true,
|
|
130
|
+
"api": {
|
|
131
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
132
|
+
"postView": "/index.php?page=post&s=view&json=1&id=",
|
|
133
|
+
"tagList": "/index.php?page=dapi&s=tag&q=index&json=1&"
|
|
134
|
+
},
|
|
135
|
+
"paginate": "pid",
|
|
136
|
+
"random": false
|
|
137
|
+
},
|
|
138
|
+
"safebooru.org": {
|
|
139
|
+
"domain": "safebooru.org",
|
|
140
|
+
"aliases": [
|
|
141
|
+
"sb",
|
|
142
|
+
"safe",
|
|
143
|
+
"safebooru"
|
|
144
|
+
],
|
|
145
|
+
"nsfw": false,
|
|
146
|
+
"api": {
|
|
147
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
148
|
+
"postView": "/index.php?page=post&s=view&json=1&id=",
|
|
149
|
+
"tagList": "/index.php?page=dapi&s=tag&q=index&json=1&"
|
|
150
|
+
},
|
|
151
|
+
"paginate": "pid",
|
|
152
|
+
"random": false
|
|
153
|
+
},
|
|
154
|
+
"tbib.org": {
|
|
155
|
+
"domain": "tbib.org",
|
|
156
|
+
"aliases": [
|
|
157
|
+
"tb",
|
|
158
|
+
"tbib",
|
|
159
|
+
"big"
|
|
160
|
+
],
|
|
161
|
+
"nsfw": false,
|
|
162
|
+
"api": {
|
|
163
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
164
|
+
"postView": "/index.php?page=post&s=view&json=1&id=",
|
|
165
|
+
"tagList": "/index.php?page=dapi&s=tag&q=index&json=1&"
|
|
166
|
+
},
|
|
167
|
+
"paginate": "pid",
|
|
168
|
+
"random": false
|
|
169
|
+
},
|
|
170
|
+
"xbooru.com": {
|
|
171
|
+
"domain": "xbooru.com",
|
|
172
|
+
"aliases": [
|
|
173
|
+
"xb",
|
|
174
|
+
"xbooru"
|
|
175
|
+
],
|
|
176
|
+
"nsfw": true,
|
|
177
|
+
"api": {
|
|
178
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
179
|
+
"postView": "/index.php?page=post&s=view&json=1&id=",
|
|
180
|
+
"tagList": "/index.php?page=dapi&s=tag&q=index&json=1&"
|
|
181
|
+
},
|
|
182
|
+
"paginate": "pid",
|
|
183
|
+
"random": false
|
|
184
|
+
},
|
|
185
|
+
"rule34.paheal.net": {
|
|
186
|
+
"domain": "rule34.paheal.net",
|
|
187
|
+
"type": "xml",
|
|
188
|
+
"aliases": [
|
|
189
|
+
"pa",
|
|
190
|
+
"paheal"
|
|
191
|
+
],
|
|
192
|
+
"nsfw": true,
|
|
193
|
+
"api": {
|
|
194
|
+
"search": "/api/danbooru/find_posts?",
|
|
195
|
+
"postView": "/post/view/"
|
|
196
|
+
},
|
|
197
|
+
"random": false
|
|
198
|
+
},
|
|
199
|
+
"derpibooru.org": {
|
|
200
|
+
"domain": "derpibooru.org",
|
|
201
|
+
"type": "derpi",
|
|
202
|
+
"aliases": [
|
|
203
|
+
"dp",
|
|
204
|
+
"derp",
|
|
205
|
+
"derpi",
|
|
206
|
+
"derpibooru"
|
|
207
|
+
],
|
|
208
|
+
"nsfw": true,
|
|
209
|
+
"api": {
|
|
210
|
+
"search": "/api/v1/json/search/images?",
|
|
211
|
+
"postView": "/images/"
|
|
212
|
+
},
|
|
213
|
+
"tagQuery": "q",
|
|
214
|
+
"tagJoin": ",",
|
|
215
|
+
"random": "sf=random"
|
|
216
|
+
},
|
|
217
|
+
"realbooru.com": {
|
|
218
|
+
"domain": "realbooru.com",
|
|
219
|
+
"aliases": [
|
|
220
|
+
"rb",
|
|
221
|
+
"realbooru"
|
|
222
|
+
],
|
|
223
|
+
"nsfw": true,
|
|
224
|
+
"api": {
|
|
225
|
+
"search": "/index.php?page=dapi&s=post&q=index&json=1&",
|
|
226
|
+
"postView": "/index.php?page=post&s=view&id="
|
|
227
|
+
},
|
|
228
|
+
"paginate": "pid",
|
|
229
|
+
"random": false
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module Structures
|
|
4
4
|
*/
|
|
5
|
-
import SearchParameters from './SearchParameters';
|
|
5
|
+
import type SearchParameters from './SearchParameters';
|
|
6
6
|
/**
|
|
7
7
|
* Interface for {@link Booru}'s **private internal** search params pls no use
|
|
8
8
|
*/
|
|
@@ -14,3 +14,4 @@ export default interface InternalSearchParameters extends SearchParameters {
|
|
|
14
14
|
/** The tags used in the search */
|
|
15
15
|
tags?: string[];
|
|
16
16
|
}
|
|
17
|
+
//# sourceMappingURL=InternalSearchParameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalSearchParameters.d.ts","sourceRoot":"","sources":["../../src/structures/InternalSearchParameters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAA;AAEtD;;GAEG;AAEH,MAAM,CAAC,OAAO,WAAW,wBAAyB,SAAQ,gBAAgB;IACxE,4CAA4C;IAC5C,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalSearchParameters.js","sourceRoot":"","sources":["../../src/structures/InternalSearchParameters.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
1
|
+
{"version":3,"file":"InternalSearchParameters.js","sourceRoot":"","sources":["../../src/structures/InternalSearchParameters.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * @packageDocumentation\n * @module Structures\n */\n\nimport type SearchParameters from './SearchParameters'\n\n/**\n * Interface for {@link Booru}'s **private internal** search params pls no use\n */\n\nexport default interface InternalSearchParameters extends SearchParameters {\n /** The uri to override with, if provided */\n uri?: string | null\n /** If `order:random` should be faked */\n fakeLimit?: number\n /** The tags used in the search */\n tags?: string[]\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module Structures
|
|
4
4
|
*/
|
|
5
|
-
import Booru from '../boorus/Booru';
|
|
5
|
+
import type Booru from '../boorus/Booru';
|
|
6
6
|
/**
|
|
7
7
|
* An image from a booru with a few common props
|
|
8
8
|
*
|
|
@@ -132,3 +132,4 @@ export default class Post {
|
|
|
132
132
|
*/
|
|
133
133
|
get common(): this;
|
|
134
134
|
}
|
|
135
|
+
//# sourceMappingURL=Post.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Post.d.ts","sourceRoot":"","sources":["../../src/structures/Post.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAA;AA4GxC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,qCAAqC;IAC9B,KAAK,EAAE,KAAK,CAAA;IACnB,kCAAkC;IAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,6BAA6B;IACtB,MAAM,EAAE,MAAM,CAAA;IACrB,4BAA4B;IACrB,KAAK,EAAE,MAAM,CAAA;IACpB,uDAAuD;IAChD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,0DAA0D;IACnD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,yDAAyD;IAClD,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,mDAAmD;IAC5C,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,sDAAsD;IAC/C,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,qDAAqD;IAC9C,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,0BAA0B;IACnB,EAAE,EAAE,MAAM,CAAA;IACjB,4EAA4E;IACrE,SAAS,EAAE,OAAO,CAAA;IACzB,4BAA4B;IACrB,IAAI,EAAE,MAAM,EAAE,CAAA;IACrB,6BAA6B;IACtB,KAAK,EAAE,MAAM,CAAA;IACpB,4CAA4C;IACrC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACjC;;;OAGG;IACI,MAAM,EAAE,MAAM,CAAA;IACrB,wCAAwC;IACjC,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IAC9B,+CAA+C;IAC/C,SAAS,CAAC,IAAI,EAAE,GAAG,CAAA;IAEnB;;;;;OAKG;gBACS,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK;IA4GnC;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,GAAG,IAAI,CAE5B;IAED;;;OAGG;IACH,IAAI,UAAU,IAAI,MAAM,GAAG,IAAI,CAE9B;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,GAAG,IAAI,CAEjC;IAED;;;OAGG;IACH,IAAI,YAAY,IAAI,MAAM,GAAG,IAAI,CAEhC;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED;;;OAGG;IACH,IAAI,cAAc,IAAI,MAAM,GAAG,IAAI,CAElC;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,GAAG,IAAI,CAEjC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;;;;;;;;;;;;;OAeG;IACH,IAAI,MAAM,IAAI,IAAI,CAGjB;CACF"}
|
package/dist/structures/Post.js
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* @module Structures
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const common = (0, util_1.deprecate)(() => { }, 'Common is now deprecated, just access the properties directly');
|
|
7
|
+
const node_util_1 = require("node:util");
|
|
8
|
+
const common = (0, node_util_1.deprecate)(() => { }, 'Common is now deprecated, just access the properties directly');
|
|
10
9
|
/**
|
|
11
10
|
* Tries to figure out what the image url should be
|
|
12
11
|
*
|
|
@@ -15,22 +14,26 @@ const common = (0, util_1.deprecate)(() => { }, 'Common is now deprecated, just
|
|
|
15
14
|
* @param {Booru} booru so hard
|
|
16
15
|
*/
|
|
17
16
|
function parseImageUrl(url, data, booru) {
|
|
17
|
+
let outUrl = url;
|
|
18
18
|
// If the image's file_url is *still* undefined or the source is empty or it's deleted
|
|
19
19
|
// Thanks danbooru *grumble grumble*
|
|
20
|
-
if (!
|
|
20
|
+
if (!outUrl || outUrl.trim() === '' || data.is_deleted) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
24
|
-
|
|
23
|
+
if (outUrl.startsWith('/data')) {
|
|
24
|
+
outUrl = `https://danbooru.donmai.us${outUrl}`;
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
if (outUrl.startsWith('/cached')) {
|
|
27
|
+
outUrl = `https://danbooru.donmai.us${outUrl}`;
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
29
|
+
if (outUrl.startsWith('/_images')) {
|
|
30
|
+
outUrl = `https://dollbooru.org${outUrl}`;
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
33
|
-
|
|
32
|
+
if (outUrl.startsWith('//derpicdn.net')) {
|
|
33
|
+
outUrl = `https:${data.image}`;
|
|
34
|
+
}
|
|
35
|
+
if (outUrl.startsWith('/_thumbs')) {
|
|
36
|
+
outUrl = `https://rule34.paheal.net${outUrl}`;
|
|
34
37
|
}
|
|
35
38
|
// Why???
|
|
36
39
|
if (!data.file_url && data.directory !== undefined) {
|
|
@@ -41,16 +44,16 @@ function parseImageUrl(url, data, booru) {
|
|
|
41
44
|
// for some ungodly reason
|
|
42
45
|
// I despise the danbooru api honestly
|
|
43
46
|
const directory = data.directory ?? `${data.hash.substr(0, 2)}/${data.hash.substr(2, 2)}`;
|
|
44
|
-
|
|
47
|
+
outUrl = `//${booru.domain}/images/${directory}/${data.image}`;
|
|
45
48
|
}
|
|
46
|
-
if (!
|
|
47
|
-
|
|
49
|
+
if (!outUrl.startsWith('http')) {
|
|
50
|
+
outUrl = `https:${outUrl}`;
|
|
48
51
|
}
|
|
49
52
|
if (booru.domain === 'xbooru.com' &&
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
outUrl.startsWith('https://api-cdn.rule34.xxx/')) {
|
|
54
|
+
outUrl = outUrl.replace('https://api-cdn.rule34.xxx/', 'https://xbooru.com/');
|
|
52
55
|
}
|
|
53
|
-
return encodeURI(
|
|
56
|
+
return encodeURI(outUrl);
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
56
59
|
* Takes and transforms tags from the booru's api into a common format
|
|
@@ -63,7 +66,7 @@ function getTags(data) {
|
|
|
63
66
|
if (Array.isArray(data.tags)) {
|
|
64
67
|
tags = data.tags;
|
|
65
68
|
}
|
|
66
|
-
else if (data.tags
|
|
69
|
+
else if (data.tags?.general) {
|
|
67
70
|
tags = Object.values(data.tags).flat();
|
|
68
71
|
}
|
|
69
72
|
else if (typeof data.tags === 'string') {
|
|
@@ -148,44 +151,43 @@ class Post {
|
|
|
148
151
|
* @param {Booru} booru The booru that created the image
|
|
149
152
|
*/
|
|
150
153
|
constructor(data, booru) {
|
|
151
|
-
// eslint-disable-next-line complexity
|
|
152
154
|
// Damn wild mix of boorus
|
|
153
155
|
this.data = data;
|
|
154
156
|
this.booru = booru;
|
|
155
157
|
// Again, thanks danbooru
|
|
156
158
|
const deletedOrBanned = data.is_deleted || data.is_banned;
|
|
157
|
-
this.fileUrl = parseImageUrl(data.file_url
|
|
158
|
-
data.image
|
|
159
|
-
(deletedOrBanned ? data.source : undefined)
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
this.fileUrl = parseImageUrl(data.file_url ??
|
|
160
|
+
data.image ??
|
|
161
|
+
(deletedOrBanned ? data.source : undefined) ??
|
|
162
|
+
data.file?.url ??
|
|
163
|
+
data.representations?.full, data, booru);
|
|
162
164
|
this.available = !deletedOrBanned && this.fileUrl !== null;
|
|
163
|
-
this.height = parseInt(data.height
|
|
164
|
-
this.width = parseInt(data.width
|
|
165
|
-
this.sampleUrl = parseImageUrl(data.sample_url
|
|
166
|
-
data.large_file_url
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.sampleHeight = parseInt(data.sample_height
|
|
170
|
-
this.sampleWidth = parseInt(data.sample_width
|
|
171
|
-
this.previewUrl = parseImageUrl(data.preview_url
|
|
172
|
-
data.preview_file_url
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.previewHeight = parseInt(data.preview_height
|
|
176
|
-
this.previewWidth = parseInt(data.preview_width
|
|
165
|
+
this.height = Number.parseInt(data.height ?? data.image_height ?? data.file?.height, 10);
|
|
166
|
+
this.width = Number.parseInt(data.width ?? data.image_width ?? data.file?.width, 10);
|
|
167
|
+
this.sampleUrl = parseImageUrl(data.sample_url ??
|
|
168
|
+
data.large_file_url ??
|
|
169
|
+
data.representations?.large ??
|
|
170
|
+
data.sample?.url, data, booru);
|
|
171
|
+
this.sampleHeight = Number.parseInt(data.sample_height ?? data.sample?.height, 10);
|
|
172
|
+
this.sampleWidth = Number.parseInt(data.sample_width ?? data.sample?.width, 10);
|
|
173
|
+
this.previewUrl = parseImageUrl(data.preview_url ??
|
|
174
|
+
data.preview_file_url ??
|
|
175
|
+
data.representations?.small ??
|
|
176
|
+
data.preview?.url, data, booru);
|
|
177
|
+
this.previewHeight = Number.parseInt(data.preview_height ?? data.preview?.height, 10);
|
|
178
|
+
this.previewWidth = Number.parseInt(data.preview_width ?? data.preview?.width, 10);
|
|
177
179
|
this.id = data.id ? data.id.toString() : 'No ID available';
|
|
178
180
|
this.tags = getTags(data);
|
|
179
181
|
if (data.score && data.score.total !== undefined) {
|
|
180
182
|
this.score = data.score.total;
|
|
181
183
|
}
|
|
182
184
|
else {
|
|
183
|
-
this.score = data.score ? parseInt(data.score, 10) : data.score;
|
|
185
|
+
this.score = data.score ? Number.parseInt(data.score, 10) : data.score;
|
|
184
186
|
}
|
|
185
|
-
this.source = data.source
|
|
187
|
+
this.source = data.source ?? data.sources ?? data.source_url;
|
|
186
188
|
this.rating =
|
|
187
|
-
data.rating
|
|
188
|
-
/(safe|suggestive|questionable|explicit)/i.exec(data.tags)
|
|
189
|
+
data.rating ??
|
|
190
|
+
/(safe|suggestive|questionable|explicit)/i.exec(data.tags) ??
|
|
189
191
|
'u';
|
|
190
192
|
if (Array.isArray(this.rating)) {
|
|
191
193
|
this.rating = this.rating[0];
|
|
@@ -210,7 +212,7 @@ class Post {
|
|
|
210
212
|
this.createdAt = new Date(data.change * 1000);
|
|
211
213
|
}
|
|
212
214
|
else {
|
|
213
|
-
this.createdAt = new Date(data.created_at
|
|
215
|
+
this.createdAt = new Date(data.created_at ?? data.date);
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Post.js","sourceRoot":"","sources":["../../src/structures/Post.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,+BAAgC;AAGhC,yEAAyE;AACzE,MAAM,MAAM,GAAG,IAAA,gBAAS,EACtB,GAAG,EAAE,GAAE,CAAC,EACR,+DAA+D,CAChE,CAAA;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,GAAW,EAAE,IAAS,EAAE,KAAY;IACzD,sFAAsF;IACtF,oCAAoC;IACpC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACjD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,GAAG,GAAG,6BAA6B,GAAG,EAAE,CAAA;IAC1C,CAAC;IAED,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,GAAG,GAAG,6BAA6B,GAAG,EAAE,CAAA;IAC1C,CAAC;IAED,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,GAAG,GAAG,wBAAwB,GAAG,EAAE,CAAA;IACrC,CAAC;IAED,IAAI,GAAG,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACrC,GAAG,G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C,CAAA;QAC/C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,CAAA;QACzD,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED;;;OAGG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAED;;;OAGG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,IAAI,MAAM;QACR,MAAM,EAAE,CAAA;QACR,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAxPD,uBAwPC","sourcesContent":["/**\n * @packageDocumentation\n * @module Structures\n */\n\nimport { deprecate } from 'node:util'\nimport type Booru from '../boorus/Booru'\n\nconst common = deprecate(\n () => {},\n 'Common is now deprecated, just access the properties directly',\n)\n\n/**\n * Tries to figure out what the image url should be\n *\n * @param {string} url why\n * @param {*} data boorus\n * @param {Booru} booru so hard\n */\nfunction parseImageUrl(url: string, data: any, booru: Booru): string | null {\n let outUrl = url\n\n // If the image's file_url is *still* undefined or the source is empty or it's deleted\n // Thanks danbooru *grumble grumble*\n if (!outUrl || outUrl.trim() === '' || data.is_deleted) {\n return null\n }\n\n if (outUrl.startsWith('/data')) {\n outUrl = `https://danbooru.donmai.us${outUrl}`\n }\n\n if (outUrl.startsWith('/cached')) {\n outUrl = `https://danbooru.donmai.us${outUrl}`\n }\n\n if (outUrl.startsWith('/_images')) {\n outUrl = `https://dollbooru.org${outUrl}`\n }\n\n if (outUrl.startsWith('//derpicdn.net')) {\n outUrl = `https:${data.image}`\n }\n\n if (outUrl.startsWith('/_thumbs')) {\n outUrl = `https://rule34.paheal.net${outUrl}`\n }\n\n // Why???\n if (!data.file_url && data.directory !== undefined) {\n // Danbooru-based boorus sometimes sort their files into directories\n // There's 2 directories, one named after the first 2 characters of the hash\n // and one named after the next 2 characters of the hash\n // Sometimes we get it in the API response as `data.directory`, sometimes it's null\n // for some ungodly reason\n // I despise the danbooru api honestly\n const directory =\n data.directory ?? `${data.hash.substr(0, 2)}/${data.hash.substr(2, 2)}`\n outUrl = `//${booru.domain}/images/${directory}/${data.image}`\n }\n\n if (!outUrl.startsWith('http')) {\n outUrl = `https:${outUrl}`\n }\n\n if (\n booru.domain === 'xbooru.com' &&\n outUrl.startsWith('https://api-cdn.rule34.xxx/')\n ) {\n outUrl = outUrl.replace(\n 'https://api-cdn.rule34.xxx/',\n 'https://xbooru.com/',\n )\n }\n\n return encodeURI(outUrl)\n}\n\n/**\n * Takes and transforms tags from the booru's api into a common format\n * (which is an array of strings)\n * @param {any} data The data from the booru\n * @returns {string[]} The tags as a string array, and not just a string or an object\n */\nfunction getTags(data: any): string[] {\n let tags: string[] = []\n\n if (Array.isArray(data.tags)) {\n tags = data.tags\n } else if (data.tags?.general) {\n tags = Object.values<string>(data.tags).flat()\n } else if (typeof data.tags === 'string') {\n tags = fromTagString(data.tags)\n } else if (typeof data.tag_string === 'string') {\n tags = fromTagString(data.tag_string)\n }\n\n return tags.filter((v) => v !== '')\n}\n\n/**\n * Parses a string of tags into an array of tags, doing some sanitization\n *\n * @example\n * fromTagString('tag1 tag2 tag3') => ['tag1', 'tag2', 'tag3']\n * fromTagString('tag1 tag,2 tag3 ') => ['tag1', 'tag2', 'tag3']\n * @param tags The tags as a string\n * @returns The string, parsed into an array of tags\n */\nfunction fromTagString(tags: string): string[] {\n return tags.split(' ').map((v) => v.replace(/,/g, ''))\n}\n\n/**\n * An image from a booru with a few common props\n *\n * @example\n * ```\n * Post {\n * fileUrl: 'https://aaaa.com/image.jpg',\n * id: '124125',\n * tags: ['cat', 'cute'],\n * score: 5,\n * source: 'https://giraffeduck.com/aaaa.png',\n * rating: 's'\n * }\n * ```\n */\nexport default class Post {\n /** The {@link Booru} it came from */\n public booru: Booru\n /** The direct link to the file */\n public fileUrl: string | null\n /** The height of the file */\n public height: number\n /** The width of the file */\n public width: number\n /** The url to the medium-sized image (if available) */\n public sampleUrl: string | null\n /** The height of the medium-sized image (if available) */\n public sampleHeight: number | null\n /** The width of the medium-sized image (if available) */\n public sampleWidth: number | null\n /** The url to the smallest image (if available) */\n public previewUrl: string | null\n /** The height of the smallest image (if available) */\n public previewHeight: number | null\n /** The width of the smallest image (if available) */\n public previewWidth: number | null\n /** The id of this post */\n public id: string\n /** If this post is available (ie. not deleted, not banned, has file url) */\n public available: boolean\n /** The tags of this post */\n public tags: string[]\n /** The score of this post */\n public score: number\n /** The source of this post, if available */\n public source?: string | string[]\n /**\n * The rating of the image, as just the first letter\n * (s/q/e/u) => safe/questionable/explicit/unrated\n */\n public rating: string\n /** The Date this post was created at */\n public createdAt?: Date | null\n /** All the data given by the booru @private */\n protected data: any\n\n /**\n * Create an image from a booru\n *\n * @param {Object} data The raw data from the Booru\n * @param {Booru} booru The booru that created the image\n */\n constructor(data: any, booru: Booru) {\n // Damn wild mix of boorus\n this.data = data\n this.booru = booru\n\n // Again, thanks danbooru\n const deletedOrBanned = data.is_deleted || data.is_banned\n\n this.fileUrl = parseImageUrl(\n data.file_url ??\n data.image ??\n (deletedOrBanned ? data.source : undefined) ??\n data.file?.url ??\n data.representations?.full,\n data,\n booru,\n )\n\n this.available = !deletedOrBanned && this.fileUrl !== null\n\n this.height = Number.parseInt(\n data.height ?? data.image_height ?? data.file?.height,\n 10,\n )\n this.width = Number.parseInt(\n data.width ?? data.image_width ?? data.file?.width,\n 10,\n )\n\n this.sampleUrl = parseImageUrl(\n data.sample_url ??\n data.large_file_url ??\n data.representations?.large ??\n data.sample?.url,\n data,\n booru,\n )\n\n this.sampleHeight = Number.parseInt(\n data.sample_height ?? data.sample?.height,\n 10,\n )\n this.sampleWidth = Number.parseInt(\n data.sample_width ?? data.sample?.width,\n 10,\n )\n\n this.previewUrl = parseImageUrl(\n data.preview_url ??\n data.preview_file_url ??\n data.representations?.small ??\n data.preview?.url,\n data,\n booru,\n )\n\n this.previewHeight = Number.parseInt(\n data.preview_height ?? data.preview?.height,\n 10,\n )\n this.previewWidth = Number.parseInt(\n data.preview_width ?? data.preview?.width,\n 10,\n )\n\n this.id = data.id ? data.id.toString() : 'No ID available'\n this.tags = getTags(data)\n\n if (data.score && data.score.total !== undefined) {\n this.score = data.score.total\n } else {\n this.score = data.score ? Number.parseInt(data.score, 10) : data.score\n }\n\n this.source = data.source ?? data.sources ?? data.source_url\n this.rating =\n data.rating ??\n /(safe|suggestive|questionable|explicit)/i.exec(data.tags) ??\n 'u'\n\n if (Array.isArray(this.rating)) {\n this.rating = this.rating[0]\n }\n\n // Thanks derpibooru\n if (this.rating === 'suggestive') {\n this.rating = 'q'\n }\n\n this.rating = this.rating.charAt(0)\n\n this.createdAt = null\n // eslint-disable-next-line\n if (typeof data.created_at === 'object') {\n this.createdAt = new Date(\n data.created_at.s * 1000 + data.created_at.n / 1000000000,\n )\n } else if (typeof data.created_at === 'number') {\n this.createdAt = new Date(data.created_at * 1000)\n } else if (typeof data.created_at === 'string') {\n this.createdAt = new Date(data.created_at)\n } else if (typeof data.change === 'number') {\n this.createdAt = new Date(data.change * 1000)\n } else {\n this.createdAt = new Date(data.created_at ?? data.date)\n }\n }\n\n /**\n * The direct link to the file\n * <p>It's prefered to use `.fileUrl` instead because camelCase\n */\n get file_url(): string | null {\n return this.fileUrl\n }\n\n /**\n * The url to the medium-sized image (if available)\n * <p>It's prefered to use `.sampleUrl` instead because camelCase\n */\n get sample_url(): string | null {\n return this.sampleUrl\n }\n\n /**\n * The height of the medium-sized image (if available)\n * <p>It's prefered to use `.sampleHeight` instead because camelCase\n */\n get sample_height(): number | null {\n return this.sampleHeight\n }\n\n /**\n * The width of the medium-sized image (if available)\n * <p>It's prefered to use `.sampleWidth` instead because camelCase\n */\n get sample_width(): number | null {\n return this.sampleWidth\n }\n\n /**\n * The url to the smallest image (if available)\n * <p>It's prefered to use `.previewUrl` instead because camelCase\n */\n get preview_url(): string | null {\n return this.previewUrl\n }\n\n /**\n * The height of the smallest image (if available)\n * <p>It's prefered to use `.previewHeight` instead because camelCase\n */\n get preview_height(): number | null {\n return this.previewHeight\n }\n\n /**\n * The width of the smallest image (if available)\n * <p>It's prefered to use `.previewWidth` instead because camelCase\n */\n get preview_width(): number | null {\n return this.previewWidth\n }\n\n /**\n * Get the post view (url to the post) of this image\n *\n * @type {String}\n * @example\n * ```\n * const e9 = Booru('e9')\n * const imgs = e9.search(['cat', 'dog'])\n *\n * // Log the post url of the first image\n * console.log(imgs[0].postView)\n * ```\n */\n get postView(): string {\n return this.booru.postView(this.id)\n }\n\n /**\n * Get some common props on the image\n *\n * @deprecated All common props are now attached directly to the image\n * @type {Object}\n *\n * @example\n * ```\n * image.id\n * // deprecated, use this instead\n * image.id\n *\n * // To access the post's raw data from the booru, do\n * image._data.id\n * ```\n */\n get common(): this {\n common()\n return this\n }\n}\n"]}
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export default interface SearchParameters {
|
|
9
9
|
/** The limit on *max* posts to show, you might get less posts than this */
|
|
10
|
-
limit?: number;
|
|
10
|
+
limit?: number | undefined;
|
|
11
11
|
/** Should posts be in random order, implementation differs per booru */
|
|
12
|
-
random?: boolean;
|
|
12
|
+
random?: boolean | undefined;
|
|
13
13
|
/** Which page of results to fetch */
|
|
14
|
-
page?: number;
|
|
14
|
+
page?: number | undefined;
|
|
15
15
|
/** Return unavailable posts (ie. banned/deleted posts) */
|
|
16
|
-
showUnavailable?: boolean;
|
|
16
|
+
showUnavailable?: boolean | undefined;
|
|
17
17
|
}
|
|
18
|
+
//# sourceMappingURL=SearchParameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchParameters.d.ts","sourceRoot":"","sources":["../../src/structures/SearchParameters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,gBAAgB;IACvC,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,wEAAwE;IACxE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchParameters.js","sourceRoot":"","sources":["../../src/structures/SearchParameters.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
1
|
+
{"version":3,"file":"SearchParameters.js","sourceRoot":"","sources":["../../src/structures/SearchParameters.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * @packageDocumentation\n * @module Structures\n */\n\n/**\n * Just an interface for {@link Booru}'s search params :)\n */\nexport default interface SearchParameters {\n /** The limit on *max* posts to show, you might get less posts than this */\n limit?: number | undefined\n /** Should posts be in random order, implementation differs per booru */\n random?: boolean | undefined\n /** Which page of results to fetch */\n page?: number | undefined\n /** Return unavailable posts (ie. banned/deleted posts) */\n showUnavailable?: boolean | undefined\n}\n"]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module Structures
|
|
4
4
|
*/
|
|
5
|
-
import Booru from '../boorus/Booru';
|
|
6
|
-
import Post from '../structures/Post';
|
|
7
|
-
import SearchParameters from './SearchParameters';
|
|
5
|
+
import type Booru from '../boorus/Booru';
|
|
6
|
+
import type Post from '../structures/Post';
|
|
7
|
+
import type SearchParameters from './SearchParameters';
|
|
8
8
|
/**
|
|
9
9
|
* Represents a page of search results, works like an array of {@link Post}
|
|
10
10
|
* <p> Usable like an array and allows to easily get the next page
|
|
@@ -71,3 +71,4 @@ export default class SearchResults extends Array<Post> {
|
|
|
71
71
|
*/
|
|
72
72
|
blacklist(tags: string[] | string): SearchResults;
|
|
73
73
|
}
|
|
74
|
+
//# sourceMappingURL=SearchResults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchResults.d.ts","sourceRoot":"","sources":["../../src/structures/SearchResults.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAA;AACxC,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE1C,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAA;AAEtD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK,CAAC,IAAI,CAAC;IACpD,qCAAqC;IAC9B,KAAK,EAAE,KAAK,CAAA;IACnB,8BAA8B;IACvB,IAAI,EAAE,MAAM,CAAA;IACnB,oCAAoC;IACpC,SAAgB,IAAI,EAAE,MAAM,EAAE,CAAA;IAC9B,uCAAuC;IACvC,SAAgB,OAAO,EAAE,gBAAgB,CAAA;IACzC,wCAAwC;IACxC,SAAgB,KAAK,EAAE,IAAI,EAAE,CAAA;IAE7B,eAAe;gBAEb,KAAK,EAAE,IAAI,EAAE,EACb,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,KAAK;IAed;;;OAGG;IACH,IAAI,KAAK,IAAI,IAAI,CAEhB;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,IAAI,CAEf;IAED;;;;OAIG;IACI,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;IAOzC;;;;;;;;OAQG;IACI,MAAM,CACX,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EACvB,EAAE,MAAc,EAAE;;KAAK,GACtB,aAAa;IAchB;;;;OAIG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,aAAa;CAGzD"}
|
|
@@ -19,13 +19,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
19
19
|
}) : function(o, v) {
|
|
20
20
|
o["default"] = v;
|
|
21
21
|
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || function (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
29
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
40
|
const Utils = __importStar(require("../Utils"));
|
|
31
41
|
/**
|
|
@@ -67,7 +77,7 @@ class SearchResults extends Array {
|
|
|
67
77
|
this.tags = tags;
|
|
68
78
|
this.options = options;
|
|
69
79
|
this.booru = booru;
|
|
70
|
-
this.page = options ? options.page
|
|
80
|
+
this.page = options ? (options.page ?? 0) : 0;
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
73
83
|
* Get the first post in this result set
|
|
@@ -103,12 +113,10 @@ class SearchResults extends Array {
|
|
|
103
113
|
* @return {SearchResults}
|
|
104
114
|
*/
|
|
105
115
|
tagged(tags, { invert = false } = {}) {
|
|
106
|
-
|
|
107
|
-
tags = [tags];
|
|
108
|
-
}
|
|
116
|
+
const searchTags = Array.isArray(tags) ? tags : [tags];
|
|
109
117
|
const posts = [];
|
|
110
118
|
for (const p of this) {
|
|
111
|
-
const m = Utils.compareArrays(
|
|
119
|
+
const m = Utils.compareArrays(searchTags, p.tags).length;
|
|
112
120
|
if ((!invert && m > 0) || (invert && m === 0)) {
|
|
113
121
|
posts.push(p);
|
|
114
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchResults.js","sourceRoot":"","sources":["../../src/structures/SearchResults.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"SearchResults.js","sourceRoot":"","sources":["../../src/structures/SearchResults.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIH,gDAAiC;AAGjC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAqB,aAAc,SAAQ,KAAW;IACpD,qCAAqC;IAC9B,KAAK,CAAO;IACnB,8BAA8B;IACvB,IAAI,CAAQ;IACnB,oCAAoC;IACpB,IAAI,CAAU;IAC9B,uCAAuC;IACvB,OAAO,CAAkB;IACzC,wCAAwC;IACxB,KAAK,CAAQ;IAE7B,eAAe;IACf,YACE,KAAa,EACb,IAAc,EACd,OAAyB,EACzB,KAAY;QAEZ,KAAK,CAAC,KAAK,CAAC,MAAM,CA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CAAC;YACrB,MAAM,CAAC,GAAW,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;YAChE,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC9C,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IACtE,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,IAAuB;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF;AA9FD,gCA8FC","sourcesContent":["/**\n * @packageDocumentation\n * @module Structures\n */\n\nimport type Booru from '../boorus/Booru'\nimport type Post from '../structures/Post'\nimport * as Utils from '../Utils'\nimport type SearchParameters from './SearchParameters'\n\n/**\n * Represents a page of search results, works like an array of {@link Post}\n * <p> Usable like an array and allows to easily get the next page\n *\n * @example\n * ```\n * const Booru = require('booru')\n * // Safebooru\n * const sb = new Booru('sb')\n *\n * const imgs = await sb.search('cat')\n *\n * // Log the images from the first page, then from the second\n * imgs.forEach(i => console.log(i.postView))\n * const imgs2 = await imgs.nextPage()\n * imgs2.forEach(i => console.log(i.postView))\n * ```\n */\nexport default class SearchResults extends Array<Post> {\n /** The booru used for this search */\n public booru: Booru\n /** The page of this search */\n public page: number\n /** The tags used for this search */\n public readonly tags: string[]\n /** The options used for this search */\n public readonly options: SearchParameters\n /** The posts from this search result */\n public readonly posts: Post[]\n\n /** @private */\n constructor(\n posts: Post[],\n tags: string[],\n options: SearchParameters,\n booru: Booru,\n ) {\n super(posts.length)\n\n for (let i = 0; i < posts.length; i++) {\n this[i] = posts[i]\n }\n\n this.posts = posts\n this.tags = tags\n this.options = options\n this.booru = booru\n this.page = options ? (options.page ?? 0) : 0\n }\n\n /**\n * Get the first post in this result set\n * @return {Post}\n */\n get first(): Post {\n return this[0]\n }\n\n /**\n * Get the last post in this result set\n * @return {Post}\n */\n get last(): Post {\n return this[this.length - 1]\n }\n\n /**\n * Get the next page\n * <p>Works like <code>sb.search('cat', {page: 1}); sb.search('cat', {page: 2})</code>\n * @return {Promise<SearchResults>}\n */\n public nextPage(): Promise<SearchResults> {\n const opts: SearchParameters = this.options\n opts.page = this.page + 1\n\n return this.booru.search(this.tags, opts)\n }\n\n /**\n * Create a new SearchResults with just images with the matching tags\n *\n * @param {String[]|String} tags The tags (or tag) to search for\n * @param {Object} options The extra options for the search\n * @param {Boolean} [options.invert=false] If the results should be inverted and\n * return images *not* tagged\n * @return {SearchResults}\n */\n public tagged(\n tags: string[] | string,\n { invert = false } = {},\n ): SearchResults {\n const searchTags = Array.isArray(tags) ? tags : [tags]\n const posts: Post[] = []\n\n for (const p of this) {\n const m: number = Utils.compareArrays(searchTags, p.tags).length\n if ((!invert && m > 0) || (invert && m === 0)) {\n posts.push(p)\n }\n }\n\n return new SearchResults(posts, this.tags, this.options, this.booru)\n }\n\n /**\n * Returns a SearchResults with images *not* tagged with any of the specified tags (or tag)\n * @param {String[]|String} tags The tags (or tag) to blacklist\n * @return {SearchResults} The results without any images with the specified tags\n */\n public blacklist(tags: string[] | string): SearchResults {\n return this.tagged(tags, { invert: true })\n }\n}\n"]}
|