Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add category tag for Wallhaven. #3247

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/sites/WallHaven/model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function parseSearch(search: string): { query: string, purity: string, order: string, sort: string, ratios: string[] } {
function parseSearch(search: string): { query: string, purity: string, category: string, order: string, sort: string, ratios: string[] } {

Check warning on line 1 in src/sites/WallHaven/model.ts

View check run for this annotation

Codecov / codecov/patch

src/sites/WallHaven/model.ts#L1

Added line #L1 was not covered by tests
let query: string = "";
let purity: string = "111";
let category: string = "111";

Check warning on line 4 in src/sites/WallHaven/model.ts

View check run for this annotation

Codecov / codecov/patch

src/sites/WallHaven/model.ts#L4

Added line #L4 was not covered by tests
let order: string = "date_added";
let sort: string = "desc";
const ratios: string[] = [];
Expand All @@ -11,6 +12,12 @@
} else if (tag.indexOf("-rating:") === 0) {
const val = tag.substr(8);
purity = val === "s" || val === "safe" ? "011" : (val === "e" || val === "explicit" ? "110" : "101");
} else if (tag.indexOf("category:") === 0) {
const val = tag.substr(9);

Check warning on line 16 in src/sites/WallHaven/model.ts

View check run for this annotation

Codecov / codecov/patch

src/sites/WallHaven/model.ts#L16

Added line #L16 was not covered by tests
category = val === "anime" ? "010" : (val === "people" ? "001" : "100");
} else if (tag.indexOf("-category:") === 0) {
const val = tag.substr(10);

Check warning on line 19 in src/sites/WallHaven/model.ts

View check run for this annotation

Codecov / codecov/patch

src/sites/WallHaven/model.ts#L19

Added line #L19 was not covered by tests
category = val === "anime" ? "101" : (val === "people" ? "110" : "011");
} else if (tag.indexOf("order:") === 0) {
const val = tag.substr(6);
if (val.substr(-5) === "_desc") {
Expand All @@ -29,12 +36,12 @@
query += (query ? " " : "") + tag;
}
}
return { query, purity, order, sort, ratios }
return { query, purity, category, order, sort, ratios }

Check warning on line 39 in src/sites/WallHaven/model.ts

View check run for this annotation

Codecov / codecov/patch

src/sites/WallHaven/model.ts#L39

Added line #L39 was not covered by tests
}

export const source: ISource = {
name: "WallHaven",
modifiers: ["rating:s", "rating:safe", "rating:q", "rating:questionable", "rating:e", "rating:explicit", "order:relevance", "order:random", "order:date_added", "order:views", "order:favorites", "order:toplist", "order:hot"],
modifiers: ["rating:s", "rating:safe", "rating:q", "rating:questionable", "rating:e", "rating:explicit", "order:relevance", "order:random", "order:date_added", "order:views", "order:favorites", "order:toplist", "order:hot", "category:general", "category:anime", "category:people"],
forcedTokens: ["tags"],
auth: {
url: {
Expand All @@ -58,6 +65,7 @@
const params: Record<string, any> = {
q: search.query,
purity: search.purity,
categories: search.category,
page: query.page,
sorting: search.order,
order: search.sort,
Expand Down
Loading