mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-21 22:05:38 -04:00
5f359e975d
New: Season packs and multi-episode releases will show as a single item in the queue Closes #6537
51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
import { PropertyFilter } from 'App/State/AppState';
|
|
|
|
export interface QueryParams {
|
|
[key: string]:
|
|
| string
|
|
| number
|
|
| boolean
|
|
| PropertyFilter[]
|
|
| number[]
|
|
| undefined;
|
|
}
|
|
|
|
const getQueryString = (queryParams?: QueryParams) => {
|
|
if (!queryParams) {
|
|
return '';
|
|
}
|
|
|
|
const searchParams = Object.keys(queryParams).reduce<URLSearchParams>(
|
|
(acc, key) => {
|
|
const value = queryParams[key];
|
|
|
|
if (value == null) {
|
|
return acc;
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
if (typeof value[0] === 'object') {
|
|
(value as PropertyFilter[]).forEach((filter) => {
|
|
acc.append(filter.key, String(filter.value));
|
|
});
|
|
} else {
|
|
value.forEach((item) => {
|
|
acc.append(key, String(item));
|
|
});
|
|
}
|
|
} else {
|
|
acc.append(key, String(value));
|
|
}
|
|
|
|
return acc;
|
|
},
|
|
new URLSearchParams()
|
|
);
|
|
|
|
const paramsString = searchParams.toString();
|
|
|
|
return `?${paramsString}`;
|
|
};
|
|
|
|
export default getQueryString;
|