fix: enhance code content display with syntax highlighting and improve logging structure
This commit is contained in:
@@ -7,7 +7,6 @@ use futures::lock::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::DATA_STORAGE;
|
||||
use crate::logs::{LogEventType, log_event};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
@@ -87,13 +86,13 @@ impl Asset {
|
||||
serde_json::to_value(self).unwrap_or(Value::Null)
|
||||
}
|
||||
|
||||
pub fn save(&self) -> Result<String> {
|
||||
let id = self.id.clone();
|
||||
let path = format!("{}{}", DATA_STORAGE, self.id);
|
||||
std::fs::create_dir_all(DATA_STORAGE)?;
|
||||
std::fs::write(&path, self.to_bytes()?)?;
|
||||
Ok(id)
|
||||
}
|
||||
// pub fn save(&self) -> Result<String> {
|
||||
// let id = self.id.clone();
|
||||
// let path = format!("{}{}", DATA_STORAGE, self.id);
|
||||
// std::fs::create_dir_all(DATA_STORAGE)?;
|
||||
// std::fs::write(&path, self.to_bytes()?)?;
|
||||
// Ok(id)
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -4,7 +4,7 @@ use actix_web::HttpRequest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::LOG_DIR;
|
||||
use crate::{LOG_DIR, LOG_FILE_NAME};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct LogHttpRequest {
|
||||
@@ -68,7 +68,7 @@ impl From<LogEventType> for LogEvent {
|
||||
}
|
||||
|
||||
pub fn log_event(event: LogEventType) {
|
||||
let log_path = LOG_DIR.to_string() + "access.log";
|
||||
let log_path = LOG_DIR.to_string() + LOG_FILE_NAME;
|
||||
|
||||
let Ok(mut file) = OpenOptions::new().create(true).append(true).open(log_path) else {
|
||||
eprintln!("failed to open log file for asset event");
|
||||
|
||||
@@ -13,7 +13,7 @@ use std::{env, fs, path::PathBuf, sync::LazyLock};
|
||||
|
||||
pub static HTML_DIR: &str = "data/html/";
|
||||
pub static LOG_DIR: &str = "data/logs/";
|
||||
pub static DATA_STORAGE: &str = "data/storage/";
|
||||
pub static LOG_FILE_NAME: &str = "log.txt";
|
||||
|
||||
pub static BIND_ADDR: LazyLock<String> = LazyLock::new(|| match env::var("BIND_ADDR") {
|
||||
Ok(addr) => {
|
||||
@@ -88,8 +88,8 @@ async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> acti
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let _ = fs::create_dir_all(DATA_STORAGE);
|
||||
let _ = fs::create_dir_all(LOG_DIR);
|
||||
let _ = fs::remove_file(format!("{}{}", LOG_DIR, LOG_FILE_NAME));
|
||||
|
||||
let assets = data_mgt::AssetTracker::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user