TextureSync/server/texture-sync-server/src/model/mod.rs

50 lines
1.0 KiB
Rust

use serde::Serialize;
use std::io;
mod sha256;
pub use sha256::Sha256;
mod date;
pub use date::Date;
mod texture_format;
pub use texture_format::TextureFormat;
#[derive(Eq, PartialEq, Clone, Serialize, Deserialize, Debug, Hash)]
pub struct Texture {
pub id: String,
pub name: String,
pub tags: Vec<String>,
pub format: TextureFormat,
pub added_on: Date,
pub resolution: (u64, u64),
pub texture_hash: Sha256,
}
pub enum ReplaceTextureStatus {
/// Done.
Ok,
/// Call Again With Texture Binary
NeedTextureData(Sha256),
}
pub type ProtocolResult<T> = Result<T, ProtocolError>;
pub enum ProtocolError {
BadRequest(String),
FileNotFound(String),
Conflict(String),
InternalServerError(std::io::Error),
NotImplemented,
}
impl From<io::Error> for ProtocolError {
fn from(err: io::Error) -> Self {
if err.kind() == io::ErrorKind::NotFound {
ProtocolError::FileNotFound("File Not Found!".to_string())
} else {
ProtocolError::InternalServerError(err)
}
}
}