Skip to content

Commit

Permalink
release: v2.7.7
Browse files Browse the repository at this point in the history
  • Loading branch information
asadahimeka committed Jun 9, 2024
1 parent 59d8674 commit 9599c1c
Show file tree
Hide file tree
Showing 37 changed files with 1,406 additions and 4,555 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# booru Changelog

## v2.7.7

- feat: support cors proxy using global method
- fix: update api endpoint of rule34.paheal

## v2.7.6

- feat: support atfbooru
Expand Down
7 changes: 4 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface InternalSearchParameters extends SearchParameters {
/** If `order:random` should be faked */
fakeLimit?: number;
/** The tags used in the search */
tags?: string[] | string;
tags?: string[];
}

/**
Expand Down Expand Up @@ -369,6 +369,7 @@ declare class Booru {
* @param credentials Credentials for the API (Currently not used)
*/
constructor(site: Site, credentials?: BooruCredentials);
protected normalizeTags(tags: string | string[]): string[];
/**
* Search for images on this booru
* @param {String|String[]} tags The tag(s) to search for
Expand All @@ -387,11 +388,11 @@ declare class Booru {
* The internal & common searching logic, pls dont use this use .search instead
*
* @protected
* @param {String[]|String} tags The tags to search with
* @param {String[]} tags The tags to search with
* @param {InternalSearchParameters} searchArgs The arguments for the search
* @return {Promise<Object>}
*/
protected doSearchRequest(tags: string[] | string, { uri, limit, random, page, credentials }?: InternalSearchParameters): Promise<any>;
protected doSearchRequest(tags: string[], { uri, limit, random, page, credentials }?: InternalSearchParameters): Promise<any>;
/**
* Generates a URL to search the booru with, mostly for debugging purposes
* @param opt
Expand Down
39 changes: 22 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var sites_default = {
],
nsfw: true,
api: {
search: "/api/danbooru/find_posts/index.xml?",
search: "/api/danbooru/find_posts?",
postView: "/post/view/"
},
random: false
Expand Down Expand Up @@ -357,12 +357,16 @@ function searchURI(site, tags = [], limit = 100, page = 1, credentials) {
const q = credentials.query;
credentialsQuery = q.startsWith("&") ? q : "&" + q;
}
return `http${site.insecure ? "" : "s"}://${site.domain}${site.api.search}${site.tagQuery}=${expandTags(tags).join(site.tagJoin)}&limit=${limit}&${site.paginate}=${page}${credentialsQuery}`;
let uri = `http${site.insecure ? "" : "s"}://${site.domain}${site.api.search}${site.tagQuery}=${expandTags(tags).join(site.tagJoin)}&limit=${limit}&${site.paginate}=${page}${credentialsQuery}`;
if (typeof BOORU_FETCH_PROXY === "function") {
uri = BOORU_FETCH_PROXY(uri) || uri;
}
return uri;
}
var defaultOptions = {
headers: {
Accept: "application/json, application/xml;q=0.9, */*;q=0.8",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
}
};

