mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-14 13:52:11 +00:00
command to load media files
This commit is contained in:
1 parent
feeae20735
commit
0556506b03
4 files changed
+58
-37
No files matched your search
@@ -25,7 +25,11 @@ use tokens::tokens::model_weights::ModelWeightToken;
|
||||
use tokens::tokens::prompts::PromptToken;
|
||||
|
||||
/// Get details about a media file from our backend
|
||||
pub async fn get_media_file(api_host: &ApiHost, media_file_token: &MediaFileToken) -> Result<GetMediaFileSuccessResponse, StorytellerError> {
|
||||
pub async fn get_media_file(
|
||||
api_host: &ApiHost,
|
||||
media_file_token: &MediaFileToken
|
||||
) -> Result<GetMediaFileSuccessResponse, StorytellerError> {
|
||||
|
||||
let url = get_media_file_token_route(api_host, media_file_token);
|
||||
|
||||
debug!("Requesting {:?}", &url);
|
||||
@@ -47,8 +51,6 @@ fn get_media_file_token_route(api_host: &ApiHost, media_file_token: &MediaFileTo
|
||||
format!("{}/v1/media_files/file/{}", api_hostname_and_scheme, media_file_token)
|
||||
}
|
||||
|
||||
// TODO(bt,2025-04-22): Share API definitions between client and server in common crate.
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
@@ -1,54 +1,70 @@
|
||||
use crate::core::commands::response::shorthand::InfallibleResponse;
|
||||
use crate::core::commands::enqueue::image_inpaint::enqueue_image_inpaint_command::EnqueueImageInpaintSuccessResponse;
|
||||
use crate::core::commands::response::shorthand::{InfallibleResponse, ResponseOrErrorType};
|
||||
use crate::core::commands::response::success_response_wrapper::SerializeMarker;
|
||||
use crate::core::model::image_models::ImageModel;
|
||||
use crate::core::state::app_env_configs::app_env_configs::AppEnvConfigs;
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::info;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use tauri::{AppHandle, State};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use crate::core::state::data_dir::app_data_root::AppDataRoot;
|
||||
use crate::services::storyteller::state::storyteller_credential_manager::StorytellerCredentialManager;
|
||||
use artcraft_api_defs::media_files::get_media_file::MediaFileInfo;
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::{error, info};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use storyteller_client::generate::image::edit::gpt_image_1_edit_image::gpt_image_1_edit_image;
|
||||
use storyteller_client::media_files::get_media_file::get_media_file;
|
||||
use tauri::{AppHandle, State};
|
||||
use tokens::tokens::media_files::MediaFileToken;
|
||||
use crate::core::commands::response::failure_response_wrapper::{CommandErrorResponseWrapper, CommandErrorStatus};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GetMediaFileRequest {
|
||||
pub token: MediaFileToken,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct AppInfoResponse {
|
||||
pub build_timestamp: DateTime<Utc>,
|
||||
pub git_commit_id: Option<String>,
|
||||
pub git_commit_short_id: Option<String>,
|
||||
pub git_commit_timestamp: Option<DateTime<Utc>>,
|
||||
pub storyteller_host: String,
|
||||
#[derive(Serialize, Debug)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GetMediaFileErrorType {
|
||||
NotFound,
|
||||
NotAuthorized,
|
||||
ServerError,
|
||||
}
|
||||
|
||||
impl SerializeMarker for AppInfoResponse {}
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct GetMediaFileResponse {
|
||||
pub success: bool,
|
||||
pub media_file: MediaFileInfo,
|
||||
}
|
||||
|
||||
impl SerializeMarker for GetMediaFileResponse {}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_media_file_command(
|
||||
pub async fn get_media_file_command(
|
||||
request: GetMediaFileRequest,
|
||||
app: AppHandle,
|
||||
app_data_root: State<'_, AppDataRoot>,
|
||||
app_env_configs: State<'_, AppEnvConfigs>,
|
||||
storyteller_creds_manager: State<'_, StorytellerCredentialManager>,
|
||||
) -> InfallibleResponse<AppInfoResponse> {
|
||||
) -> ResponseOrErrorType<GetMediaFileResponse, GetMediaFileErrorType > {
|
||||
info!("get_media_file_command called...");
|
||||
|
||||
let build_timestamp = build_metadata::build_timestamp();
|
||||
let git_commit_id = build_metadata::git_commit_id();
|
||||
let git_commit_short_id = build_metadata::git_commit_short_id();
|
||||
let git_commit_timestamp = build_metadata::git_commit_timestamp();
|
||||
let result = get_media_file(
|
||||
&app_env_configs.storyteller_host,
|
||||
//Some(&creds),
|
||||
&request.token,
|
||||
).await;
|
||||
|
||||
let storyteller_host = app_env_configs.storyteller_host.to_api_hostname_and_scheme();
|
||||
let result = match result {
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
error!("Failed to get media file: {:?}", err);
|
||||
return Err(CommandErrorResponseWrapper {
|
||||
status: CommandErrorStatus::ServerError,
|
||||
error_message: None,
|
||||
error_type: Some(GetMediaFileErrorType::ServerError),
|
||||
error_details: None,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
AppInfoResponse {
|
||||
build_timestamp,
|
||||
git_commit_id: git_commit_id.map(|s| s.to_string()),
|
||||
git_commit_short_id: git_commit_short_id.map(|s| s.to_string()),
|
||||
git_commit_timestamp,
|
||||
storyteller_host,
|
||||
}.into()
|
||||
Ok(GetMediaFileResponse {
|
||||
success: true,
|
||||
media_file: result.media_file
|
||||
}.into())
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
pub mod core;
|
||||
pub mod services;
|
||||
|
||||
use log::error;
|
||||
use tauri::Manager;
|
||||
|
||||
use crate::core::commands::app_preferences::get_app_preferences_command::get_app_preferences_command;
|
||||
use crate::core::commands::app_preferences::update_app_preference_command::update_app_preferences_command;
|
||||
use crate::core::commands::enqueue::image::enqueue_text_to_image_command::enqueue_text_to_image_command;
|
||||
use crate::core::commands::enqueue::image_bg_removal::enqueue_image_bg_removal_command::enqueue_image_bg_removal_command;
|
||||
use crate::core::commands::enqueue::image_inpaint::enqueue_image_inpaint_command::enqueue_image_inpaint_command;
|
||||
use crate::core::commands::enqueue::image_edit::enqueue_contextual_edit_image_command::enqueue_contextual_edit_image_command;
|
||||
use crate::core::commands::enqueue::image_inpaint::enqueue_image_inpaint_command::enqueue_image_inpaint_command;
|
||||
use crate::core::commands::enqueue::object::enqueue_image_to_3d_object_command::enqueue_image_to_3d_object_command;
|
||||
use crate::core::commands::enqueue::video::enqueue_image_to_video_command::enqueue_image_to_video_command;
|
||||
use crate::core::commands::flip_image::flip_image;
|
||||
use crate::core::commands::get_app_info_command::get_app_info_command;
|
||||
use crate::core::commands::load_without_cors_command::load_without_cors_command;
|
||||
use crate::core::commands::media_files::get_media_file_command::get_media_file_command;
|
||||
use crate::core::commands::platform_info_command::platform_info_command;
|
||||
use crate::core::commands::providers::get_provider_order_command::get_provider_order_command;
|
||||
use crate::core::commands::providers::set_provider_order_command::set_provider_order_command;
|
||||
@@ -41,7 +43,6 @@ use crate::services::sora::state::sora_credential_manager::SoraCredentialManager
|
||||
use crate::services::sora::state::sora_task_queue::SoraTaskQueue;
|
||||
use crate::services::sora::threads::sora_task_polling_thread::sora_task_polling_thread;
|
||||
use crate::services::storyteller::state::storyteller_credential_manager::StorytellerCredentialManager;
|
||||
use log::error;
|
||||
|
||||
use tauri_plugin_dialog;
|
||||
use tauri_plugin_http;
|
||||
@@ -156,6 +157,7 @@ pub fn run() {
|
||||
get_app_info_command,
|
||||
get_app_preferences_command,
|
||||
get_fal_api_key_command,
|
||||
get_media_file_command,
|
||||
get_provider_order_command,
|
||||
load_without_cors_command,
|
||||
open_sora_login_command,
|
||||
|
||||
@@ -17,6 +17,7 @@ use crate::core::utils::simple_http_download_to_tempfile::simple_http_download_t
|
||||
use crate::services::fal::state::fal_credential_manager::FalCredentialManager;
|
||||
use crate::services::storyteller::state::storyteller_credential_manager::StorytellerCredentialManager;
|
||||
use anyhow::anyhow;
|
||||
use artcraft_api_defs::media_files::get_media_file::GetMediaFileSuccessResponse;
|
||||
use base64::prelude::BASE64_STANDARD;
|
||||
use base64::{DecodeError, Engine};
|
||||
use errors::AnyhowError;
|
||||
@@ -28,7 +29,7 @@ use log::{error, info, warn};
|
||||
use reqwest::Url;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use storyteller_client::error::storyteller_error::StorytellerError;
|
||||
use storyteller_client::media_files::get_media_file::{get_media_file, GetMediaFileSuccessResponse};
|
||||
use storyteller_client::media_files::get_media_file::get_media_file;
|
||||
use storyteller_client::media_files::upload_image_media_file_from_file::{upload_image_media_file_from_file, UploadImageFromFileArgs};
|
||||
use storyteller_client::utils::api_host::ApiHost;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
|
||||
Reference in new issue
Block a user