Initial commit: Momentry Core v0.1

- Rust-based digital asset management system
- Video analysis: ASR, OCR, YOLO, Face, Pose
- RAG capabilities with Qdrant vector database
- Multi-database support: PostgreSQL, Redis, MongoDB
- Monitoring system with launchd plists
- n8n workflow automation integration
This commit is contained in:
accusys
2026-03-16 15:07:33 +08:00
parent ca24794853
commit 75edf0aa71
101 changed files with 19858 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
use anyhow::Result;
use std::fs;
use std::path::{Path, PathBuf};
pub struct FileManager {
base_dir: PathBuf,
}
impl FileManager {
pub fn new(base_dir: PathBuf) -> Self {
Self { base_dir }
}
pub fn get_json_path(&self, uuid: &str, suffix: &str) -> PathBuf {
self.base_dir.join(format!("{}.{}.json", uuid, suffix))
}
pub fn save_json(&self, uuid: &str, suffix: &str, content: &str) -> Result<PathBuf> {
let path = self.get_json_path(uuid, suffix);
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
fs::write(&path, content)?;
Ok(path)
}
pub fn load_json(&self, uuid: &str, suffix: &str) -> Result<String> {
let path = self.get_json_path(uuid, suffix);
Ok(fs::read_to_string(path)?)
}
pub fn exists(&self, uuid: &str, suffix: &str) -> bool {
self.get_json_path(uuid, suffix).exists()
}
pub fn list_video_files(dir: &Path) -> Result<Vec<PathBuf>> {
let mut videos = Vec::new();
if !dir.exists() {
return Ok(videos);
}
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if let Some(ext) = path.extension() {
let ext = ext.to_string_lossy().to_lowercase();
if matches!(ext.as_str(), "mp4" | "mkv" | "avi" | "mov" | "webm" | "m4v") {
videos.push(path);
}
}
}
Ok(videos)
}
}

5
src/core/storage/mod.rs Normal file
View File

@@ -0,0 +1,5 @@
pub mod file_manager;
pub mod uuid;
pub use file_manager::FileManager;
pub use uuid::compute_uuid;

44
src/core/storage/uuid.rs Normal file
View File

@@ -0,0 +1,44 @@
use sha2::{Digest, Sha256};
use std::path::PathBuf;
/// Compute UUID from file path using SHA256
/// UUID = SHA256(user_path + filename)[0:16]
pub fn compute_uuid(user_path: &str, filename: &str) -> String {
let key = format!("{}/{}", user_path.trim_end_matches('/'), filename);
let hash = Sha256::digest(key.as_bytes());
let hash_str = hex::encode(hash);
hash_str[0..16].to_string()
}
/// Compute UUID from full file path
pub fn compute_uuid_from_path(full_path: &str) -> String {
let path = PathBuf::from(full_path);
let parent = path
.parent()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_default();
let filename = path
.file_name()
.map(|n| n.to_string_lossy().to_string())
.unwrap_or_default();
compute_uuid(&parent, &filename)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_uuid_computation() {
let uuid = compute_uuid("/Users/test/Videos", "video.mp4");
assert_eq!(uuid.len(), 16);
println!("UUID: {}", uuid);
}
#[test]
fn test_uuid_from_path() {
let uuid = compute_uuid_from_path("/Users/test/Videos/video.mp4");
assert_eq!(uuid.len(), 16);
}
}