cryptgeon/packages/backend/src/note/model.rs

30 lines
635 B
Rust
Raw Normal View History

2021-05-01 12:39:40 +02:00
use bs62;
use ring::rand::SecureRandom;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub struct Note {
2022-03-12 14:07:33 +01:00
pub meta: String,
pub contents: String,
pub views: Option<u32>,
pub expiration: Option<u32>,
2021-05-01 12:39:40 +02:00
}
#[derive(Serialize, Deserialize, Clone)]
2023-05-23 09:38:23 +02:00
pub struct NoteInfo {
pub meta: String,
}
2021-05-01 12:39:40 +02:00
2021-05-02 03:07:08 +02:00
#[derive(Serialize, Deserialize, Clone)]
pub struct NotePublic {
2022-03-12 14:07:33 +01:00
pub meta: String,
pub contents: String,
2021-05-02 03:07:08 +02:00
}
2021-05-01 12:39:40 +02:00
pub fn generate_id() -> String {
2022-03-12 14:07:33 +01:00
let mut id: [u8; 32] = [0; 32];
let sr = ring::rand::SystemRandom::new();
let _ = sr.fill(&mut id);
return bs62::encode_data(&id);
2021-05-01 12:39:40 +02:00
}