From c137f17f9cd3f863ba82c64943fa6b10839498e9 Mon Sep 17 00:00:00 2001 From: jmortiger Date: Sun, 10 Nov 2024 23:23:56 -0500 Subject: [PATCH] [Blacklist] Add fuzzy direct equality to filesize blacklist tag (#784) The search metatag `filesize`, when using a direct equality comparison (`=`, e.g. `filesize:10kb`), instead uses a range comparison (`..`) with the bounds being the value + & - 5% (e.g. `filesize:10kb` is equal to `filesize:9.5kb..10.5kb`). The equivalent blacklist tag mirrored the search metatag in all aspects but this; this commit adds this fuzzy matching capability. --- app/javascript/src/javascripts/models/Filter.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/javascript/src/javascripts/models/Filter.js b/app/javascript/src/javascripts/models/Filter.js index f8d5e85d1..24eeabbd7 100644 --- a/app/javascript/src/javascripts/models/Filter.js +++ b/app/javascript/src/javascripts/models/Filter.js @@ -170,7 +170,19 @@ class FilterToken { ]; } } - } else this.value = FilterUtils.normalizeData(raw, this.type); + } else { + this.value = FilterUtils.normalizeData(raw, this.type); + if (this.comparison === "=" && this.type === "filesize") { + // If the comparison uses direct equality, mirror the fudging behavior of + // the filesize search metatag by changing the comparison to a range of + // the initial value -5% and +5%. + this.comparison = ".."; + this.value = [ + Math.trunc(this.value * 0.95), + Math.trunc(this.value * 1.05), + ]; + } + } } /**