mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
resetting bearer token fails
This commit is contained in:
1 parent
cd680ac319
commit
a9967f0e76
5 files changed
+35
-2
No files matched your search
@@ -7,6 +7,7 @@ use openai_sora_client::credentials::SoraCredentials;
|
||||
use openai_sora_client::sentinel_refresh::refresh_sentinel;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use anyhow::anyhow;
|
||||
use openai_sora_client::sentinel_refresh::generate::token::generate_token;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -55,6 +56,7 @@ impl SoraCredentialManager {
|
||||
Ok(creds)
|
||||
}
|
||||
|
||||
/// Refresh the sentinel token from Sora's API
|
||||
pub async fn call_sentinel_refresh(&self) -> AnyhowResult<SoraCredentials> {
|
||||
// NB(bt,2025-04-21): Technically we don't need credentials to get a sentinel.
|
||||
let mut creds = self.holder.get_credentials_required()?;
|
||||
|
||||
@@ -10,6 +10,7 @@ use reqwest::Url;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use tauri::{AppHandle, Manager, Webview};
|
||||
use crate::utils::sora::initialize_sora_jwt_bearer_token::initialize_sora_jwt_bearer_token;
|
||||
|
||||
pub const LOGIN_WINDOW_NAME: &str = "login_window";
|
||||
|
||||
@@ -48,7 +49,7 @@ async fn check_login_window(webview: &Webview, app_data_root: &AppDataRoot) -> A
|
||||
clear_browsing_data_on_test_domain(webview)?;
|
||||
//keep_on_task(webview)?;
|
||||
extract_cookies_to_file(webview, app_data_root)?;
|
||||
// TODO: Other maintenance tasks ...
|
||||
//initialize_sora_jwt_bearer_token(app_data_root).await?; // TODO: This only runs once. We need better management.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@ pub mod get_url_file_extension;
|
||||
pub mod image;
|
||||
pub mod large_file_transfer;
|
||||
pub mod simple_http_download;
|
||||
pub mod sora_webview_cookies;
|
||||
pub mod sora_webview_cookies;
|
||||
pub mod sora;
|
||||
@@ -0,0 +1,28 @@
|
||||
use crate::state::app_dir::AppDataRoot;
|
||||
use anyhow::anyhow;
|
||||
use errors::AnyhowResult;
|
||||
use log::info;
|
||||
use openai_sora_client::bearer::generate::generate_bearer_with_cookie;
|
||||
|
||||
/// Loading the JWT bearer token for the first time.
|
||||
pub async fn initialize_sora_jwt_bearer_token(app_data_root: &AppDataRoot) -> AnyhowResult<()> {
|
||||
if !app_data_root.get_sora_cookie_file_path().exists() {
|
||||
return Err(anyhow!("Cookie file does not exist"));
|
||||
}
|
||||
|
||||
if app_data_root.get_sora_bearer_token_file_path().exists() {
|
||||
return Ok(()); // Bearer token already exists.
|
||||
}
|
||||
|
||||
let cookie = std::fs::read_to_string(app_data_root.get_sora_cookie_file_path())?
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
info!("Requesting initial JWT bearer token...");
|
||||
|
||||
let bearer = generate_bearer_with_cookie(&cookie).await?;
|
||||
|
||||
std::fs::write(app_data_root.get_sora_bearer_token_file_path(), bearer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod initialize_sora_jwt_bearer_token;
|
||||
Reference in new issue
Block a user