fix: Create archives dir if it does not exist

This commit is contained in:
Ashhhleyyy 2022-07-05 10:53:02 +01:00
parent 9d2f753620
commit f42924cd3b
Signed by: ash
GPG key ID: 83B789081A0878FB
2 changed files with 7 additions and 2 deletions

View file

@ -27,6 +27,11 @@ async fn main() -> Result<()> {
fs::create_dir_all(tempdir)?;
}
let archive_dir = Path::new("project-archives");
if !archive_dir.exists() {
fs::create_dir_all(archive_dir)?;
}
let app = routes::router()
.layer(Extension(AuthToken(upload_token)));

View file

@ -15,7 +15,7 @@ pub fn router() -> Router {
}
async fn get_asset(Path((project, filename)): Path<(String, String)>) -> Result<(HeaderMap, Vec<u8>), StatusCode> {
let path = path::Path::new("project_archives")
let path = path::Path::new("project-archives")
.join(format!("{project}.zip"));
if path.exists() {
let data = {
@ -69,7 +69,7 @@ fn find_asset(mut zip: ZipArchive<impl std::io::Read + std::io::Seek>, filename:
async fn upload_project(mut multipart: Multipart, _auth: Authed, Path(project): Path<String>) -> Result<(), StatusCode> {
while let Some(field) = multipart.next_field().await.map_err(|_| StatusCode::BAD_REQUEST)? {
let path = path::Path::new("project_archives")
let path = path::Path::new("project-archives")
.join(format!("{project}.zip"));
return if let Err(e) = stream_to_file(path, field).await {
tracing::error!(%e, "failed to upload project archive");