From 5e3fe6cfc42a3ed97aa995268e016f573ec274fc Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 10 May 2026 09:59:08 -0400 Subject: [PATCH] payloads --- .../artcraft/src/core/providers/mod.rs | 1 + .../src/core/providers/payload/api_key.rs | 2 + .../src/core/providers/payload/mod.rs | 3 + .../payload/provider_credential_payload.rs | 8 +++ .../src/core/providers/payload/web_login.rs | 70 +++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 crates/desktop/artcraft/src/core/providers/payload/api_key.rs create mode 100644 crates/desktop/artcraft/src/core/providers/payload/mod.rs create mode 100644 crates/desktop/artcraft/src/core/providers/payload/provider_credential_payload.rs create mode 100644 crates/desktop/artcraft/src/core/providers/payload/web_login.rs diff --git a/crates/desktop/artcraft/src/core/providers/mod.rs b/crates/desktop/artcraft/src/core/providers/mod.rs index 990814b096..a552943c94 100644 --- a/crates/desktop/artcraft/src/core/providers/mod.rs +++ b/crates/desktop/artcraft/src/core/providers/mod.rs @@ -1,2 +1,3 @@ +pub mod payload; pub mod provider_credential_key; pub mod provider_credential_type; \ No newline at end of file diff --git a/crates/desktop/artcraft/src/core/providers/payload/api_key.rs b/crates/desktop/artcraft/src/core/providers/payload/api_key.rs new file mode 100644 index 0000000000..7156d55232 --- /dev/null +++ b/crates/desktop/artcraft/src/core/providers/payload/api_key.rs @@ -0,0 +1,2 @@ + +pub struct ApiKeyData(pub String); diff --git a/crates/desktop/artcraft/src/core/providers/payload/mod.rs b/crates/desktop/artcraft/src/core/providers/payload/mod.rs new file mode 100644 index 0000000000..8d5083bee3 --- /dev/null +++ b/crates/desktop/artcraft/src/core/providers/payload/mod.rs @@ -0,0 +1,3 @@ +pub mod provider_credential_payload; +pub mod api_key; +pub mod web_login; \ No newline at end of file diff --git a/crates/desktop/artcraft/src/core/providers/payload/provider_credential_payload.rs b/crates/desktop/artcraft/src/core/providers/payload/provider_credential_payload.rs new file mode 100644 index 0000000000..93b78dfb92 --- /dev/null +++ b/crates/desktop/artcraft/src/core/providers/payload/provider_credential_payload.rs @@ -0,0 +1,8 @@ +use crate::core::providers::payload::api_key::ApiKeyData; +use crate::core::providers::payload::web_login::WebLoginData; + +pub enum ProviderCredentialPayload { + ApiKey(ApiKeyData), + // TODO: There might be logins in the future that use weird header states, etc. + WebLogin (WebLoginData), +} diff --git a/crates/desktop/artcraft/src/core/providers/payload/web_login.rs b/crates/desktop/artcraft/src/core/providers/payload/web_login.rs new file mode 100644 index 0000000000..56ea3a04cc --- /dev/null +++ b/crates/desktop/artcraft/src/core/providers/payload/web_login.rs @@ -0,0 +1,70 @@ +use std::collections::HashMap; +use std::error::Error; +use std::fmt::Display; +use std::path::Path; +use chrono::{DateTime, Utc}; +use crate::core::artcraft_error::ArtcraftError; + +const CURRENT_VERSION: u8 = 1; + +pub struct WebLoginData { + pub cookies_header: Option, + pub additional_headers: Option>, + + pub username: Option, + pub email_address: Option, + + pub created_at: Option>, + pub updated_at: Option>, +} + +impl WebLoginData { + pub fn new() -> Self { + Self { + cookies_header: None, + additional_headers: None, + username: None, + email_address: None, + created_at: None, + updated_at: None, + } + } + + pub fn load_from_file>(file_path: P) -> Result { + unimplemented!() + } + + pub fn save_to_file>(&self, file_path: P) -> Result<(), ArtcraftError> { + unimplemented!() + } +} + +#[derive(Debug)] +pub enum WebLoginDataError { + InvalidVersion, + IoError(std::io::Error), +} + +impl Error for WebLoginDataError {} + +impl Display for WebLoginDataError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + WebLoginDataError::InvalidVersion => write!(f, "Invalid version"), + WebLoginDataError::IoError(e) => write!(f, "IO error: {}", e), + } + } +} + +struct WebLoginDataSerializable { + version: u8, + + cookies_header: Option, + additional_headers: Option>, + + username: Option, + email_address: Option, + + created_at: Option>, + updated_at: Option>, +}