Skip to content
Snippets Groups Projects

Elio server

Merged elio.marconi requested to merge elio-server into main
12 files
+ 136
25
Compare changes
  • Side-by-side
  • Inline
Files
12
+ 13
3
@@ -3,13 +3,12 @@ use sharedlib::config::Config;
@@ -3,13 +3,12 @@ use sharedlib::config::Config;
use std::{
use std::{
fs,
fs,
fs::OpenOptions,
fs::OpenOptions,
 
io,
io::Write,
io::Write,
path::Path,
path::Path,
env,
env,
collections::HashMap
};
};
pub const BASEDIR:&str = "./data";
pub const BASEDIR:&str = "./data";
pub const MAXFILESIZE:usize = 100;
pub const MAXFILESIZE:usize = 100;
pub struct DataFile {
pub struct DataFile {
@@ -68,6 +67,14 @@ impl DataFile {
@@ -68,6 +67,14 @@ impl DataFile {
Ok(())
Ok(())
}
}
 
pub fn save_image(&self, data:Vec<u8>) -> Result<String, io::Error> {
 
let filename = chrono::Local::now().format("%Y%m%d-%Hh%Mm%Ss.jpeg").to_string();
 
let path = get_full_path_image(self) + &filename;
 
let mut file = std::fs::File::create(path.clone())?;
 
file.write_all(&data[..])?;
 
Ok(path)
 
}
 
fn check_data_size(&mut self){
fn check_data_size(&mut self){
if self.size > MAXFILESIZE {
if self.size > MAXFILESIZE {
self.nb_files += 1;
self.nb_files += 1;
@@ -80,7 +87,10 @@ fn get_full_path(file : &DataFile) -> String{
@@ -80,7 +87,10 @@ fn get_full_path(file : &DataFile) -> String{
String::from(&file.path) +"/"+ file.nb_files.to_string().as_str()
String::from(&file.path) +"/"+ file.nb_files.to_string().as_str()
}
}
//to do
fn get_full_path_image(file : &DataFile) -> String{
 
String::from(&file.path) +"/".to_string().as_str()
 
}
 
fn get_file_nb(dir:&str) -> std::io::Result<u32> {
fn get_file_nb(dir:&str) -> std::io::Result<u32> {
let res = Path::new(&dir).read_dir()?;
let res = Path::new(&dir).read_dir()?;
Ok(res.into_iter().count() as u32)
Ok(res.into_iter().count() as u32)
Loading