add X-Task-Id for upload
This commit is contained in:
parent
5219908242
commit
7e8cffa07f
@ -21,7 +21,7 @@ curl --location 'http://localhost:8090/enqueue' \
|
||||
--form 'channelLayout="mono"' \
|
||||
--form 'uploadUrl="http://127.0.0.1:8909/upload"'
|
||||
```
|
||||
3. Your `uploadUrl` will receive JSON response with job ID and error in case of failure and the entire transcoded file contents in case of success. Use `Content-Type` header to differentiate between the two data types.
|
||||
3. Your `uploadUrl` will receive JSON response with job ID and error in case of failure and the entire transcoded file contents in case of success (success request will have `X-Task-Id` header with task ID). Use `Content-Type` header to differentiate between the two data types.
|
||||
|
||||
You can change configuration using this environment variables:
|
||||
- `LISTEN` - change this environment variable to change TCP listen address. Default is `0.0.0.0:8090`.
|
||||
|
@ -2,11 +2,6 @@ use axum_typed_multipart::{FieldData, TryFromMultipart};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Error {
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct ConvertResponse {
|
||||
pub id: Option<String>,
|
||||
|
@ -166,4 +166,4 @@ async fn cleanup_directory(dir_path: &str) -> Result<(), Box<dyn std::error::Err
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,11 @@ impl Task {
|
||||
|
||||
std::fs::remove_file(Path::new(&self.params.input_path)).ok();
|
||||
|
||||
if let Err(err) = upload_file(&self.params.output_path, &self.params.upload_url) {
|
||||
if let Err(err) = upload_file(
|
||||
&self.id.to_string(),
|
||||
&self.params.output_path,
|
||||
&self.params.upload_url,
|
||||
) {
|
||||
error!(
|
||||
"couldn't upload result for job id={}, file path {}: {}",
|
||||
&self.id.to_string(),
|
||||
@ -211,6 +215,7 @@ fn send_error(
|
||||
}
|
||||
|
||||
fn upload_file<P: AsRef<Path>>(
|
||||
id: &str,
|
||||
file_path: P,
|
||||
url: &str,
|
||||
) -> Result<Response, Box<dyn std::error::Error>> {
|
||||
@ -233,6 +238,7 @@ fn upload_file<P: AsRef<Path>>(
|
||||
"Content-Disposition",
|
||||
&format!("attachment; filename=\"{}\"", file_name),
|
||||
)
|
||||
.set("X-Task-Id", id)
|
||||
.send_bytes(&buffer)?;
|
||||
|
||||
if response.status() == 200 {
|
||||
|
@ -240,7 +240,7 @@ fn filter_graph(
|
||||
};
|
||||
filter.add(&abuffersink_filter, "out", "")?;
|
||||
|
||||
let mut out = match filter.get("out") {
|
||||
let mut out = match filter.get("out") {
|
||||
Some(filter) => filter,
|
||||
None => return Err(ffmpeg::Error::Unknown),
|
||||
};
|
||||
@ -257,9 +257,7 @@ fn filter_graph(
|
||||
.contains(codec::capabilities::Capabilities::VARIABLE_FRAME_SIZE)
|
||||
{
|
||||
if let Some(mut out_filter) = filter.get("out") {
|
||||
out_filter
|
||||
.sink()
|
||||
.set_frame_size(encoder.frame_size());
|
||||
out_filter.sink().set_frame_size(encoder.frame_size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user