mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-07 10:31:46 +00:00
cookies are for the correct domain
This commit is contained in:
1 parent
c256d84389
commit
3e36efe7c8
5 files changed
+21
-4
No files matched your search
@@ -33,8 +33,15 @@ pub async fn submit_job(req: SubmitJobRequest<'_>) -> Result<SubmitJobResponse,
|
||||
// let url = format!("https://{}/api/app/submit-jobs", req.hostname.as_str());
|
||||
let url = format!("https://{}/api/submit-jobs", req.hostname.as_str());
|
||||
|
||||
let cookie_header = req.cookie_header.trim();
|
||||
|
||||
if cookie_header.len() < 20 {
|
||||
error!("Cookie header is too short (len: {}): {}", cookie_header.len(), cookie_header);
|
||||
return Err(MidjourneyClientError::CookieTooShort.into());
|
||||
}
|
||||
|
||||
let mut http_request = client.post(url)
|
||||
.header("cookie", req.cookie_header)
|
||||
.header("cookie", cookie_header)
|
||||
.header("Referer", &referer)
|
||||
.header("Referrer-Policy", "origin-when-cross-origin")
|
||||
.header("accept", "*/*")
|
||||
|
||||
@@ -6,6 +6,9 @@ use std::path::PathBuf;
|
||||
/// An error arising from the client, either before or after the request is sent.
|
||||
#[derive(Debug)]
|
||||
pub enum MidjourneyClientError {
|
||||
/// The cookie was too short to be valid.
|
||||
CookieTooShort,
|
||||
|
||||
/// Could not determine the filetype for the file.
|
||||
FileTypeNotKnown(PathBuf),
|
||||
|
||||
@@ -28,6 +31,7 @@ impl Error for MidjourneyClientError {}
|
||||
impl Display for MidjourneyClientError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::CookieTooShort => write!(f, "The cookie header is too short to be valid."),
|
||||
Self::FileTypeNotKnown(path) => write!(f, "Could not determine the filetype for the file: {:?}", path),
|
||||
Self::FileTypeNotHandled(path) => write!(f, "Could not handle the file type for the file: {:?}", path),
|
||||
Self::IoError(err) => write!(f, "IO error: {}", err),
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ use reqwest::Url;
|
||||
use tauri::webview::Cookie;
|
||||
use tauri::WebviewWindow;
|
||||
|
||||
const ROOT_COOKIE_URL_STR: &str = "https://midjourney.com";
|
||||
const ROOT_COOKIE_URL_STR: &str = "https://www.midjourney.com";
|
||||
|
||||
static ROOT_COOKIE_URL: Lazy<Url> = Lazy::new(|| {
|
||||
Url::parse(ROOT_COOKIE_URL_STR).expect("URL should parse")
|
||||
@@ -16,7 +16,7 @@ pub fn extract_midjourney_webview_cookies(webview: &WebviewWindow) -> AnyhowResu
|
||||
let cookies = get_all_midjourney_cookies(webview)?;
|
||||
for cookie in cookies.iter() {
|
||||
cookie_store.add_cookie_name_and_value(
|
||||
cookie.name().to_string(),
|
||||
cookie.name().to_string(),
|
||||
cookie.value().to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
+2
@@ -117,6 +117,8 @@ async fn check_login_window(
|
||||
// _ => {},
|
||||
//}
|
||||
|
||||
info!("Current cookies (len {}): {:?}", cookie_store.len(), cookie_store.to_cookie_string());
|
||||
|
||||
mj_creds_manager.replace_cookie_store(cookie_store)?;
|
||||
|
||||
if true {
|
||||
|
||||
@@ -18,7 +18,7 @@ impl CookieStore {
|
||||
pub fn add_cookie(&mut self, cookie: Cookie) {
|
||||
self.cookies.insert(cookie.name.clone(), cookie);
|
||||
}
|
||||
|
||||
|
||||
pub fn add_cookie_name_and_value(&mut self, name: String, value: String) {
|
||||
self.add_cookie(Cookie {
|
||||
name,
|
||||
@@ -33,6 +33,10 @@ impl CookieStore {
|
||||
pub fn remove_cookie(&mut self, name: &str) {
|
||||
self.cookies.remove(name);
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.cookies.len()
|
||||
}
|
||||
|
||||
pub fn clear_all(&mut self) {
|
||||
self.cookies.clear();
|
||||
|
||||
Reference in new issue
Block a user