This commit is contained in:
Brandon Thomas committed 2025-08-15 01:38:02 -04:00
1 parent ed674fc045
commit 3a0018f49a
4 files changed
+29 -10

No files matched your search

@@ -30,7 +30,6 @@ pub async fn submit_job(req: SubmitJobRequest<'_>) -> Result<SubmitJobResponse,
let referer = format!("https://{}", req.hostname.as_str());
// NB: Other recent clients use /api/app/submit-jobs, but this appears invalid.
// 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();
@@ -177,15 +176,16 @@ mod tests {
use filesys::read_to_trimmed_string::read_to_trimmed_string;
// Get channel id via:
// https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=AIzaSyAjizp68NsH3JGUS0EyLXsChW4fN0A92tM
// https://identitytoolkit.googleapis.com/v1/accounts:lookup?key=[TOKEN]
#[ignore]
#[tokio::test]
async fn test() -> AnyhowResult<()> {
let cookie_header = read_to_trimmed_string("/Users/bt/secrets/midjourney/cookie.txt")?;
let channel_id = read_to_trimmed_string("/Users/bt/secrets/midjourney/channel_id.txt")?;
let result = submit_job(SubmitJobRequest {
prompt: "photorealistic, high definition, a submarine falling out of the sky and onto manhattan, busy city, sunset, cloudy and overcast, giant military submarine, upside down submarine, falling at angle, drone shot, submarine is in pieces, cracked machinery, exposed steel, giant skyscrapers below, tall buildings, city streets, cars on streets",
channel_id: "singleplayer_f8a57ac3-e416-4dd4-9be8-2c4223691b01",
prompt: "a modern n64 console",
channel_id: &channel_id,
cookie_header,
hostname: MidjourneyHostname::Standard,
}).await?;
@@ -0,0 +1,20 @@
use crate::credentials::midjourney_user_id::MidjourneyUserId;
#[derive(Debug, Clone)]
pub enum ChannelId {
/// Channel based on the user ID.
/// This is what Midjourney uses by default.
UserId(MidjourneyUserId),
// Bare string ID
Raw(String),
}
impl ChannelId {
pub fn to_string(&self) -> String {
match self {
Self::UserId(user_id) => format!("singleplayer_{}", user_id.0),
Self::Raw(id) => id.clone(),
}
}
}
@@ -10,29 +10,27 @@ pub struct GetMidjourneyUserIdRequest {
}
pub async fn get_midjourney_user_id(req: GetMidjourneyUserIdRequest) -> Result<MidjourneyUserId, MidjourneyError> {
let items = storage_list(GetStorageListRequest {
hostname: req.hostname,
cookie_header: req.cookie_header,
}).await?;
let user_id = items
.into_iter()
.find_map(|item| item.bucket_pathname)
.and_then(|path| path.split('/').next().map(|id| id.to_owned()))
.map(|id| MidjourneyUserId(id.to_string()))
.ok_or(MidjourneyApiError::NoUserId)?;
Ok(user_id)
}
#[cfg(test)]
mod tests {
use crate::client::midjourney_hostname::MidjourneyHostname;
use crate::recipes::get_midjourney_user_id::{get_midjourney_user_id, GetMidjourneyUserIdRequest};
use errors::AnyhowResult;
use filesys::read_to_trimmed_string::read_to_trimmed_string;
use crate::endpoints::storage_list::{storage_list, GetStorageListRequest};
use crate::recipes::get_midjourney_user_id::{get_midjourney_user_id, GetMidjourneyUserIdRequest};
#[ignore]
#[tokio::test]
@@ -1 +1,2 @@
mod get_midjourney_user_id;
mod get_midjourney_user_id;
mod channel_id;