Expand Down Expand Up @@ -749,6 +753,13 @@ var Booru = class {
this.site = site;
this.credentials = credentials;
}
normalizeTags(tags) {
if (!Array.isArray(tags)) {
return [tags];
} else {
return tags.slice();
}
}
async search(tags, {
limit = 1,
random = false,
Expand All @@ -757,8 +768,9 @@ var Booru = class {
credentials
} = {}) {
const fakeLimit = random && !this.site.random ? 100 : 0;
const tagArray = this.normalizeTags(tags);
try {
const searchResult = await this.doSearchRequest(tags, {
const searchResult = await this.doSearchRequest(tagArray, {
limit,
random,
page,
Expand All @@ -767,7 +779,7 @@ var Booru = class {
});
return this.parseSearchResult(searchResult, {
fakeLimit,
tags,
tags: tagArray,
limit,
random,
page,
Expand All @@ -794,8 +806,6 @@ var Booru = class {
page = 1,
credentials
} = {}) {
if (!Array.isArray(tags))
tags = [tags];
let fakeLimit;
if (random) {
if (this.site.random) {
Expand Down Expand Up @@ -884,9 +894,6 @@ var Booru = class {
if (tags === void 0) {
tags = [];
}
if (!Array.isArray(tags)) {
tags = [tags];
}
if (!showUnavailable) {
posts = posts.filter((p) => p.available);
}
Expand All @@ -901,16 +908,14 @@ var Derpibooru = class extends Booru_default {
super(site, credentials);
}
search(tags, { limit = 1, random = false, page = 0 } = {}) {
if (!Array.isArray(tags)) {
tags = [tags];
}
const tagArray = this.normalizeTags(tags);
if (tags[0] === void 0) {
tags[0] = "*";
tagArray[0] = "*";
}
page += 1;
const uri = this.getSearchUrl({ tags, limit, page }) + (random && this.site.random === "string" ? `&${this.site.random}` : "") + (this.credentials ? `&key=${this.credentials.token}` : "");
return super.doSearchRequest(tags, { limit, random, page, uri }).then(
(r) => super.parseSearchResult(r, { fakeLimit: 0, tags, limit, random, page })
const uri = this.getSearchUrl({ tags: tagArray, limit, page }) + (random && this.site.random === "string" ? `&${this.site.random}` : "") + (this.credentials ? `&key=${this.credentials.token}` : "");
return super.doSearchRequest(tagArray, { limit, random, page, uri }).then(
(r) => super.parseSearchResult(r, { fakeLimit: 0, tags: tagArray, limit, random, page })
).catch((e) => Promise.reject(new BooruError(e)));
}
};
Expand Down
39 changes: 22 additions & 17 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ var sites_default = {
],
nsfw: true,
api: {
search: "/api/danbooru/find_posts/index.xml?",
search: "/api/danbooru/find_posts?",
postView: "/post/view/"
},
random: false
Expand Down Expand Up @@ -320,12 +320,16 @@ function searchURI(site, tags = [], limit = 100, page = 1, credentials) {
const q = credentials.query;
credentialsQuery = q.startsWith("&") ? q : "&" + q;
}
return `http${site.insecure ? "" : "s"}://${site.domain}${site.api.search}${site.tagQuery}=${expandTags(tags).join(site.tagJoin)}&limit=${limit}&${site.paginate}=${page}${credentialsQuery}`;
let uri = `http${site.insecure ? "" : "s"}://${site.domain}${site.api.search}${site.tagQuery}=${expandTags(tags).join(site.tagJoin)}&limit=${limit}&${site.paginate}=${page}${credentialsQuery}`;
if (typeof BOORU_FETCH_PROXY === "function") {
uri = BOORU_FETCH_PROXY(uri) || uri;
}
return uri;
}
var defaultOptions = {
headers: {
Accept: "application/json, application/xml;q=0.9, */*;q=0.8",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
}
};

Expand Down Expand Up @@ -712,6 +716,13 @@ var Booru = class {
this.site = site;
this.credentials = credentials;
}
normalizeTags(tags) {
if (!Array.isArray(tags)) {
return [tags];
} else {
return tags.slice();
}
}
async search(tags, {
limit = 1,
random = false,
Expand All @@ -720,8 +731,9 @@ var Booru = class {
credentials
} = {}) {
const fakeLimit = random && !this.site.random ? 100 : 0;
const tagArray = this.normalizeTags(tags);
try {
const searchResult = await this.doSearchRequest(tags, {
const searchResult = await this.doSearchRequest(tagArray, {
limit,
random,
page,
Expand All @@ -730,7 +742,7 @@ var Booru = class {
});
return this.parseSearchResult(searchResult, {
fakeLimit,
tags,
tags: tagArray,
limit,
random,
page,
Expand All @@ -757,8 +769,6 @@ var Booru = class {
page = 1,
credentials
} = {}) {
if (!Array.isArray(tags))
tags = [tags];
let fakeLimit;
if (random) {
if (this.site.random) {
Expand Down Expand Up @@ -847,9 +857,6 @@ var Booru = class {
if (tags === void 0) {
tags = [];
}
if (!Array.isArray(tags)) {
tags = [tags];
}
if (!showUnavailable) {
posts = posts.filter((p) => p.available);
}
Expand All @@ -864,16 +871,14 @@ var Derpibooru = class extends Booru_default {
super(site, credentials);
}
search(tags, { limit = 1, random = false, page = 0 } = {}) {
if (!Array.isArray(tags)) {
tags = [tags];
}
const tagArray = this.normalizeTags(tags);
if (tags[0] === void 0) {
tags[0] = "*";
tagArray[0] = "*";
}
page += 1;
const uri = this.getSearchUrl({ tags, limit, page }) + (random && this.site.random === "string" ? `&${this.site.random}` : "") + (this.credentials ? `&key=${this.credentials.token}` : "");
return super.doSearchRequest(tags, { limit, random, page, uri }).then(
(r) => super.parseSearchResult(r, { fakeLimit: 0, tags, limit, random, page })
const uri = this.getSearchUrl({ tags: tagArray, limit, page }) + (random && this.site.random === "string" ? `&${this.site.random}` : "") + (this.credentials ? `&key=${this.credentials.token}` : "");
return super.doSearchRequest(tagArray, { limit, random, page, uri }).then(
(r) => super.parseSearchResult(r, { fakeLimit: 0, tags: tagArray, limit, random, page })
).catch((e) => Promise.reject(new BooruError(e)));
}
};
Expand Down
24 changes: 12 additions & 12 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
:root {
--light-hl-0: #000000;
--dark-hl-0: #D4D4D4;
--light-hl-1: #008000;
--dark-hl-1: #6A9955;
--light-hl-2: #0000FF;
--dark-hl-2: #569CD6;
--light-hl-3: #0070C1;
--dark-hl-3: #4FC1FF;
--light-hl-4: #795E26;
--dark-hl-4: #DCDCAA;
--light-hl-5: #A31515;
--dark-hl-5: #CE9178;
--light-hl-0: #795E26;
--dark-hl-0: #DCDCAA;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #A31515;
--dark-hl-2: #CE9178;
--light-hl-3: #008000;
--dark-hl-3: #6A9955;
--light-hl-4: #0000FF;
--dark-hl-4: #569CD6;
--light-hl-5: #0070C1;
--dark-hl-5: #4FC1FF;
--light-hl-6: #001080;
--dark-hl-6: #9CDCFE;
--light-hl-7: #098658;
Expand Down
Loading

0 comments on commit 9599c1c

Please sign in to comment.