diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index a5371be..4ab801e 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -78,6 +78,37 @@ jobs: fi 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) shell: bash run: | @@ -89,8 +120,7 @@ jobs: fi OWNER="${FULL%%/*}" REPO="${FULL##*/}" - VERSION="${GITHUB_REF_NAME#v}" - PKG_VERSION="${VERSION}" + PKG_VERSION="${{ steps.version_meta.outputs.pkg_version }}" BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}" mkdir -p dist @@ -119,8 +149,7 @@ jobs: exit 1 fi REPO="${FULL##*/}" - VERSION="${GITHUB_REF_NAME#v}" - PKG_VERSION="${VERSION}" + PKG_VERSION="${{ steps.version_meta.outputs.pkg_version }}" BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}" mkdir -p dist @@ -143,8 +172,7 @@ jobs: fi OWNER="${FULL%%/*}" REPO="${FULL##*/}" - VERSION="${GITHUB_REF_NAME#v}" - PKG_VERSION="${VERSION}" + PKG_VERSION="${{ steps.version_meta.outputs.pkg_version }}" BIN_NAME="${{ steps.pkg_meta.outputs.pkg_name }}" if [ -z "${BASE_URL:-}" ]; then diff --git a/src/api.rs b/src/api.rs index 5a6edaf..0ef8e53 100644 --- a/src/api.rs +++ b/src/api.rs @@ -6,7 +6,7 @@ use serde_json::json; use crate::{ data_mgt::AssetTracker, - logs::{LogEventType, log_event}, + logs::{LogEventBody, LogEventLine, LogEventType, log_event}, }; #[derive(Deserialize, Debug)] @@ -24,10 +24,12 @@ async fn api_upload( ) -> Result { // Convert to bytes 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 { - // Decode base64 → bytes - general_purpose::STANDARD.decode(&body.content).unwrap() + match general_purpose::STANDARD.decode(&body.content) { + Ok(bytes) => bytes, + Err(_) => return Ok(HttpResponse::BadRequest().body("Invalid base64 payload")), + } }; let connection_info = req.connection_info(); let uploader_ip = connection_info @@ -86,40 +88,6 @@ struct ActivityItem { 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, -} - -#[derive(Deserialize)] -struct LogHttpRequest { - method: String, - path: String, - query_string: String, - scheme: String, - ip: String, - real_ip: String, - user_agent: String, -} - #[get("/api/stats")] async fn api_stats(assets: web::Data) -> Result { use crate::LOG_DIR; diff --git a/src/logs.rs b/src/logs.rs index 85a8b09..6f6da40 100644 --- a/src/logs.rs +++ b/src/logs.rs @@ -1,11 +1,37 @@ use std::{fs::OpenOptions, io::Write}; use actix_web::HttpRequest; -use serde::Serialize; +use serde::{Deserialize, Serialize}; 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, +} + + + +#[derive(Debug, Serialize, Deserialize)] pub struct LogHttpRequest { pub method: String, pub path: String,