Refactor asset and logging directory creation for improved clarity
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
use std::fs;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -52,7 +50,6 @@ impl Asset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(&self) -> Result<String> {
|
pub fn save(&self) -> Result<String> {
|
||||||
let _ = fs::create_dir_all(DATA_STORAGE);
|
|
||||||
let id = self.id.clone();
|
let id = self.id.clone();
|
||||||
let path = format!("{}{}", DATA_STORAGE, self.id);
|
let path = format!("{}{}", DATA_STORAGE, self.id);
|
||||||
std::fs::create_dir_all(DATA_STORAGE)?;
|
std::fs::create_dir_all(DATA_STORAGE)?;
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
use std::{
|
use std::{fs::OpenOptions, io::Write, time::Instant};
|
||||||
fs::{self, OpenOptions},
|
|
||||||
io::Write,
|
|
||||||
time::Instant,
|
|
||||||
};
|
|
||||||
|
|
||||||
use actix_web::HttpRequest;
|
use actix_web::HttpRequest;
|
||||||
|
|
||||||
@@ -12,7 +8,6 @@ pub fn log_to_file(req: &HttpRequest, start: Instant) {
|
|||||||
let delta = start.elapsed().as_nanos();
|
let delta = start.elapsed().as_nanos();
|
||||||
println!("Request processed in {} ns", delta);
|
println!("Request processed in {} ns", delta);
|
||||||
let duration_ms = delta as f64 / 1000_000.0;
|
let duration_ms = delta as f64 / 1000_000.0;
|
||||||
let _ = fs::create_dir_all(LOG_DIR);
|
|
||||||
|
|
||||||
let log_path = LOG_DIR.to_string() + "access.log";
|
let log_path = LOG_DIR.to_string() + "access.log";
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use actix_web::{
|
|||||||
web::{self},
|
web::{self},
|
||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::path::PathBuf;
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
pub static BIND_ADDR: &str = "0.0.0.0";
|
pub static BIND_ADDR: &str = "0.0.0.0";
|
||||||
pub static BIND_PORT: u16 = 80;
|
pub static BIND_PORT: u16 = 80;
|
||||||
@@ -56,6 +56,9 @@ async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> acti
|
|||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let _ = fs::create_dir_all(DATA_STORAGE);
|
||||||
|
let _ = fs::create_dir_all(LOG_DIR);
|
||||||
|
|
||||||
println!("Starting server at http://{}:{}/", BIND_ADDR, BIND_PORT);
|
println!("Starting server at http://{}:{}/", BIND_ADDR, BIND_PORT);
|
||||||
tokio::spawn(async {
|
tokio::spawn(async {
|
||||||
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(60));
|
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(60));
|
||||||
|
|||||||
Reference in New Issue
Block a user