Compare commits
1 Commits
67b210a7bf
...
5a0a897461
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a0a897461 |
@@ -1,4 +1,4 @@
|
||||
FROM rust:1.94-bookworm AS base
|
||||
FROM rust:1.91-bookworm AS base
|
||||
|
||||
#
|
||||
# MARK: Build
|
||||
@@ -18,7 +18,7 @@ RUN cargo test --release --workspace
|
||||
#
|
||||
# MARK: Release
|
||||
#
|
||||
FROM debian:bookworm AS deploy
|
||||
FROM debian:bookworm@sha256:00cd074b40c4d99ff0c24540bdde0533ca3791edcdac0de36d6b9fb3260d89e2 AS deploy
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ pub struct ExtractQuery {
|
||||
|
||||
#[serde(default)]
|
||||
download: bool,
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
/// Extract a specific field from an item's metadata.
|
||||
@@ -32,7 +31,6 @@ pub struct ExtractQuery {
|
||||
("source" = String, Query, description = "Source label"),
|
||||
("key" = String, Query, description = "Item key"),
|
||||
("path" = String, Query, description = "Object path (e.g. $.flac.title); repeat for fallbacks"),
|
||||
("name" = Option<String>, Query, description = "Downloaded filename; defaults to the last segment of the key"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Field value as JSON"),
|
||||
@@ -114,27 +112,18 @@ pub async fn get_extract(
|
||||
time_ms = start.elapsed().as_millis()
|
||||
);
|
||||
|
||||
let disposition_type = if params.download {
|
||||
let disposition = if params.download {
|
||||
"attachment"
|
||||
} else {
|
||||
"inline"
|
||||
};
|
||||
let file_name = params.name.unwrap_or_else(|| {
|
||||
params
|
||||
.key
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or(¶ms.key)
|
||||
.to_owned()
|
||||
});
|
||||
let disposition = format!("{disposition_type}; filename=\"{file_name}\"");
|
||||
|
||||
match value {
|
||||
PileValue::String(s) => (
|
||||
StatusCode::OK,
|
||||
[
|
||||
(header::CONTENT_TYPE, "text/plain".to_owned()),
|
||||
(header::CONTENT_DISPOSITION, disposition),
|
||||
(header::CONTENT_DISPOSITION, disposition.to_owned()),
|
||||
],
|
||||
s.to_string(),
|
||||
)
|
||||
@@ -143,7 +132,7 @@ pub async fn get_extract(
|
||||
StatusCode::OK,
|
||||
[
|
||||
(header::CONTENT_TYPE, mime.to_string()),
|
||||
(header::CONTENT_DISPOSITION, disposition),
|
||||
(header::CONTENT_DISPOSITION, disposition.to_owned()),
|
||||
],
|
||||
bytes.as_ref().clone(),
|
||||
)
|
||||
@@ -151,7 +140,7 @@ pub async fn get_extract(
|
||||
_ => match value.to_json(&extract_state).await {
|
||||
Ok(json) => (
|
||||
StatusCode::OK,
|
||||
[(header::CONTENT_DISPOSITION, disposition)],
|
||||
[(header::CONTENT_DISPOSITION, disposition.to_owned())],
|
||||
Json(json),
|
||||
)
|
||||
.into_response(),
|
||||
|
||||
@@ -21,7 +21,6 @@ pub struct FieldQuery {
|
||||
|
||||
#[serde(default)]
|
||||
download: bool,
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
/// Extract a specific field from an item's metadata.
|
||||
@@ -32,7 +31,6 @@ pub struct FieldQuery {
|
||||
("source" = String, Query, description = "Source label"),
|
||||
("key" = String, Query, description = "Item key"),
|
||||
("field" = String, Query, description = "Schema field"),
|
||||
("name" = Option<String>, Query, description = "Downloaded filename; defaults to the last segment of the key"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Field value as JSON"),
|
||||
@@ -100,27 +98,18 @@ pub async fn get_field(
|
||||
time_ms = start.elapsed().as_millis()
|
||||
);
|
||||
|
||||
let disposition_type = if params.download {
|
||||
let disposition = if params.download {
|
||||
"attachment"
|
||||
} else {
|
||||
"inline"
|
||||
};
|
||||
let file_name = params.name.unwrap_or_else(|| {
|
||||
params
|
||||
.key
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or(¶ms.key)
|
||||
.to_owned()
|
||||
});
|
||||
let disposition = format!("{disposition_type}; filename=\"{file_name}\"");
|
||||
|
||||
match value {
|
||||
PileValue::String(s) => (
|
||||
StatusCode::OK,
|
||||
[
|
||||
(header::CONTENT_TYPE, "text/plain".to_owned()),
|
||||
(header::CONTENT_DISPOSITION, disposition),
|
||||
(header::CONTENT_DISPOSITION, disposition.to_owned()),
|
||||
],
|
||||
s.to_string(),
|
||||
)
|
||||
@@ -129,7 +118,7 @@ pub async fn get_field(
|
||||
StatusCode::OK,
|
||||
[
|
||||
(header::CONTENT_TYPE, mime.to_string()),
|
||||
(header::CONTENT_DISPOSITION, disposition),
|
||||
(header::CONTENT_DISPOSITION, disposition.to_owned()),
|
||||
],
|
||||
bytes.as_ref().clone(),
|
||||
)
|
||||
@@ -137,7 +126,7 @@ pub async fn get_field(
|
||||
_ => match value.to_json(&extract_state).await {
|
||||
Ok(json) => (
|
||||
StatusCode::OK,
|
||||
[(header::CONTENT_DISPOSITION, disposition)],
|
||||
[(header::CONTENT_DISPOSITION, disposition.to_owned())],
|
||||
Json(json),
|
||||
)
|
||||
.into_response(),
|
||||
|
||||
@@ -19,10 +19,8 @@ use crate::Datasets;
|
||||
pub struct ItemQuery {
|
||||
source: String,
|
||||
key: String,
|
||||
|
||||
#[serde(default)]
|
||||
download: bool,
|
||||
name: Option<String>,
|
||||
}
|
||||
|
||||
/// Parse a `Range: bytes=...` header value.
|
||||
@@ -50,7 +48,6 @@ fn parse_byte_range(s: &str) -> Option<(Option<u64>, Option<u64>)> {
|
||||
params(
|
||||
("source" = String, Query, description = "Source label"),
|
||||
("key" = String, Query, description = "Item key"),
|
||||
("name" = Option<String>, Query, description = "Downloaded filename; defaults to the last segment of the key"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Raw item bytes"),
|
||||
@@ -166,20 +163,11 @@ pub async fn item_get(
|
||||
StatusCode::OK
|
||||
};
|
||||
|
||||
let disposition_type = if params.download {
|
||||
let disposition = if params.download {
|
||||
"attachment"
|
||||
} else {
|
||||
"inline"
|
||||
};
|
||||
let file_name = params.name.unwrap_or_else(|| {
|
||||
params
|
||||
.key
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or(¶ms.key)
|
||||
.to_owned()
|
||||
});
|
||||
let disposition = format!("{disposition_type}; filename=\"{file_name}\"");
|
||||
|
||||
let mut builder = axum::http::Response::builder()
|
||||
.status(status)
|
||||
|
||||
Reference in New Issue
Block a user