Add support for literal tags and prefixes
parent
eb7db48de3
commit
6604d3b5c3
|
@ -3,6 +3,7 @@ import validator from 'class-validator';
|
||||||
|
|
||||||
// Modules from file
|
// Modules from file
|
||||||
import { urls } from "../constants/url.js";
|
import { urls } from "../constants/url.js";
|
||||||
|
import PrefixParser from './prefix-parser.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query used to search for specific threads on the platform.
|
* Query used to search for specific threads on the platform.
|
||||||
|
@ -37,14 +38,14 @@ export default class SearchQuery {
|
||||||
@validator.ArrayMaxSize(SearchQuery.MAX_TAGS, {
|
@validator.ArrayMaxSize(SearchQuery.MAX_TAGS, {
|
||||||
message: "Too many tags: $value instead of $constraint1"
|
message: "Too many tags: $value instead of $constraint1"
|
||||||
})
|
})
|
||||||
public tags: number[] = [];
|
public tags: string[] = [];
|
||||||
/**
|
/**
|
||||||
* List of IDs of prefixes to be included in the search.
|
* List of IDs of prefixes to be included in the search.
|
||||||
*/
|
*/
|
||||||
@validator.IsArray({
|
@validator.IsArray({
|
||||||
message: "Expected an array, received $value"
|
message: "Expected an array, received $value"
|
||||||
})
|
})
|
||||||
public prefixes: number[] = [];
|
public prefixes: string[] = [];
|
||||||
/**
|
/**
|
||||||
* Sorting type between (default: `date`):
|
* Sorting type between (default: `date`):
|
||||||
* `date`, `likes`, `views`, `title`, `rating`
|
* `date`, `likes`, `views`, `title`, `rating`
|
||||||
|
@ -104,11 +105,12 @@ export default class SearchQuery {
|
||||||
url.searchParams.set("cat", this.category);
|
url.searchParams.set("cat", this.category);
|
||||||
|
|
||||||
// Add tags and prefixes
|
// Add tags and prefixes
|
||||||
for (const tag of this.tags) {
|
const parser = new PrefixParser();
|
||||||
|
for (const tag of parser.prefixesToIDs(this.tags)) {
|
||||||
url.searchParams.append("tags[]", tag.toString());
|
url.searchParams.append("tags[]", tag.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const p of this.prefixes) {
|
for (const p of parser.prefixesToIDs(this.prefixes)) {
|
||||||
url.searchParams.append("prefixes[]", p.toString());
|
url.searchParams.append("prefixes[]", p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue