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/boorus/Booru.js
CHANGED
|
@@ -8,11 +8,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.Booru = void 0;
|
|
11
|
-
const Constants_1 = require("../Constants");
|
|
12
|
-
const Utils_1 = require("../Utils");
|
|
13
11
|
const undici_1 = require("undici");
|
|
12
|
+
const Constants_1 = require("../Constants");
|
|
14
13
|
const Post_1 = __importDefault(require("../structures/Post"));
|
|
15
14
|
const SearchResults_1 = __importDefault(require("../structures/SearchResults"));
|
|
15
|
+
const Tag_1 = __importDefault(require("../structures/Tag"));
|
|
16
|
+
const TagListResults_1 = __importDefault(require("../structures/TagListResults"));
|
|
17
|
+
const Utils_1 = require("../Utils");
|
|
16
18
|
const resolvedFetch = typeof window !== 'undefined' ? window.fetch.bind(window) : undici_1.fetch;
|
|
17
19
|
/*
|
|
18
20
|
- new Booru
|
|
@@ -66,9 +68,7 @@ class Booru {
|
|
|
66
68
|
if (!Array.isArray(tags)) {
|
|
67
69
|
return [tags];
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
return tags.slice();
|
|
71
|
-
}
|
|
71
|
+
return tags.slice();
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Search for images on this booru
|
|
@@ -99,9 +99,7 @@ class Booru {
|
|
|
99
99
|
if (err instanceof Error) {
|
|
100
100
|
throw new Constants_1.BooruError(err);
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
throw err;
|
|
104
|
-
}
|
|
102
|
+
throw err;
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
/**
|
|
@@ -111,11 +109,55 @@ class Booru {
|
|
|
111
109
|
* @return {String} The url to the post
|
|
112
110
|
*/
|
|
113
111
|
postView(id) {
|
|
114
|
-
if (typeof id === 'string' && Number.isNaN(parseInt(id, 10))) {
|
|
112
|
+
if (typeof id === 'string' && Number.isNaN(Number.parseInt(id, 10))) {
|
|
115
113
|
throw new Constants_1.BooruError(`Not a valid id for postView: ${id}`);
|
|
116
114
|
}
|
|
117
115
|
return `http${this.site.insecure ? '' : 's'}://${this.domain}${this.site.api.postView}${id}`;
|
|
118
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets a list of tags from the booru
|
|
119
|
+
* @param {Partial<TagsURLParams>} [params] The parameters for the tags list
|
|
120
|
+
* @param {number} [params.limit=100] The limit of tags to return
|
|
121
|
+
* @param {number} [params.page=1] The page of tags to return
|
|
122
|
+
* @return {Promise<any[]>} A promise with the tags as an array
|
|
123
|
+
*/
|
|
124
|
+
async tagList({ limit = 100, page = 1, } = {}) {
|
|
125
|
+
const url = this.getTagListUrl({ limit, page });
|
|
126
|
+
const options = Constants_1.defaultOptions;
|
|
127
|
+
try {
|
|
128
|
+
const response = await resolvedFetch(url, options);
|
|
129
|
+
// Check for CloudFlare ratelimiting
|
|
130
|
+
if (response.status === 503) {
|
|
131
|
+
const body = await response.clone().text();
|
|
132
|
+
if (body.includes('cf-browser-verification')) {
|
|
133
|
+
throw new Constants_1.BooruError("Received a CloudFlare browser verification request. Can't proceed.");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
throw new Constants_1.BooruError(`Received HTTP ${response.status} from booru: '${await response.text()}'`);
|
|
138
|
+
}
|
|
139
|
+
const data = await response.text();
|
|
140
|
+
/**
|
|
141
|
+
* Many boorus don't support JSON parameter for tag listing
|
|
142
|
+
* So attempt JSON parsing, but if it fails default to XML parsing
|
|
143
|
+
**/
|
|
144
|
+
let tags = [];
|
|
145
|
+
try {
|
|
146
|
+
tags = (0, Utils_1.tryParseJSON)(data);
|
|
147
|
+
}
|
|
148
|
+
catch (_e) {
|
|
149
|
+
tags = (0, Utils_1.jsonifyTags)(data);
|
|
150
|
+
}
|
|
151
|
+
return this.parseTagListResult(tags, { limit, page });
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
if (err.type === 'invalid-json')
|
|
155
|
+
if (err instanceof Error) {
|
|
156
|
+
throw new Constants_1.BooruError(err);
|
|
157
|
+
}
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
119
161
|
/**
|
|
120
162
|
* The internal & common searching logic, pls dont use this use .search instead
|
|
121
163
|
*
|
|
@@ -127,18 +169,20 @@ class Booru {
|
|
|
127
169
|
async doSearchRequest(tags, { uri = null, limit = 1, random = false, page = 0, } = {}) {
|
|
128
170
|
// Used for random on sites without order:random
|
|
129
171
|
let fakeLimit;
|
|
172
|
+
let searchTags = tags.slice();
|
|
130
173
|
if (random) {
|
|
131
174
|
if (this.site.random) {
|
|
132
|
-
|
|
175
|
+
searchTags.push('order:random');
|
|
133
176
|
}
|
|
134
177
|
else {
|
|
135
178
|
fakeLimit = 100;
|
|
136
179
|
}
|
|
137
180
|
}
|
|
138
181
|
if (this.site.defaultTags) {
|
|
139
|
-
|
|
182
|
+
searchTags = searchTags.concat(this.site.defaultTags.filter((v) => !searchTags.includes(v)));
|
|
140
183
|
}
|
|
141
|
-
const fetchuri = uri
|
|
184
|
+
const fetchuri = uri ??
|
|
185
|
+
this.getSearchUrl({ tags: searchTags, limit: fakeLimit ?? limit, page });
|
|
142
186
|
const options = Constants_1.defaultOptions;
|
|
143
187
|
const xml = this.site.type === 'xml';
|
|
144
188
|
try {
|
|
@@ -151,16 +195,14 @@ class Booru {
|
|
|
151
195
|
}
|
|
152
196
|
}
|
|
153
197
|
const data = await response.text();
|
|
154
|
-
const posts = xml ? (0, Utils_1.
|
|
198
|
+
const posts = xml ? (0, Utils_1.jsonifyPosts)(data) : (0, Utils_1.tryParseJSON)(data);
|
|
155
199
|
if (!response.ok) {
|
|
156
200
|
throw new Constants_1.BooruError(`Received HTTP ${response.status} ` +
|
|
157
|
-
`from booru: '${posts.error
|
|
158
|
-
posts.message
|
|
201
|
+
`from booru: '${posts.error ??
|
|
202
|
+
posts.message ??
|
|
159
203
|
JSON.stringify(posts)}'`);
|
|
160
204
|
}
|
|
161
|
-
|
|
162
|
-
return posts;
|
|
163
|
-
}
|
|
205
|
+
return posts;
|
|
164
206
|
}
|
|
165
207
|
catch (err) {
|
|
166
208
|
if (err.type === 'invalid-json')
|
|
@@ -179,6 +221,19 @@ class Booru {
|
|
|
179
221
|
getSearchUrl({ tags = [], limit = 100, page = 1, } = {}) {
|
|
180
222
|
return (0, Constants_1.searchURI)(this.site, tags, limit, page, this.credentials);
|
|
181
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Generates a URL to get a list of tags from the booru
|
|
226
|
+
* @param opt
|
|
227
|
+
* @param {number} [opt.limit] The limit of tags to return
|
|
228
|
+
* @param {number} [opt.page] The page of tags to return
|
|
229
|
+
* @returns {string} A URL to get the tags list
|
|
230
|
+
*/
|
|
231
|
+
getTagListUrl({ limit = 100, page = 1, } = {}) {
|
|
232
|
+
if (!this.site.api.tagList) {
|
|
233
|
+
throw new Constants_1.BooruError(`This booru does not support tag listing: ${this.site.domain}`);
|
|
234
|
+
}
|
|
235
|
+
return (0, Constants_1.tagListURI)(this.site, limit, page, this.credentials);
|
|
236
|
+
}
|
|
182
237
|
/**
|
|
183
238
|
* Parse the response from the booru
|
|
184
239
|
*
|
|
@@ -188,42 +243,42 @@ class Booru {
|
|
|
188
243
|
* @return {SearchResults} The results of this search
|
|
189
244
|
*/
|
|
190
245
|
parseSearchResult(result, { fakeLimit, tags, limit, random, page, showUnavailable, }) {
|
|
191
|
-
|
|
192
|
-
|
|
246
|
+
let outResult = result;
|
|
247
|
+
if (outResult.success === false) {
|
|
248
|
+
throw new Constants_1.BooruError(outResult.message ?? outResult.reason);
|
|
193
249
|
}
|
|
194
250
|
// Gelbooru
|
|
195
|
-
if (
|
|
196
|
-
const attributes =
|
|
197
|
-
if (attributes.count === '0' || !
|
|
198
|
-
|
|
251
|
+
if (outResult['@attributes']) {
|
|
252
|
+
const attributes = outResult['@attributes'];
|
|
253
|
+
if (attributes.count === '0' || !outResult.post) {
|
|
254
|
+
outResult = [];
|
|
199
255
|
}
|
|
200
|
-
else if (Array.isArray(
|
|
201
|
-
|
|
256
|
+
else if (Array.isArray(outResult.post)) {
|
|
257
|
+
outResult = outResult.post;
|
|
202
258
|
}
|
|
203
259
|
else {
|
|
204
|
-
|
|
260
|
+
outResult = [outResult.post];
|
|
205
261
|
}
|
|
206
262
|
}
|
|
207
|
-
if (
|
|
208
|
-
|
|
263
|
+
if (outResult.posts) {
|
|
264
|
+
outResult = outResult.posts;
|
|
209
265
|
}
|
|
210
|
-
if (
|
|
211
|
-
|
|
266
|
+
if (outResult.images) {
|
|
267
|
+
outResult = outResult.images;
|
|
212
268
|
}
|
|
213
269
|
let r;
|
|
214
270
|
// If gelbooru/other booru decides to return *nothing* instead of an empty array
|
|
215
|
-
if (
|
|
271
|
+
if (outResult === '') {
|
|
216
272
|
r = [];
|
|
217
273
|
}
|
|
218
274
|
else if (fakeLimit) {
|
|
219
|
-
r = (0, Utils_1.shuffle)(
|
|
275
|
+
r = (0, Utils_1.shuffle)(outResult);
|
|
220
276
|
}
|
|
221
|
-
else if (
|
|
277
|
+
else if (outResult.constructor === Object) {
|
|
222
278
|
// For XML based sites
|
|
223
|
-
r = [
|
|
279
|
+
r = [outResult];
|
|
224
280
|
}
|
|
225
|
-
|
|
226
|
-
let posts = results
|
|
281
|
+
let posts = (r ?? outResult)
|
|
227
282
|
.slice(0, limit)
|
|
228
283
|
.map((v) => new Post_1.default(v, this));
|
|
229
284
|
const options = { limit, random, page, showUnavailable };
|
|
@@ -235,6 +290,28 @@ class Booru {
|
|
|
235
290
|
}
|
|
236
291
|
return new SearchResults_1.default(posts, tags, options, this);
|
|
237
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Parse the response from the booru for a tag list
|
|
295
|
+
*
|
|
296
|
+
* @param result
|
|
297
|
+
* @param param1
|
|
298
|
+
* @returns
|
|
299
|
+
*/
|
|
300
|
+
parseTagListResult(result, { limit = 100, page = 1 } = {}) {
|
|
301
|
+
if (result.success === false) {
|
|
302
|
+
throw new Constants_1.BooruError(result.message ?? result.reason);
|
|
303
|
+
}
|
|
304
|
+
let tags = [];
|
|
305
|
+
if (result) {
|
|
306
|
+
if (Array.isArray(result)) {
|
|
307
|
+
tags = result.map((v) => new Tag_1.default(v, this));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
tags = [new Tag_1.default(result, this)];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return new TagListResults_1.default(tags, { limit, page }, this);
|
|
314
|
+
}
|
|
238
315
|
}
|
|
239
316
|
exports.Booru = Booru;
|
|
240
317
|
exports.default = Booru;
|
package/dist/boorus/Booru.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Booru.js","sourceRoot":"","sources":["../../src/boorus/Booru.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAAoE;AACpE,oCAAqE;AAErE,mCAA8B;AAE9B,8DAAqC;AAErC,gFAAuD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kBAAkB,CAC1B,MAAW,EACX,EAAE,KAAK,GAAG,GAAG,EAAE,IAAI,GAAG,CAAC,KAA6B,EAAE;QAEtD,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC7B,MAAM,IAAI,sBAAU,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;QACvD,CAAC;QAED,IAAI,IAAI,GAAU,EAAE,CAAA;QAEpB,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,aAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;YAC5C,CAAC;iBAAM,CAAC;gBACN,IAAI,GAAG,CAAC,IAAI,aAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QAED,OAAO,IAAI,wBAAc,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;IACxD,CAAC;CACF;AAtWD,sBAsWC;AAED,kBAAe,KAAK,CAAA","sourcesContent":["/**\n * @packageDocumentation\n * @module Boorus\n */\n\nimport { fetch } from 'undici'\nimport { BooruError, defaultOptions, searchURI, tagListURI } from '../Constants'\nimport type InternalSearchParameters from '../structures/InternalSearchParameters'\nimport Post from '../structures/Post'\nimport type SearchParameters from '../structures/SearchParameters'\nimport SearchResults from '../structures/SearchResults'\nimport type Site from '../structures/Site'\nimport Tag from '../structures/Tag'\nimport TagListResults from '../structures/TagListResults'\nimport {\n jsonifyPosts,\n jsonifyTags,\n resolveSite,\n shuffle,\n tryParseJSON,\n} from '../Utils'\n\n// Shut up the compiler\n// This attempts to find and use the native browser fetch, if possible\n// Fixes https://github.com/AtoraSuunva/booru/issues/51\ndeclare const window: any\nconst resolvedFetch: typeof fetch =\n typeof window !== 'undefined' ? window.fetch.bind(window) : fetch\n\nexport type BooruCredentials = Record<string, string>\n\ninterface SearchUrlParams {\n tags: string[]\n limit: number\n page: number\n}\n\ninterface TagsURLParams {\n limit?: number | undefined\n page?: number | undefined\n}\n\n/*\n - new Booru\n => Constructor, params {name, {nsfw, {search, postView, ...}, random}, {apiTokens...}}\n => .search([tags...], {limit, random})\n => .postView(id)\n => .site\n */\n\n/**\n * A basic, JSON booru\n * @example\n * ```\n * const Booru = require('booru')\n * // Aliases are supported\n * const e9 = Booru('e9')\n *\n * // You can then search the site\n * const imgs = await e9.search(['cat', 'cute'], {limit: 3})\n *\n * // And use the images\n * imgs.forEach(i => console.log(i.fileUrl))\n *\n * // Or access other methods on the Booru\n * e9.postView(imgs[0].id)\n * ```\n */\nexport class Booru {\n /** The domain of the booru */\n public domain: string\n /** The site object representing this booru */\n public site: Site\n /** The credentials to use for this booru */\n public credentials?: BooruCredentials | undefined\n\n /**\n * Create a new booru from a site\n *\n * @private\n * @param site The site to use\n * @param credentials Credentials for the API (Currently not used)\n */\n constructor(site: Site, credentials?: BooruCredentials) {\n const domain = resolveSite(site.domain)\n\n if (domain === null) {\n throw new Error(`Invalid site passed: ${site.domain}`)\n }\n\n this.domain = domain\n this.site = site\n this.credentials = credentials\n }\n\n protected normalizeTags(tags: string | string[]): string[] {\n if (!Array.isArray(tags)) {\n return [tags]\n }\n\n return tags.slice()\n }\n\n /**\n * Search for images on this booru\n * @param {String|String[]} tags The tag(s) to search for\n * @param {SearchParameters} searchArgs The arguments for the search\n * @return {Promise<SearchResults>} The results as an array of Posts\n */\n public async search(\n tags: string | string[],\n {\n limit = 1,\n random = false,\n page = 0,\n showUnavailable = false,\n }: SearchParameters = {},\n ): Promise<SearchResults> {\n const fakeLimit: number = random && !this.site.random ? 100 : 0\n const tagArray = this.normalizeTags(tags)\n\n try {\n const searchResult = await this.doSearchRequest(tagArray, {\n limit,\n random,\n page,\n showUnavailable,\n })\n return this.parseSearchResult(searchResult, {\n fakeLimit,\n tags: tagArray,\n limit,\n random,\n page,\n showUnavailable,\n })\n } catch (err) {\n if (err instanceof Error) {\n throw new BooruError(err)\n }\n\n throw err\n }\n }\n\n /**\n * Gets the url you'd see in your browser from a post id for this booru\n *\n * @param {String} id The id to get the postView for\n * @return {String} The url to the post\n */\n public postView(id: string | number): string {\n if (typeof id === 'string' && Number.isNaN(Number.parseInt(id, 10))) {\n throw new BooruError(`Not a valid id for postView: ${id}`)\n }\n\n return `http${this.site.insecure ? '' : 's'}://${this.domain}${\n this.site.api.postView\n }${id}`\n }\n\n /**\n * Gets a list of tags from the booru\n * @param {Partial<TagsURLParams>} [params] The parameters for the tags list\n * @param {number} [params.limit=100] The limit of tags to return\n * @param {number} [params.page=1] The page of tags to return\n * @return {Promise<any[]>} A promise with the tags as an array\n */\n public async tagList({\n limit = 100,\n page = 1,\n }: Partial<TagsURLParams> = {}): Promise<TagListResults> {\n const url = this.getTagListUrl({ limit, page })\n const options = defaultOptions\n try {\n const response = await resolvedFetch(url, options)\n\n // Check for CloudFlare ratelimiting\n if (response.status === 503) {\n const body = await response.clone().text()\n if (body.includes('cf-browser-verification')) {\n throw new BooruError(\n \"Received a CloudFlare browser verification request. Can't proceed.\",\n )\n }\n }\n\n if (!response.ok) {\n throw new BooruError(\n `Received HTTP ${response.status} from booru: '${await response.text()}'`,\n )\n }\n\n const data = await response.text()\n /**\n * Many boorus don't support JSON parameter for tag listing\n * So attempt JSON parsing, but if it fails default to XML parsing\n **/\n let tags = []\n try {\n tags = tryParseJSON(data)\n } catch (_e) {\n tags = jsonifyTags(data)\n }\n\n return this.parseTagListResult(tags, { limit, page })\n } catch (err) {\n if ((err as any).type === 'invalid-json')\n if (err instanceof Error) {\n throw new BooruError(err)\n }\n\n throw err\n }\n }\n\n /**\n * The internal & common searching logic, pls dont use this use .search instead\n *\n * @protected\n * @param {String[]|String} tags The tags to search with\n * @param {InternalSearchParameters} searchArgs The arguments for the search\n * @return {Promise<Object>}\n */\n protected async doSearchRequest(\n tags: string[],\n {\n uri = null,\n limit = 1,\n random = false,\n page = 0,\n }: InternalSearchParameters = {},\n ): Promise<any> {\n // Used for random on sites without order:random\n let fakeLimit: number | undefined\n let searchTags = tags.slice()\n\n if (random) {\n if (this.site.random) {\n searchTags.push('order:random')\n } else {\n fakeLimit = 100\n }\n }\n\n if (this.site.defaultTags) {\n searchTags = searchTags.concat(\n this.site.defaultTags.filter((v) => !searchTags.includes(v)),\n )\n }\n\n const fetchuri =\n uri ??\n this.getSearchUrl({ tags: searchTags, limit: fakeLimit ?? limit, page })\n const options = defaultOptions\n const xml = this.site.type === 'xml'\n\n try {\n const response = await resolvedFetch(fetchuri, options)\n\n // Check for CloudFlare ratelimiting\n if (response.status === 503) {\n const body = await response.clone().text()\n if (body.includes('cf-browser-verification')) {\n throw new BooruError(\n \"Received a CloudFlare browser verification request. Can't proceed.\",\n )\n }\n }\n\n const data = await response.text()\n const posts = xml ? jsonifyPosts(data) : tryParseJSON(data)\n\n if (!response.ok) {\n throw new BooruError(\n `Received HTTP ${response.status} ` +\n `from booru: '${\n (posts as any).error ??\n (posts as any).message ??\n JSON.stringify(posts)\n }'`,\n )\n }\n\n return posts\n } catch (err) {\n if ((err as any).type === 'invalid-json') return ''\n throw err\n }\n }\n\n /**\n * Generates a URL to search the booru with, mostly for debugging purposes\n * @param opt\n * @param {string[]} [opt.tags] The tags to search for\n * @param {number} [opt.limit] The limit of results to return\n * @param {number} [opt.page] The page of results to return\n * @returns A URL to search the booru\n */\n getSearchUrl({\n tags = [],\n limit = 100,\n page = 1,\n }: Partial<SearchUrlParams> = {}): string {\n return searchURI(this.site, tags, limit, page, this.credentials)\n }\n\n /**\n * Generates a URL to get a list of tags from the booru\n * @param opt\n * @param {number} [opt.limit] The limit of tags to return\n * @param {number} [opt.page] The page of tags to return\n * @returns {string} A URL to get the tags list\n */\n getTagListUrl({\n limit = 100,\n page = 1,\n }: Partial<TagsURLParams> = {}): string {\n if (!this.site.api.tagList) {\n throw new BooruError(\n `This booru does not support tag listing: ${this.site.domain}`,\n )\n }\n return tagListURI(this.site, limit, page, this.credentials)\n }\n\n /**\n * Parse the response from the booru\n *\n * @protected\n * @param {Object} result The response of the booru\n * @param {InternalSearchParameters} searchArgs The arguments used for the search\n * @return {SearchResults} The results of this search\n */\n protected parseSearchResult(\n result: any,\n {\n fakeLimit,\n tags,\n limit,\n random,\n page,\n showUnavailable,\n }: InternalSearchParameters,\n ): SearchResults {\n let outResult = result\n\n if (outResult.success === false) {\n throw new BooruError(outResult.message ?? outResult.reason)\n }\n\n // Gelbooru\n if (outResult['@attributes']) {\n const attributes = outResult['@attributes']\n\n if (attributes.count === '0' || !outResult.post) {\n outResult = []\n } else if (Array.isArray(outResult.post)) {\n outResult = outResult.post\n } else {\n outResult = [outResult.post]\n }\n }\n\n if (outResult.posts) {\n outResult = outResult.posts\n }\n\n if (outResult.images) {\n outResult = outResult.images\n }\n\n let r: string[] | undefined\n // If gelbooru/other booru decides to return *nothing* instead of an empty array\n if (outResult === '') {\n r = []\n } else if (fakeLimit) {\n r = shuffle(outResult)\n } else if (outResult.constructor === Object) {\n // For XML based sites\n r = [outResult]\n }\n\n let posts: Post[] = (r ?? outResult)\n .slice(0, limit)\n .map((v: any) => new Post(v, this))\n const options = { limit, random, page, showUnavailable }\n\n if (tags === undefined) {\n tags = []\n }\n\n if (!showUnavailable) {\n posts = posts.filter((p) => p.available)\n }\n\n return new SearchResults(posts, tags, options, this)\n }\n\n /**\n * Parse the response from the booru for a tag list\n *\n * @param result\n * @param param1\n * @returns\n */\n protected parseTagListResult(\n result: any,\n { limit = 100, page = 1 }: Partial<TagsURLParams> = {},\n ): TagListResults {\n if (result.success === false) {\n throw new BooruError(result.message ?? result.reason)\n }\n\n let tags: any[] = []\n\n if (result) {\n if (Array.isArray(result)) {\n tags = result.map((v) => new Tag(v, this))\n } else {\n tags = [new Tag(result, this)]\n }\n }\n\n return new TagListResults(tags, { limit, page }, this)\n }\n}\n\nexport default Booru\n"]}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module Boorus
|
|
4
4
|
*/
|
|
5
|
-
import SearchParameters from '../structures/SearchParameters';
|
|
6
|
-
import SearchResults from '../structures/SearchResults';
|
|
7
|
-
import
|
|
8
|
-
import Booru, { BooruCredentials } from './Booru';
|
|
5
|
+
import type SearchParameters from '../structures/SearchParameters';
|
|
6
|
+
import type SearchResults from '../structures/SearchResults';
|
|
7
|
+
import Booru from './Booru';
|
|
9
8
|
/**
|
|
10
9
|
* A class designed for Derpibooru
|
|
11
10
|
* >:(
|
|
@@ -14,12 +13,7 @@ import Booru, { BooruCredentials } from './Booru';
|
|
|
14
13
|
* @inheritDoc
|
|
15
14
|
*/
|
|
16
15
|
export default class Derpibooru extends Booru {
|
|
17
|
-
/**
|
|
18
|
-
* Create a new booru for Derpibooru from a site
|
|
19
|
-
* @param site The site to use
|
|
20
|
-
* @param credentials Credentials for the API (Currently not used)
|
|
21
|
-
*/
|
|
22
|
-
constructor(site: Site, credentials?: BooruCredentials);
|
|
23
16
|
/** @inheritDoc */
|
|
24
17
|
search(tags: string[] | string, { limit, random, page }?: SearchParameters): Promise<SearchResults>;
|
|
25
18
|
}
|
|
19
|
+
//# sourceMappingURL=Derpibooru.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Derpibooru.d.ts","sourceRoot":"","sources":["../../src/boorus/Derpibooru.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,gBAAgB,MAAM,gCAAgC,CAAA;AAClE,OAAO,KAAK,aAAa,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,MAAM,SAAS,CAAA;AAE3B;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,KAAK;IAC3C,kBAAkB;IACF,MAAM,CACpB,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EACvB,EAAE,KAAS,EAAE,MAAc,EAAE,IAAQ,EAAE,GAAE,gBAAqB,GAC7D,OAAO,CAAC,aAAa,CAAC;CA6B1B"}
|
|
@@ -17,14 +17,6 @@ const Booru_1 = __importDefault(require("./Booru"));
|
|
|
17
17
|
* @inheritDoc
|
|
18
18
|
*/
|
|
19
19
|
class Derpibooru extends Booru_1.default {
|
|
20
|
-
/**
|
|
21
|
-
* Create a new booru for Derpibooru from a site
|
|
22
|
-
* @param site The site to use
|
|
23
|
-
* @param credentials Credentials for the API (Currently not used)
|
|
24
|
-
*/
|
|
25
|
-
constructor(site, credentials) {
|
|
26
|
-
super(site, credentials);
|
|
27
|
-
}
|
|
28
20
|
/** @inheritDoc */
|
|
29
21
|
search(tags, { limit = 1, random = false, page = 0 } = {}) {
|
|
30
22
|
const tagArray = this.normalizeTags(tags);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Derpibooru.js","sourceRoot":"","sources":["../../src/boorus/Derpibooru.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,4CAAyC;
|
|
1
|
+
{"version":3,"file":"Derpibooru.js","sourceRoot":"","sources":["../../src/boorus/Derpibooru.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,4CAAyC;AAGzC,oDAA2B;AAE3B;;;;;;GAMG;AACH,MAAqB,UAAW,SAAQ,eAAK;IAC3C,kBAAkB;IACF,MAAM,CACpB,IAAuB,EACvB,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,GAAG,CAAC,KAAuB,EAAE;QAE9D,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;QAEzC,mCAAmC;QACnC,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9B,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;QACnB,CAAC;QAED,oCAAoC;QACpC,IAAI,IAAI,CAAC,CAAA;QAET,MAAM,GAAG,GACP,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAClD,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAE5D,OAAO,KAAK;aACT,eAAe,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;aACvD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACV,KAAK,CAAC,iBAAiB,CAAC,CAAC,EAAE;YACzB,SAAS,EAAE,CAAC;YACZ,IAAI,EAAE,QAAQ;YACd,KAAK;YACL,MAAM;YACN,IAAI;SACL,CAAC,CACH;aACA,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,sBAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,CAAC;CACF;AAlCD,6BAkCC","sourcesContent":["/**\n * @packageDocumentation\n * @module Boorus\n */\n\nimport { BooruError } from '../Constants'\nimport type SearchParameters from '../structures/SearchParameters'\nimport type SearchResults from '../structures/SearchResults'\nimport Booru from './Booru'\n\n/**\n * A class designed for Derpibooru\n * >:(\n * @private\n * @extends Booru\n * @inheritDoc\n */\nexport default class Derpibooru extends Booru {\n /** @inheritDoc */\n public override search(\n tags: string[] | string,\n { limit = 1, random = false, page = 0 }: SearchParameters = {},\n ): Promise<SearchResults> {\n const tagArray = this.normalizeTags(tags)\n\n // For any image, you must supply *\n if (tagArray[0] === undefined) {\n tagArray[0] = '*'\n }\n\n // Derpibooru offsets the pages by 1\n page += 1\n\n const uri =\n this.getSearchUrl({ tags: tagArray, limit, page }) +\n (random && this.site.random === 'string' ? `&${this.site.random}` : '') +\n (this.credentials ? `&key=${this.credentials.token}` : '')\n\n return super\n .doSearchRequest(tagArray, { limit, random, page, uri })\n .then((r) =>\n super.parseSearchResult(r, {\n fakeLimit: 0,\n tags: tagArray,\n limit,\n random,\n page,\n }),\n )\n .catch((e) => Promise.reject(new BooruError(e)))\n }\n}\n"]}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module Boorus
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import Booru, { BooruCredentials } from './Booru';
|
|
5
|
+
import Booru from './Booru';
|
|
7
6
|
/**
|
|
8
7
|
* A class designed for Xml-returning boorus
|
|
9
8
|
*
|
|
@@ -11,10 +10,5 @@ import Booru, { BooruCredentials } from './Booru';
|
|
|
11
10
|
* @inheritDoc
|
|
12
11
|
*/
|
|
13
12
|
export default class XmlBooru extends Booru {
|
|
14
|
-
/**
|
|
15
|
-
* Create a new booru using XML from a site
|
|
16
|
-
* @param {Site} site The site to use
|
|
17
|
-
* @param {Object?} credentials Credentials for the API (Currently not used)
|
|
18
|
-
*/
|
|
19
|
-
constructor(site: Site, credentials?: BooruCredentials);
|
|
20
13
|
}
|
|
14
|
+
//# sourceMappingURL=XmlBooru.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XmlBooru.d.ts","sourceRoot":"","sources":["../../src/boorus/XmlBooru.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,SAAS,CAAA;AAE3B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,KAAK;CAAG"}
|
package/dist/boorus/XmlBooru.js
CHANGED
|
@@ -15,14 +15,6 @@ const Booru_1 = __importDefault(require("./Booru"));
|
|
|
15
15
|
* @inheritDoc
|
|
16
16
|
*/
|
|
17
17
|
class XmlBooru extends Booru_1.default {
|
|
18
|
-
/**
|
|
19
|
-
* Create a new booru using XML from a site
|
|
20
|
-
* @param {Site} site The site to use
|
|
21
|
-
* @param {Object?} credentials Credentials for the API (Currently not used)
|
|
22
|
-
*/
|
|
23
|
-
constructor(site, credentials) {
|
|
24
|
-
super(site, credentials);
|
|
25
|
-
}
|
|
26
18
|
}
|
|
27
19
|
exports.default = XmlBooru;
|
|
28
20
|
//# sourceMappingURL=XmlBooru.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XmlBooru.js","sourceRoot":"","sources":["../../src/boorus/XmlBooru.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;
|
|
1
|
+
{"version":3,"file":"XmlBooru.js","sourceRoot":"","sources":["../../src/boorus/XmlBooru.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,oDAA2B;AAE3B;;;;;GAKG;AACH,MAAqB,QAAS,SAAQ,eAAK;CAAG;AAA9C,2BAA8C","sourcesContent":["/**\n * @packageDocumentation\n * @module Boorus\n */\n\nimport Booru from './Booru'\n\n/**\n * A class designed for Xml-returning boorus\n *\n * @extends Booru\n * @inheritDoc\n */\nexport default class XmlBooru extends Booru {}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* @module Index
|
|
4
4
|
*/
|
|
5
|
-
import Booru, { BooruCredentials } from './boorus/Booru';
|
|
5
|
+
import Booru, { type BooruCredentials } from './boorus/Booru';
|
|
6
6
|
import Derpibooru from './boorus/Derpibooru';
|
|
7
7
|
import XmlBooru from './boorus/XmlBooru';
|
|
8
8
|
import Post from './structures/Post';
|
|
9
|
-
import SearchParameters from './structures/SearchParameters';
|
|
9
|
+
import type SearchParameters from './structures/SearchParameters';
|
|
10
10
|
import SearchResults from './structures/SearchResults';
|
|
11
11
|
import Site from './structures/Site';
|
|
12
|
+
import type TagListParameters from './structures/TagListParameters';
|
|
13
|
+
import type TagListResults from './structures/TagListResults';
|
|
12
14
|
/**
|
|
13
15
|
* Create a new booru to search with
|
|
14
16
|
*
|
|
@@ -23,6 +25,9 @@ export default booruForSite;
|
|
|
23
25
|
export interface BooruSearch extends SearchParameters {
|
|
24
26
|
credentials?: BooruCredentials;
|
|
25
27
|
}
|
|
28
|
+
export interface BooruTagList extends TagListParameters {
|
|
29
|
+
credentials?: BooruCredentials;
|
|
30
|
+
}
|
|
26
31
|
/**
|
|
27
32
|
* Searches a site for images with tags and returns the results
|
|
28
33
|
* @param {String} site The site to search
|
|
@@ -39,6 +44,20 @@ export interface BooruSearch extends SearchParameters {
|
|
|
39
44
|
* ```
|
|
40
45
|
*/
|
|
41
46
|
export declare function search(site: string, tags?: string[] | string, { limit, random, page, credentials }?: BooruSearch): Promise<SearchResults>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a list of tags from a site
|
|
49
|
+
* @param {String} site The site to get the tags from
|
|
50
|
+
* @param {TagListParameters} [options={}] The options for the tag list
|
|
51
|
+
* @return {Promise<TagListResults>} A promise with the tags as an array of objects
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```
|
|
55
|
+
* const Booru = require('booru')
|
|
56
|
+
* // Returns a promise with the first 100 tags from e926
|
|
57
|
+
* Booru.tagList('e926')
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function tagList(site: string, { limit, page, credentials }?: BooruTagList): Promise<TagListResults>;
|
|
42
61
|
/**
|
|
43
62
|
* Deprecated, now a noop
|
|
44
63
|
* <p>This will be removed *soon* please stop using it</p>
|
|
@@ -54,3 +73,4 @@ export { BooruError, sites } from './Constants';
|
|
|
54
73
|
export { resolveSite } from './Utils';
|
|
55
74
|
export { Derpibooru, Post, SearchResults, Site, XmlBooru };
|
|
56
75
|
export type { BooruCredentials, SearchParameters };
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts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G;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAGxD;AAED,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;AAC1D,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -10,14 +10,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.XmlBooru = exports.Site = exports.SearchResults = exports.Post = exports.Derpibooru = exports.resolveSite = exports.sites = exports.BooruError = exports.BooruClass = void 0;
|
|
11
11
|
exports.forSite = booruForSite;
|
|
12
12
|
exports.search = search;
|
|
13
|
+
exports.tagList = tagList;
|
|
13
14
|
exports.commonfy = commonfy;
|
|
14
|
-
const
|
|
15
|
-
const util_1 = require("util");
|
|
15
|
+
const node_util_1 = require("node:util");
|
|
16
16
|
const Booru_1 = __importDefault(require("./boorus/Booru"));
|
|
17
17
|
const Derpibooru_1 = __importDefault(require("./boorus/Derpibooru"));
|
|
18
18
|
exports.Derpibooru = Derpibooru_1.default;
|
|
19
19
|
const XmlBooru_1 = __importDefault(require("./boorus/XmlBooru"));
|
|
20
20
|
exports.XmlBooru = XmlBooru_1.default;
|
|
21
|
+
const Constants_1 = require("./Constants");
|
|
21
22
|
const Post_1 = __importDefault(require("./structures/Post"));
|
|
22
23
|
exports.Post = Post_1.default;
|
|
23
24
|
const SearchResults_1 = __importDefault(require("./structures/SearchResults"));
|
|
@@ -77,7 +78,7 @@ exports.default = booruForSite;
|
|
|
77
78
|
function search(site, tags = [], { limit = 1, random = false, page = 0, credentials = {} } = {}) {
|
|
78
79
|
const rSite = (0, Utils_1.resolveSite)(site);
|
|
79
80
|
if (typeof limit === 'string') {
|
|
80
|
-
limit = parseInt(limit, 10);
|
|
81
|
+
limit = Number.parseInt(limit, 10);
|
|
81
82
|
}
|
|
82
83
|
if (rSite === null) {
|
|
83
84
|
throw new Constants_1.BooruError('Site not supported');
|
|
@@ -96,8 +97,32 @@ function search(site, tags = [], { limit = 1, random = false, page = 0, credenti
|
|
|
96
97
|
booruCache[rSite].credentials = credentials;
|
|
97
98
|
return booruCache[rSite].search(tags, { limit, random, page });
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Get a list of tags from a site
|
|
102
|
+
* @param {String} site The site to get the tags from
|
|
103
|
+
* @param {TagListParameters} [options={}] The options for the tag list
|
|
104
|
+
* @return {Promise<TagListResults>} A promise with the tags as an array of objects
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```
|
|
108
|
+
* const Booru = require('booru')
|
|
109
|
+
* // Returns a promise with the first 100 tags from e926
|
|
110
|
+
* Booru.tagList('e926')
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function tagList(site, { limit = 1, page = 0, credentials = {} } = {}) {
|
|
114
|
+
const rSite = (0, Utils_1.resolveSite)(site);
|
|
115
|
+
if (rSite === null) {
|
|
116
|
+
throw new Constants_1.BooruError('Site not supported');
|
|
117
|
+
}
|
|
118
|
+
const booruSite = new Site_1.default(Constants_1.sites[rSite]);
|
|
119
|
+
if (!booruCache[rSite]) {
|
|
120
|
+
booruCache[rSite] = booruFrom(booruSite, credentials);
|
|
121
|
+
}
|
|
122
|
+
booruCache[rSite].credentials = credentials;
|
|
123
|
+
return booruCache[rSite].tagList({ limit, page });
|
|
124
|
+
}
|
|
125
|
+
const deprecatedCommonfy = (0, node_util_1.deprecate)(() => { }, 'Common is now deprecated, just access the properties directly');
|
|
101
126
|
/**
|
|
102
127
|
* Deprecated, now a noop
|
|
103
128
|
* <p>This will be removed *soon* please stop using it</p>
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAwDsB,+BAAO;AA0BhC,wBAgCC;AAeD,0BAkBC;AAgBD,4BAGC;AApKD,yCAAqC;AACrC,2DAA6D;AAC7D,qEAA4C;AAuKnC,qBAvKF,oBAAU,CAuKE;AAtKnB,iEAAwC;AAsKQ,mBAtKzC,kBAAQ,CAsKyC;AArKxD,2CAA6D;AAC7D,6DAAoC;AAoKf,eApKd,cAAI,CAoKc;AAlKzB,+EAAsD;AAkK3B,wBAlKpB,uBAAa,CAkKoB;AAjKxC,6DAAoC;AAiKM,eAjKnC,cAAI,CAiKmC;AA9J9C,mCAAqC;AAErC,MAAM,UAAU,GAAiC;IAC/C,KAAK,EAAE,oBAAU;IACjB,GAAG,EAAE,kBAAQ;CACd,CAAA;AAED,MAAM,UAAU,GAAoC,EAAE,CAAA;AAEtD;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,SAAe,EAAE,WAA8B;IAChE,OAAO,IAAI,CACT,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC;QACxD,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC;QAC5B,CAAC,CAAC,eAAK,CACV,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAC3B,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,IAAY,EAAE,WAA8B;IAChE,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAA;IAE/B,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,sBAAU,CAAC,oBAAoB,CAAC,CAAA;IA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kGAAA,KAAK,OAAA;AAC1B,iCAAqC;AAA5B,oGAAA,WAAW,OAAA","sourcesContent":["/**\n * @packageDocumentation\n * @module Index\n */\n\nimport { deprecate } from 'node:util'\nimport Booru, { type BooruCredentials } from './boorus/Booru'\nimport Derpibooru from './boorus/Derpibooru'\nimport XmlBooru from './boorus/XmlBooru'\nimport { type AnySite, BooruError, sites } from './Constants'\nimport Post from './structures/Post'\nimport type SearchParameters from './structures/SearchParameters'\nimport SearchResults from './structures/SearchResults'\nimport Site from './structures/Site'\nimport type TagListParameters from './structures/TagListParameters'\nimport type TagListResults from './structures/TagListResults'\nimport { resolveSite } from './Utils'\n\nconst BooruTypes: Record<string, typeof Booru> = {\n derpi: Derpibooru,\n xml: XmlBooru,\n}\n\nconst booruCache: Partial<Record<AnySite, Booru>> = {}\n\n/**\n * Create a new booru, if special type, use that booru, else use default Booru\n *\n * @param booruSite The site to use\n * @param credentials The credentials to use, if any\n * @return A new booru\n */\nfunction booruFrom(booruSite: Site, credentials?: BooruCredentials): Booru {\n return new (\n booruSite.type !== undefined && BooruTypes[booruSite.type]\n ? BooruTypes[booruSite.type]\n : Booru\n )(booruSite, credentials)\n}\n\n/**\n * Create a new booru to search with\n *\n * @constructor\n * @param {String} site The {@link Site} domain (or alias of it) to create a booru from\n * @param {BooruCredentials} credentials The credentials to use on this booru\n * @return {Booru} A booru to use\n */\nfunction booruForSite(site: string, credentials?: BooruCredentials): Booru {\n const rSite = resolveSite(site)\n\n if (!rSite) throw new BooruError('Site not supported')\n\n const booruSite = new Site(sites[rSite])\n\n // If special type, use that booru, else use default Booru\n return booruFrom(booruSite, credentials)\n}\n\nexport { booruForSite as forSite }\nexport default booruForSite\n\nexport interface BooruSearch extends SearchParameters {\n credentials?: BooruCredentials\n}\n\nexport interface BooruTagList extends TagListParameters {\n credentials?: BooruCredentials\n}\n\n/**\n * Searches a site for images with tags and returns the results\n * @param {String} site The site to search\n * @param {String[]|String} [tags=[]] Tags to search with\n * @param {SearchParameters} [searchOptions={}] The options for searching\n * if provided (Unused)\n * @return {Promise<SearchResults>} A promise with the images as an array of objects\n *\n * @example\n * ```\n * const Booru = require('booru')\n * // Returns a promise with the latest cute glace pic from e926\n * Booru.search('e926', ['glaceon', 'cute'])\n * ```\n */\nexport function search(\n site: string,\n tags: string[] | string = [],\n { limit = 1, random = false, page = 0, credentials = {} }: BooruSearch = {},\n): Promise<SearchResults> {\n const rSite = resolveSite(site)\n\n if (typeof limit === 'string') {\n limit = Number.parseInt(limit, 10)\n }\n\n if (rSite === null) {\n throw new BooruError('Site not supported')\n }\n\n if (!Array.isArray(tags) && typeof tags !== 'string') {\n throw new BooruError('`tags` should be an array or string')\n }\n\n if (typeof limit !== 'number' || Number.isNaN(limit)) {\n throw new BooruError('`limit` should be an int')\n }\n\n const booruSite = new Site(sites[rSite])\n\n if (!booruCache[rSite]) {\n booruCache[rSite] = booruFrom(booruSite, credentials)\n }\n\n // This is ugly and a hack, I know this\n booruCache[rSite].credentials = credentials\n return booruCache[rSite].search(tags, { limit, random, page })\n}\n\n/**\n * Get a list of tags from a site\n * @param {String} site The site to get the tags from\n * @param {TagListParameters} [options={}] The options for the tag list\n * @return {Promise<TagListResults>} A promise with the tags as an array of objects\n *\n * @example\n * ```\n * const Booru = require('booru')\n * // Returns a promise with the first 100 tags from e926\n * Booru.tagList('e926')\n * ```\n */\nexport function tagList(\n site: string,\n { limit = 1, page = 0, credentials = {} }: BooruTagList = {},\n): Promise<TagListResults> {\n const rSite = resolveSite(site)\n\n if (rSite === null) {\n throw new BooruError('Site not supported')\n }\n\n const booruSite = new Site(sites[rSite])\n\n if (!booruCache[rSite]) {\n booruCache[rSite] = booruFrom(booruSite, credentials)\n }\n\n booruCache[rSite].credentials = credentials\n return booruCache[rSite].tagList({ limit, page })\n}\n\nconst deprecatedCommonfy = deprecate(\n () => {},\n 'Common is now deprecated, just access the properties directly',\n)\n\n/**\n * Deprecated, now a noop\n * <p>This will be removed *soon* please stop using it</p>\n * <p>Just access <code><{@link Post}>.prop</code>, no need to commonfy anymore\n *\n * @deprecated Just use <code><{@link Post}>.prop</code> instead\n * @param {Post[]} images Array of {@link Post} objects\n * @return {Promise<Post[]>} Array of {@link Post} objects\n */\nexport function commonfy(images: Post[]): Promise<Post[]> {\n deprecatedCommonfy()\n return Promise.resolve(images)\n}\n\nexport { Booru as BooruClass } from './boorus/Booru'\nexport { BooruError, sites } from './Constants'\nexport { resolveSite } from './Utils'\nexport { Derpibooru, Post, SearchResults, Site, XmlBooru }\nexport type { BooruCredentials, SearchParameters }\n"]}
|