Skip to content

Commit

Permalink
feat: accept borrowed 'static bytes for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
philpax committed Oct 1, 2024
1 parent 1260430 commit 561438f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rucomfyui-node-graph/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ enum TokioOutputEvent {
QueueWorkflowResult(
(
NodeToWorkflowNodeMapping,
HashMap<WorkflowNodeId, Vec<rucomfyui::Bytes>>,
HashMap<WorkflowNodeId, Vec<rucomfyui::OwnedBytes>>,
),
),
Error(TokioOutputError),
Expand Down
4 changes: 2 additions & 2 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use crate::{Bytes, Client, Result};
use crate::{Client, OwnedBytes, Result};

impl Client {
/// Get the history for this ComfyUI instance.
Expand Down Expand Up @@ -77,7 +77,7 @@ impl HistoryImage {
)
}
/// Download the image.
pub async fn download(&self, client: &Client) -> Result<Bytes> {
pub async fn download(&self, client: &Client) -> Result<OwnedBytes> {
Ok(client
.client
.get(self.url(client))
Expand Down
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ pub enum ClientError {
pub type Result<T> = std::result::Result<T, ClientError>;

/// An alias around `Vec<u8>` for raw bytes.
pub type Bytes = Vec<u8>;
pub type OwnedBytes = Vec<u8>;

/// An alias around `Cow<'a, [u8]>` for borrowed bytes.
pub type BorrowedBytes<'a> = std::borrow::Cow<'a, [u8]>;

/// Client for the ComfyUI API.
pub struct Client {
Expand All @@ -46,7 +49,11 @@ impl Client {
}
impl Client {
/// Upload a file to the ComfyUI API.
pub async fn upload(&self, filename: &str, bytes: Bytes) -> Result<serde_json::Value> {
pub async fn upload(
&self,
filename: &str,
bytes: impl Into<BorrowedBytes<'static>>,
) -> Result<serde_json::Value> {
let form = Form::new()
.part("image", Part::bytes(bytes).file_name(filename.to_string()))
.text("type", "input")
Expand Down
4 changes: 2 additions & 2 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::{workflow::WorkflowNodeId, Bytes, Client, Result, Workflow};
use crate::{workflow::WorkflowNodeId, Client, OwnedBytes, Result, Workflow};

impl Client {
/// Send a workflow to the ComfyUI API.
Expand All @@ -26,7 +26,7 @@ impl Client {
pub async fn easy_queue(
&self,
workflow: &Workflow,
) -> Result<HashMap<WorkflowNodeId, Vec<Bytes>>> {
) -> Result<HashMap<WorkflowNodeId, Vec<OwnedBytes>>> {
let output = self.queue(workflow).await?;

// Poll for output
Expand Down

0 comments on commit 561438f

Please sign in to comment.