From b5dea32ea5fe90454862f2e7085c48ba49b250fb Mon Sep 17 00:00:00 2001 From: BlockListed <44610569+BlockListed@users.noreply.github.com> Date: Sat, 9 Sep 2023 13:53:19 +0200 Subject: [PATCH] make attachments / ciphers support multi-domains --- src/db/models/attachment.rs | 10 ++++++---- src/db/models/cipher.rs | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs index f8eca72f..a1f1604d 100644 --- a/src/db/models/attachment.rs +++ b/src/db/models/attachment.rs @@ -35,15 +35,17 @@ impl Attachment { format!("{}/{}/{}", CONFIG.attachments_folder(), self.cipher_uuid, self.id) } - pub fn get_url(&self, host: &str) -> String { + // TODO: Change back + pub fn get_url(&self, base_url: &str, _parameter_to_break_existing_uses: ()) -> String { let token = encode_jwt(&generate_file_download_claims(self.cipher_uuid.clone(), self.id.clone())); - format!("{}/attachments/{}/{}?token={}", host, self.cipher_uuid, self.id, token) + format!("{}/attachments/{}/{}?token={}", base_url, self.cipher_uuid, self.id, token) } - pub fn to_json(&self, host: &str) -> Value { + // TODO: Change back + pub fn to_json(&self, base_url: &str, _parameter_to_break_existing_uses: ()) -> Value { json!({ "Id": self.id, - "Url": self.get_url(host), + "Url": self.get_url(base_url, ()), "FileName": self.file_name, "Size": self.file_size.to_string(), "SizeName": crate::util::get_display_size(self.file_size), diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 61683d85..f9192f6c 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -113,25 +113,27 @@ use crate::error::MapResult; /// Database methods impl Cipher { + // TODO: Change back pub async fn to_json( &self, - host: &str, + base_url: &str, user_uuid: &str, cipher_sync_data: Option<&CipherSyncData>, sync_type: CipherSyncType, conn: &mut DbConn, + _parameter_to_break_existing_uses: (), ) -> Value { use crate::util::format_date; let mut attachments_json: Value = Value::Null; if let Some(cipher_sync_data) = cipher_sync_data { if let Some(attachments) = cipher_sync_data.cipher_attachments.get(&self.uuid) { - attachments_json = attachments.iter().map(|c| c.to_json(host)).collect(); + attachments_json = attachments.iter().map(|c| c.to_json(base_url, ())).collect(); } } else { let attachments = Attachment::find_by_cipher(&self.uuid, conn).await; if !attachments.is_empty() { - attachments_json = attachments.iter().map(|c| c.to_json(host)).collect() + attachments_json = attachments.iter().map(|c| c.to_json(base_url, ())).collect() } }