From 2c93387a34e0ffdb964932e10f61a31b5a627864 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 9 Mar 2026 17:09:15 +0000 Subject: [PATCH] :recycle: Move int-in-range? helper to app.common.data Remove the private int-in-range? definition from app.auth.oidc and add it as a public utility in app.common.data, then use d/int-in-range? in both app.auth.oidc and app.media. Signed-off-by: Andrey Antukh --- backend/src/app/auth/oidc.clj | 8 ++------ backend/src/app/media.clj | 2 +- common/src/app/common/data.cljc | 5 +++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/src/app/auth/oidc.clj b/backend/src/app/auth/oidc.clj index 7668a49b99..5b74725c54 100644 --- a/backend/src/app/auth/oidc.clj +++ b/backend/src/app/auth/oidc.clj @@ -223,10 +223,6 @@ ;; GITHUB AUTH PROVIDER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn- int-in-range? - [val start end] - (and (<= start val) (< val end))) - (defn- lookup-github-email [cfg tdata props] (or (some-> props :github/email) @@ -237,7 +233,7 @@ {:keys [status body]} (http/req! cfg params)] - (when-not (int-in-range? status 200 300) + (when-not (d/int-in-range? status 200 300) (ex/raise :type :internal :code :unable-to-retrieve-github-emails :hint "unable to retrieve github emails" @@ -513,7 +509,7 @@ :status (:status response) :body (:body response)) - (when-not (int-in-range? (:status response) 200 300) + (when-not (d/int-in-range? (:status response) 200 300) (ex/raise :type :internal :code :unable-to-retrieve-user-info :hint "unable to retrieve user info" diff --git a/backend/src/app/media.clj b/backend/src/app/media.clj index 6bd3bf661a..27f74c1b54 100644 --- a/backend/src/app/media.clj +++ b/backend/src/app/media.clj @@ -304,7 +304,7 @@ format (cm/mtype->format mtype) max-size (cf/get :media-max-file-size default-max-file-size)] - (when-not (and (>= status 200) (< status 300)) + (when-not (d/int-in-range? status 200 300) (ex/raise :type :validation :code :unable-to-download-from-url :hint "the url returned a non-success http status" diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 4cb6cedc60..c089a3b113 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -36,6 +36,11 @@ [size i] (and (< i size) (>= i 0))) +(defn int-in-range? + "Check if an integer val is in the range [start, end)." + [val start end] + (and (>= val start) (< val end))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Commonly used transducers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;