Skip to content

Commit

Permalink
feat(image-processor): add upload info to response
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartkloock committed May 22, 2024
1 parent da414e3 commit 8a57bf8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
15 changes: 13 additions & 2 deletions image-processor/proto/scuffle/image_processor/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ message ProcessImageResponse {
// A unique identifier for the task
string id = 1;

// If the task had an input upload, this will be the path to the uploaded image.
optional DrivePath upload_path = 2;
// If the task had an input upload, this will be the info of the uploaded image.
optional ProcessImageResponseUploadInfo upload_info = 2;

// Errors that occurred when creating the task.
optional Error error = 3;
}

message ProcessImageResponseUploadInfo {
// The path of the uploaded image
DrivePath path = 1;

// The content type of the uploaded image
string content_type = 2;

// The size of the uploaded image in bytes
uint64 size = 3;
}

// The Payload for a ImageProcessor.CancelTask request
message CancelTaskRequest {
// The unique identifier of the task to cancel
Expand Down
2 changes: 1 addition & 1 deletion image-processor/src/management/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl scuffle_image_processor_proto::image_processor_server::ImageProcessor for M
Ok(resp) => resp,
Err(err) => ProcessImageResponse {
id: "".to_owned(),
upload_path: None,
upload_info: None,
error: Some(err),
},
};
Expand Down
2 changes: 1 addition & 1 deletion image-processor/src/management/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn process_image(
Ok(resp) => resp,
Err(err) => ProcessImageResponse {
id: "".to_owned(),
upload_path: None,
upload_info: None,
error: Some(err),
},
};
Expand Down
14 changes: 10 additions & 4 deletions image-processor/src/management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bson::oid::ObjectId;
use bytes::Bytes;
use scuffle_image_processor_proto::{
input, CancelTaskRequest, CancelTaskResponse, DrivePath, Error, ErrorCode, Input, ProcessImageRequest,
ProcessImageResponse,
ProcessImageResponse, ProcessImageResponseUploadInfo,
};

use crate::database::Job;
Expand Down Expand Up @@ -42,7 +42,7 @@ impl ManagementServer {

let id = ObjectId::new();

let upload_path = if let Some(input_upload) = request.input_upload {
let upload_info = if let Some(input_upload) = request.input_upload {
let drive_path = input_upload.drive_path.unwrap();
let drive = self.global.drive(&drive_path.drive).unwrap();

Expand Down Expand Up @@ -79,6 +79,8 @@ impl ManagementServer {
});
}

let upload_size = input_upload.binary.len() as u64;

drive
.write(
&path,
Expand All @@ -99,7 +101,11 @@ impl ManagementServer {
}
})?;

Some(drive_path)
Some(ProcessImageResponseUploadInfo {
path: Some(drive_path),
content_type: file_format.media_type().to_owned(),
size: upload_size,
})
} else {
None
};
Expand All @@ -116,7 +122,7 @@ impl ManagementServer {

Ok(ProcessImageResponse {
id: job.id.to_string(),
upload_path,
upload_info,
error: None,
})
}
Expand Down

0 comments on commit 8a57bf8

Please sign in to comment.