Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Define your Radarr and Sonarr instances in this section. You can name the instan
Define your request filters in this section.

- **`media_type`**: Specifies the type of media, either `"movie"` or `"tv"`.
- **`is_not_4k`**: Should only apply to non-4k requests
- **`is_4k`**: Should only apply to 4k requests
- **`conditions`**: A set of fields and values used to filter requests. Refer to [testData.js](https://github.com/varthe/Redirecterr/blob/main/testData.js) for examples of request objects. Each field within `conditions` can be:
- A **single value**: Matches if the value is present in the request.
- A **list of values**: Matches if any value in the list is present in the request.
Expand Down
6 changes: 6 additions & 0 deletions configBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const schema = {
type: "string",
enum: ["movie", "tv"],
},
is_not_4k: {
type: "boolean",
},
is_4k: {
type: "boolean",
},
conditions: {
type: "object",
additionalProperties: {
Expand Down
5 changes: 4 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ const matchValue = (filterValue, dataValue) => {

const findMatchingInstances = (webhook, data, filters) => {
try {
const matchingFilter = filters.find(({ media_type, conditions }) => {
const matchingFilter = filters.find(({ media_type, is_not_4k, is_4k, conditions }) => {
if (media_type !== webhook.media?.media_type) return false

if (is_not_4k && webhook.media?.status !== "PENDING") return false
if (is_4k && webhook.media?.status4k !== "PENDING") return false

for (const [key, value] of Object.entries(conditions || {})) {
const requestValue = data[key] || webhook.request?.[key]
if (!requestValue) {
Expand Down