Bad attempt at streaming a tar.gz file
This commit is contained in:
parent
9a2e364101
commit
828ee6c533
4 changed files with 129 additions and 7 deletions
35
src/main.rs
35
src/main.rs
|
|
@ -1,6 +1,14 @@
|
|||
use axum::{http::StatusCode, routing::get_service, Router};
|
||||
use async_compression::tokio::bufread::GzipDecoder;
|
||||
use axum::{
|
||||
extract::BodyStream,
|
||||
http::StatusCode,
|
||||
routing::{get_service, post},
|
||||
Router,
|
||||
};
|
||||
use hyper::{Body, Request};
|
||||
use std::net::SocketAddr;
|
||||
use tower_http::{services::ServeDir, trace::TraceLayer};
|
||||
use tar::Archive;
|
||||
use tower_http::{auth::RequireAuthorizationLayer, services::ServeDir, trace::TraceLayer};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -14,10 +22,20 @@ async fn main() {
|
|||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
// Get required variables from env vars
|
||||
let api_key = std::env::var("API_KEY").expect("No API_KEY was provided.");
|
||||
let data_dir = std::env::var("DATA_DIR").expect("No DATA_DIR was provided.");
|
||||
|
||||
std::fs::create_dir_all(&data_dir).unwrap();
|
||||
|
||||
let app = Router::new()
|
||||
.nest(
|
||||
"/",
|
||||
get_service(ServeDir::new("./static")).handle_error(
|
||||
.route(
|
||||
"/api/deploy",
|
||||
post(post_deploy).layer(RequireAuthorizationLayer::bearer(&api_key)),
|
||||
)
|
||||
// The fallback option is to serve the actual static files
|
||||
.fallback(
|
||||
get_service(ServeDir::new(format!("{}/static", data_dir))).handle_error(
|
||||
|error: std::io::Error| async move {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
|
|
@ -35,3 +53,10 @@ async fn main() {
|
|||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
async fn post_deploy(body: BodyStream) {
|
||||
// let tar = GzDecoder::new(body);
|
||||
let tar = GzipDecoder::new(body);
|
||||
let mut archive = Archive::new(tar);
|
||||
archive.unpack("./static").unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue