add server

This commit is contained in:
Aleksandr 2025-10-20 21:38:35 +03:00
parent c546ce40ed
commit 7583f7e557
5 changed files with 62 additions and 5 deletions

View file

@ -9,6 +9,7 @@ pub mod threads;
pub mod auth;
pub mod authors;
pub mod files;
pub mod games;
pub mod uploads;
pub mod users;

8
core/src/errors/files.rs Normal file
View file

@ -0,0 +1,8 @@
use eva::data;
use crate::types::file;
#[data(copy, display("file {id} was not found"), error)]
pub struct NotFound {
pub id: file::Id,
}

View file

@ -1 +1,23 @@
use eva::data;
use crate::{errors, types::file};
pub mod get_info {
use super::*;
#[data]
pub struct Args {
pub id: file::Id,
}
#[data]
pub struct Ok {
pub info: file::FileInfo,
}
#[data(error)]
pub enum Err {
#[display("{_0}")]
NotFound(#[from] errors::files::NotFound),
}
}

View file

@ -75,7 +75,7 @@ pub mod finish {
}
}
pub mod cancel {
pub mod abort {
use super::*;
#[data]

View file

@ -3,13 +3,36 @@
//! Basically same as [`entity::Id`], but additionally stores server where file is located in
//! two lowest bits of random.
use std::{mem, num::NonZeroU128, str::FromStr};
use std::{
mem,
num::{NonZeroU64, NonZeroU128},
str::FromStr,
};
use crate::types::entity;
use eva::{data, hash::blake3, int, str, str::ToCompactString};
use crate::{
types::entity,
world::{World, WorldMut},
};
use eva::{data, hash::blake3, int, rand::Rng, str, str::ToCompactString, time::Clock};
pub type Hash = blake3::Hash;
#[data]
pub struct FileInfo {
pub id: Id,
pub format: FileFormat,
pub class: Class,
pub size: NonZeroU64,
}
#[data(copy)]
pub enum FileFormat {
#[display("image:{_0}")]
Image(ImageFormat),
#[display("opaque")]
Opaque,
}
#[data(copy, ord, display(name))]
pub enum ImageFormat {
Png,
@ -109,6 +132,10 @@ entity::define_eid! {
}
impl Id {
pub fn new<W: WorldMut>(mut w: World<W>, server: Server) -> Self {
Self::from_parts(w.clock().get().as_millis(), w.rng().random(), server)
}
pub const fn from_parts(millis: u64, random: u128, server: Server) -> Self {
let id = entity::Id::from_parts(
millis,
@ -119,7 +146,6 @@ impl Id {
}
pub const fn server(self) -> Server {
// It's still possible that ID is invalid because of deserialization.
unsafe { mem::transmute::<u8, Server>(self.0.metadata().data() & 0b111) }
}