From d1e1a41d41f60708b2aabda1b60fe780e1c4ba35 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 8 Apr 2024 17:09:16 +0200 Subject: [PATCH] fix lemmy tests --- src/fetch/mod.rs | 12 ++++++------ src/fetch/object_id.rs | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/fetch/mod.rs b/src/fetch/mod.rs index 332f581..4d563b6 100644 --- a/src/fetch/mod.rs +++ b/src/fetch/mod.rs @@ -74,6 +74,12 @@ pub async fn fetch_object_http( return Err(Error::FetchWrongId(res.url)); } + // Dont allow fetching local object. Only check this after the request as a local url + // may redirect to a remote object. + if data.config.is_local_url(&res.url) { + return Err(Error::NotFound); + } + Ok(res) } @@ -124,12 +130,6 @@ async fn fetch_object_http_with_accept( let text = res.bytes_limited().await?; let object_id = extract_id(&text).ok(); - // Dont allow fetching local object. Only check this after the request as a local url - // may redirect to a remote object. - if data.config.is_local_url(&url) { - return Err(Error::NotFound); - } - match serde_json::from_slice(&text) { Ok(object) => Ok(FetchObjectResponse { object, diff --git a/src/fetch/object_id.rs b/src/fetch/object_id.rs index f17a836..50e75bc 100644 --- a/src/fetch/object_id.rs +++ b/src/fetch/object_id.rs @@ -91,9 +91,10 @@ where // object found in database if let Some(object) = db_object { - // object is old and should be refetched if let Some(last_refreshed_at) = object.last_refreshed_at() { - if should_refetch_object(last_refreshed_at) { + let is_local = data.config.is_local_url(&self.0); + if !is_local && should_refetch_object(last_refreshed_at) { + // object is outdated and should be refetched return self.dereference_from_http(data, Some(object)).await; } }