Implement check upload status endpoint

This commit is contained in:
SeanOMik 2023-04-18 01:16:29 -04:00
parent 3d70301c54
commit 5431c2d9d3
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
2 changed files with 26 additions and 5 deletions

View File

@ -1,4 +1,4 @@
use actix_web::{HttpResponse, HttpRequest, post, web, patch, put, delete};
use actix_web::{HttpResponse, HttpRequest, post, web, patch, put, delete, get};
use bytes::{BytesMut, Bytes, BufMut};
use qstring::QString;
use tracing::{debug};
@ -84,8 +84,6 @@ pub async fn finish_chunked_upload(body: Bytes, path: web::Path<(String, String)
database.replace_digest(&layer_uuid, &digest).await.unwrap();
//let first_digest = digest.first().unwrap().to_owned();
HttpResponse::Created()
.insert_header(("Location", format!("/v2/{}/blobs/{}", name, digest)))
.insert_header(("Content-Length", 0))
@ -103,4 +101,25 @@ pub async fn cancel_upload(path: web::Path<(String, String)>, state: web::Data<A
// I'm not sure what this response should be, its not specified in the registry spec.
HttpResponse::Ok()
.finish()
}
#[get("/{uuid}")]
pub async fn check_upload_status(path: web::Path<(String, String)>, state: web::Data<AppState>) -> HttpResponse {
let (name, layer_uuid) = (path.0.to_owned(), path.1.to_owned());
let database = &state.database;
let ending = match database.get_digest(&layer_uuid).await.unwrap() {
Some(current_bytes) => {
current_bytes.len()
},
None => {
0
}
};
HttpResponse::Created()
.insert_header(("Location", format!("/v2/{}/blobs/uploads/{}", name, layer_uuid)))
.insert_header(("Range", format!("0-{}", ending)))
.insert_header(("Docker-Upload-Digest", layer_uuid))
.finish()
}

View File

@ -15,7 +15,7 @@ use database::Database;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let pool = SqlitePoolOptions::new()
.max_connections(5)
.max_connections(15)
.connect("test.db").await.unwrap();
pool.create_schema().await.unwrap();
@ -28,7 +28,8 @@ async fn main() -> std::io::Result<()> {
.with_max_level(Level::DEBUG)
.init();
let payload_config = web::PayloadConfig::new(31_460_000); // 30mb
// TODO: Make configurable by deployment
let payload_config = web::PayloadConfig::new(5 * 1024 * 1024 * 1024); // 5Gb
debug!("Starting http server...");
@ -68,6 +69,7 @@ async fn main() -> std::io::Result<()> {
.service(api::uploads::chunked_upload_layer)
.service(api::uploads::finish_chunked_upload)
.service(api::uploads::cancel_upload)
.service(api::uploads::check_upload_status)
// TODO: Cross Repository Blob Mount
)
)