mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
new endpoints
This commit is contained in:
1 parent
5d062876b6
commit
112836dc2b
7 files changed
+107
-6
No files matched your search
@@ -32,7 +32,9 @@ use crate::services::fal::commands::set_fal_api_key_command::set_fal_api_key_com
|
||||
use crate::services::fal::state::fal_credential_manager::FalCredentialManager;
|
||||
use crate::services::fal::state::fal_task_queue::FalTaskQueue;
|
||||
use crate::services::fal::threads::fal_task_polling_thread::fal_task_polling_thread;
|
||||
use crate::services::midjourney::commands::open_midjourney_login_command::open_midjourney_login_command;
|
||||
use crate::services::midjourney::commands::midjourney_clear_credentials_command::midjourney_clear_credentials_command;
|
||||
use crate::services::midjourney::commands::midjourney_get_credential_info_command::midjourney_get_credential_info_command;
|
||||
use crate::services::midjourney::commands::midjourney_open_login_command::midjourney_open_login_command;
|
||||
use crate::services::midjourney::state::midjourney_credential_manager::MidjourneyCredentialManager;
|
||||
use crate::services::sora::commands::check_sora_session_command::check_sora_session_command;
|
||||
use crate::services::sora::commands::open_sora_login_command::open_sora_login_command;
|
||||
@@ -164,7 +166,9 @@ pub fn run() {
|
||||
get_provider_order_command,
|
||||
load_without_cors_command,
|
||||
open_sora_login_command,
|
||||
open_midjourney_login_command,
|
||||
midjourney_clear_credentials_command,
|
||||
midjourney_get_credential_info_command,
|
||||
midjourney_open_login_command,
|
||||
platform_info_command,
|
||||
set_fal_api_key_command,
|
||||
set_provider_order_command,
|
||||
|
||||
Whitespace-only changes.
+31
@@ -0,0 +1,31 @@
|
||||
use crate::core::commands::response::shorthand::{Response, SimpleResponse};
|
||||
use crate::services::fal::state::fal_credential_manager::FalCredentialManager;
|
||||
use crate::services::midjourney::state::midjourney_credential_manager::MidjourneyCredentialManager;
|
||||
use errors::AnyhowResult;
|
||||
use fal_client::creds::fal_api_key::FalApiKey;
|
||||
use log::{error, info};
|
||||
use serde_derive::Deserialize;
|
||||
use tauri::State;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn midjourney_clear_credentials_command(
|
||||
creds_manager: State<'_, MidjourneyCredentialManager>,
|
||||
) -> SimpleResponse {
|
||||
info!("midjourney_clear_credentials_command called");
|
||||
|
||||
clear_creds(&creds_manager)
|
||||
.map_err(|err| {
|
||||
error!("Error clearing creds: {:?}", err);
|
||||
"error clearing creds"
|
||||
})?;
|
||||
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
fn clear_creds(
|
||||
creds: &MidjourneyCredentialManager,
|
||||
) -> AnyhowResult<()> {
|
||||
creds.clear_credentials()?;
|
||||
creds.persist_to_disk()?;
|
||||
Ok(())
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
use crate::core::commands::response::shorthand::{Response, ResponseOrErrorMessage};
|
||||
use crate::core::commands::response::success_response_wrapper::SerializeMarker;
|
||||
use crate::services::fal::state::fal_credential_manager::FalCredentialManager;
|
||||
use crate::services::midjourney::state::midjourney_credential_manager::MidjourneyCredentialManager;
|
||||
use errors::AnyhowResult;
|
||||
use log::{error, info};
|
||||
use serde_derive::Serialize;
|
||||
use tauri::State;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct MidjourneyGetCredentialInfoResponse {
|
||||
pub maybe_email: Option<String>,
|
||||
pub can_clear_state: bool,
|
||||
}
|
||||
|
||||
impl SerializeMarker for MidjourneyGetCredentialInfoResponse {}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn midjourney_get_credential_info_command(
|
||||
creds_manager: State<'_, MidjourneyCredentialManager>,
|
||||
) -> ResponseOrErrorMessage<MidjourneyGetCredentialInfoResponse> {
|
||||
info!("midjourney_get_credential_info_command called");
|
||||
|
||||
let info = get_info(&creds_manager)
|
||||
.map_err(|err| {
|
||||
error!("Error getting info: {:?}", err);
|
||||
"error getting info"
|
||||
})?;
|
||||
|
||||
Ok(info.into())
|
||||
}
|
||||
|
||||
fn get_info(
|
||||
creds: &MidjourneyCredentialManager,
|
||||
) -> AnyhowResult<MidjourneyGetCredentialInfoResponse> {
|
||||
let mut can_clear_state = true;
|
||||
|
||||
let maybe_cookies = creds.maybe_copy_cookie_store()?;
|
||||
let maybe_user_info = creds.maybe_copy_user_info()?;
|
||||
|
||||
if maybe_cookies.is_none() && maybe_user_info.is_none() {
|
||||
can_clear_state = false;
|
||||
}
|
||||
|
||||
let maybe_email = maybe_user_info
|
||||
.map(|info| info.email.clone())
|
||||
.flatten();
|
||||
|
||||
Ok(MidjourneyGetCredentialInfoResponse {
|
||||
maybe_email,
|
||||
can_clear_state,
|
||||
})
|
||||
}
|
||||
+2
-2
@@ -7,12 +7,12 @@ use log::{error, info};
|
||||
use tauri::{AppHandle, State};
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn open_midjourney_login_command(
|
||||
pub async fn midjourney_open_login_command(
|
||||
app: AppHandle,
|
||||
app_data_root: State<'_, AppDataRoot>,
|
||||
mj_creds_manager: State<'_, MidjourneyCredentialManager>,
|
||||
) -> Result<String, String> {
|
||||
info!("open_midjourney_command called");
|
||||
info!("midjourney_open_login_command called");
|
||||
|
||||
do_open_login(&app, &app_data_root, &mj_creds_manager)
|
||||
.await
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod open_midjourney_login_command;
|
||||
pub mod clear_midjourney_credentials_command;
|
||||
pub mod midjourney_clear_credentials_command;
|
||||
pub mod midjourney_get_credential_info_command;
|
||||
pub mod midjourney_open_login_command;
|
||||
+12
@@ -94,6 +94,18 @@ impl MidjourneyCredentialManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear_credentials(&self) -> anyhow::Result<()> {
|
||||
match self.cookies.write() {
|
||||
Err(err) => return Err(anyhow::anyhow!("Failed to acquire write lock: {:?}", err)),
|
||||
Ok(mut store) => *store = None,
|
||||
}
|
||||
match self.user_info.write() {
|
||||
Err(err) => return Err(anyhow::anyhow!("Failed to acquire write lock: {:?}", err)),
|
||||
Ok(mut info) => *info = None,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn persist_to_disk(&self) -> anyhow::Result<()> {
|
||||
let maybe_cookies = match self.cookies.read() {
|
||||
Err(err) => return Err(anyhow::anyhow!("Failed to acquire read lock: {:?}", err)),
|
||||
|
||||
Reference in new issue
Block a user