fix: enhance logging structure by adding missing log event types and improving error handling in API
This commit is contained in:
@@ -78,6 +78,37 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
echo "pkg_name=$PKG_NAME" >> "$GITHUB_OUTPUT"
|
echo "pkg_name=$PKG_NAME" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Compute versions
|
||||||
|
id: version_meta
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
CARGO_VER="$(python3 - << 'PY'
|
||||||
|
import re
|
||||||
|
txt = open("Cargo.toml", "r", encoding="utf-8").read()
|
||||||
|
m = re.search(r'(?m)^\s*version\s*=\s*"([^"]+)"\s*$', txt)
|
||||||
|
print(m.group(1) if m else "")
|
||||||
|
PY
|
||||||
|
)"
|
||||||
|
if [ -z "$CARGO_VER" ]; then
|
||||||
|
echo "Could not read version from Cargo.toml"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
REF="${GITHUB_REF_NAME:-}"
|
||||||
|
SHA="${GITHUB_SHA:-}"
|
||||||
|
SHORT_SHA="${SHA:0:8}"
|
||||||
|
|
||||||
|
if [[ "$REF" == v* ]]; then
|
||||||
|
PKG_VERSION="${REF#v}"
|
||||||
|
else
|
||||||
|
PKG_VERSION="${CARGO_VER}+g${SHORT_SHA}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "cargo_version=$CARGO_VER" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "pkg_version=$PKG_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Create source tarball (code)
|
- name: Create source tarball (code)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -89,8 +120,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
OWNER="${FULL%%/*}"
|
OWNER="${FULL%%/*}"
|
||||||
REPO="${FULL##*/}"
|
REPO="${FULL##*/}"
|
||||||
VERSION="${GITHUB_REF_NAME#v}"
|
PKG_VERSION="${{ steps.version_meta.outputs.pkg_version }}"
|
||||||
PKG_VERSION="${VERSION}"
|
|
||||||
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@@ -119,8 +149,7 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
REPO="${FULL##*/}"
|
REPO="${FULL##*/}"
|
||||||
VERSION="${GITHUB_REF_NAME#v}"
|
PKG_VERSION="${{ steps.version_meta.outputs.pkg_version }}"
|
||||||
PKG_VERSION="${VERSION}"
|
|
||||||
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
@@ -143,8 +172,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
OWNER="${FULL%%/*}"
|
OWNER="${FULL%%/*}"
|
||||||
REPO="${FULL##*/}"
|
REPO="${FULL##*/}"
|
||||||
VERSION="${GITHUB_REF_NAME#v}"
|
PKG_VERSION="${{ steps.version_meta.outputs.pkg_version }}"
|
||||||
PKG_VERSION="${VERSION}"
|
|
||||||
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}"
|
||||||
|
|
||||||
if [ -z "${BASE_URL:-}" ]; then
|
if [ -z "${BASE_URL:-}" ]; then
|
||||||
|
|||||||
44
src/api.rs
44
src/api.rs
@@ -6,7 +6,7 @@ use serde_json::json;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data_mgt::AssetTracker,
|
data_mgt::AssetTracker,
|
||||||
logs::{LogEventType, log_event},
|
logs::{LogEventBody, LogEventLine, LogEventType, log_event},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -24,10 +24,12 @@ async fn api_upload(
|
|||||||
) -> Result<HttpResponse, actix_web::Error> {
|
) -> Result<HttpResponse, actix_web::Error> {
|
||||||
// Convert to bytes
|
// Convert to bytes
|
||||||
let content_bytes = if body.content_type == "text/plain" {
|
let content_bytes = if body.content_type == "text/plain" {
|
||||||
body.content.as_bytes().to_vec() // UTF-8 bytes
|
body.content.as_bytes().to_vec()
|
||||||
} else {
|
} else {
|
||||||
// Decode base64 → bytes
|
match general_purpose::STANDARD.decode(&body.content) {
|
||||||
general_purpose::STANDARD.decode(&body.content).unwrap()
|
Ok(bytes) => bytes,
|
||||||
|
Err(_) => return Ok(HttpResponse::BadRequest().body("Invalid base64 payload")),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let connection_info = req.connection_info();
|
let connection_info = req.connection_info();
|
||||||
let uploader_ip = connection_info
|
let uploader_ip = connection_info
|
||||||
@@ -86,40 +88,6 @@ struct ActivityItem {
|
|||||||
timestamp: String,
|
timestamp: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct LogEventLine {
|
|
||||||
time: String,
|
|
||||||
event: LogEventBody,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
enum LogEventBody {
|
|
||||||
AssetUploaded(LogAsset),
|
|
||||||
AssetDeleted(LogAsset),
|
|
||||||
HttpRequest(LogHttpRequest),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct LogAsset {
|
|
||||||
id: String,
|
|
||||||
share_duration: u32,
|
|
||||||
created_at: i64,
|
|
||||||
expires_at: i64,
|
|
||||||
mime: String,
|
|
||||||
uploader_ip: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct LogHttpRequest {
|
|
||||||
method: String,
|
|
||||||
path: String,
|
|
||||||
query_string: String,
|
|
||||||
scheme: String,
|
|
||||||
ip: String,
|
|
||||||
real_ip: String,
|
|
||||||
user_agent: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/api/stats")]
|
#[get("/api/stats")]
|
||||||
async fn api_stats(assets: web::Data<AssetTracker>) -> Result<HttpResponse, actix_web::Error> {
|
async fn api_stats(assets: web::Data<AssetTracker>) -> Result<HttpResponse, actix_web::Error> {
|
||||||
use crate::LOG_DIR;
|
use crate::LOG_DIR;
|
||||||
|
|||||||
30
src/logs.rs
30
src/logs.rs
@@ -1,11 +1,37 @@
|
|||||||
use std::{fs::OpenOptions, io::Write};
|
use std::{fs::OpenOptions, io::Write};
|
||||||
|
|
||||||
use actix_web::HttpRequest;
|
use actix_web::HttpRequest;
|
||||||
use serde::Serialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{LOG_DIR, data_mgt::Asset};
|
use crate::{LOG_DIR, data_mgt::Asset};
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct LogEventLine {
|
||||||
|
pub time: String,
|
||||||
|
pub event: LogEventBody,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub enum LogEventBody {
|
||||||
|
AssetUploaded(LogAsset),
|
||||||
|
AssetDeleted(LogAsset),
|
||||||
|
HttpRequest(LogHttpRequest),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct LogAsset {
|
||||||
|
pub id: String,
|
||||||
|
pub share_duration: u32,
|
||||||
|
pub created_at: i64,
|
||||||
|
pub expires_at: i64,
|
||||||
|
pub mime: String,
|
||||||
|
pub uploader_ip: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct LogHttpRequest {
|
pub struct LogHttpRequest {
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user